RSTalign is an experimental R port of the C++ engine of STalign (Clifton et al., 2023), and it is not an official STalign release. RSTalign is still under development.
If you use STalign or RSTalign, please cite the paper (citation("RSTalign")):
Clifton K, Anant M, Aihara G, Atta L, Aimiuwu OK, Kebschull JM, Miller MI, Tward D, Fan J (2023). STalign: Alignment of spatial transcriptomics data using diffeomorphic metric mapping. Nature Communications 14, 8123. https://doi.org/10.1038/s41467-023-43915-7
Implementation
A minimal R interface (using Rcpp) to the C++ LDDMM engine of the Python package STalign (CPU, float64), through Rcpp.
-
lddmm()runs the LDDMM. - The
affine_from_landmarks()andapply_affine()(2 x 3affine matrices) functions are the tools for the initial alignment, andlandmark_affine()a small Shiny app in which you click matching landmarks on the two point clouds to get such a matrix. -
R/rasterize.Randsrc/rasterize.cpparerasterize(), which turns a point cloud into the density imagelddmm()needs: the C++ port ofSTalign.rasterize(_raster.py), without the figure it draws. -
src/stalign/holds the engine sources, vendored (copied unmodified) fromSTalign/_cpp/of the original repository, includingpocketfft. The source repository, the exact commit ID, and how to check or update the copy are insrc/README.md.
It runs both engines: 2D image to 2D image (LDDMM) and 3D volume to 2D slice (LDDMM_3D_to_slice), chosen by the number of axes of the source.
Installation
You can install RSTalign from R-universe:
install.packages('RSTalign', repos = c('https://bimsbbioinfo.r-universe.dev',
'https://cloud.r-project.org'))The development version of RSTalign needs a C++17 compiler (Xcode command line tools on macOS) and Rcpp.
devtools::install_github("BIMSBbioinfo/RSTalign")Usage
lddmm() has no affine pre-fit, so the source has to start in roughly the pose of the target. A rotation and a shift, or any other affine map, is written as a 2 x 3 matrix [L | t] acting on (x, y); apply_affine() applies it to the cells. To get the matrix by pointing at matching structures instead of guessing an angle, landmark_affine() opens a Shiny app that rasterizes the two clouds, lets you click landmark pairs (source first, then target), and returns the least-squares matrix once you press Done:
library(RSTalign)
M0 <- landmark_affine(source_cells, target_cells) # click >= 3 pairs, check the overlay, Done
source_start <- apply_affine(source_cells, M0) # then rasterize source_start as above