Guide to Spatial Registration (original) (raw)
What is Spatial Registration?
Spatial Registration is an analysis that compares the gene expression of groups in a query RNA-seq data set (typically spatially resolved RNA-seq or single cell RNA-seq) to groups in a reference spatially resolved RNA-seq data set (such annotated anatomical features).
For spatial data, this can be helpful to compare manual annotations, or annotating clusters. For scRNA-seq data it can check if a cell type might be more concentrated in one area or anatomical feature of the tissue.
The spatial annotation process correlates the \(t\)-statistics from the gene enrichment analysis between spatial features from the reference data set, with the \(t\)-statistics from the gene enrichment of features in the query data set. Pairs with high positive correlation show where similar patterns of gene expression are occurring and what anatomical feature the new spatial feature or cell population may map to.
Overview of the Spatial Registration method
- Perform gene set enrichment analysis between spatial features (ex. anatomical features, histological layers) on reference spatial data set. Or access existing statistics.
- Perform gene set enrichment analysis between features (ex. new annotations, data-driven clusters) on new query data set.
- Correlate the \(t\)-statistics between the reference and query features.
- Annotate new spatial features with the most strongly associated reference feature.
- Plot correlation heat map to observe patterns between the two data sets.
Explore Results
Now we can use these correlation values to learn about the cell types.
Create Heatmap of Correlations
We can see from this heatmap what layers the different cell types are associated with.
- Oligo with WM
- Astro with Layer 1
- Excitatory neurons to different layers of the cortex
- Weak associate with Inhibitory Neurons
layer_stat_cor_plot(cor_layer)
Annotate Cell Types by Top Correlation
We can use annotate_registered_clusters
to create annotation labels for the cell types based on the correlation values.
anno <- annotate_registered_clusters(
cor_stats_layer = cor_layer,
confidence_threshold = 0.25,
cutoff_merge_ratio = 0.25
)
anno
#> cluster layer_confidence layer_label layer_label_simple
#> 1 Oligo good WM WM
#> 2 Astro good Layer1 L1
#> 3 OPC good WM WM
#> 4 Micro good WM WM
#> 5 Mural poor Layer1* L1*
#> 6 Excit_B good Layer2/Layer3 L2/3
#> 7 Excit_C good Layer3 L3
#> 8 Excit_A good Layer5 L5
#> 9 Excit_E good Layer6 L6
#> 10 Excit_F good Layer6/Layer5 L6/5
#> 11 Inhib_A poor Layer2/Layer3/Layer4* L2/3/4*
#> 12 Inhib_C poor Layer2* L2*
#> 13 Excit_D good Layer4 L4
#> 14 Inhib_B poor Layer4* L4*
#> 15 Inhib_D good Layer4 L4
Plot Annotated Cell Types
Finally, we can update our heatmap with colors and annotations based on cluster registration for the snRNA-seq clusters.
layer_stat_cor_plot(
cor_layer,
query_colors = get_colors(clusters = rownames(cor_layer)),
reference_colors = libd_layer_colors,
annotation = anno,
cluster_rows = FALSE,
cluster_columns = FALSE
)
Reproducibility
The spatialLIBD package (Pardo, Spangler, Weber et al., 2022) was made possible thanks to:
- R (R Core Team, 2025)
- BiocStyle (Oleś, 2025)
- knitr (Xie, 2025)
- RefManageR (McLean, 2017)
- rmarkdown (Allaire, Xie, Dervieux et al., 2024)
- sessioninfo (Wickham, Chang, Flight et al., 2025)
- testthat (Wickham, 2011)
This package was developed using biocthis.
Code for creating the vignette
## Create the vignette
library("rmarkdown")
system.time(render("guide_to_spatial_registration.Rmd", "BiocStyle::html_document"))
## Extract the R code
library("knitr")
knit("guide_to_spatial_registration.Rmd", tangle = TRUE)
Date the vignette was generated.
#> [1] "2025-05-01 11:45:04 EDT"
Wallclock time spent generating the vignette.
#> Time difference of 45.166 secs
R
session information.
#> ─ Session info ───────────────────────────────────────────────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.5.0 RC (2025-04-04 r88126)
#> os Ubuntu 24.04.2 LTS
#> system x86_64, linux-gnu
#> ui X11
#> language (EN)
#> collate C
#> ctype en_US.UTF-8
#> tz America/New_York
#> date 2025-05-01
#> pandoc 2.7.3 @ /usr/bin/ (via rmarkdown)
#> quarto 1.5.57 @ /usr/local/bin/quarto
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────────────────────────────────────────────
#> package * version date (UTC) lib source
#> abind 1.4-8 2024-09-12 [2] CRAN (R 4.5.0)
#> AnnotationDbi 1.70.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> AnnotationHub 3.16.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> attempt 0.3.1 2020-05-03 [2] CRAN (R 4.5.0)
#> backports 1.5.0 2024-05-23 [2] CRAN (R 4.5.0)
#> beachmat 2.24.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> beeswarm 0.4.0 2021-06-01 [2] CRAN (R 4.5.0)
#> benchmarkme 1.0.8 2022-06-12 [2] CRAN (R 4.5.0)
#> benchmarkmeData 1.0.4 2020-04-23 [2] CRAN (R 4.5.0)
#> bibtex 0.5.1 2023-01-26 [2] CRAN (R 4.5.0)
#> Biobase * 2.68.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> BiocFileCache * 2.16.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> BiocGenerics * 0.54.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> BiocIO 1.18.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> BiocManager 1.30.25 2024-08-28 [2] CRAN (R 4.5.0)
#> BiocNeighbors 2.2.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> BiocParallel 1.42.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> BiocSingular 1.24.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> BiocStyle * 2.36.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> BiocVersion 3.21.1 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> Biostrings 2.76.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> bit 4.6.0 2025-03-06 [2] CRAN (R 4.5.0)
#> bit64 4.6.0-1 2025-01-16 [2] CRAN (R 4.5.0)
#> bitops 1.0-9 2024-10-03 [2] CRAN (R 4.5.0)
#> blob 1.2.4 2023-03-17 [2] CRAN (R 4.5.0)
#> bookdown 0.43 2025-04-15 [2] CRAN (R 4.5.0)
#> bslib 0.9.0 2025-01-30 [2] CRAN (R 4.5.0)
#> cachem 1.1.0 2024-05-16 [2] CRAN (R 4.5.0)
#> Cairo 1.6-2 2023-11-28 [2] CRAN (R 4.5.0)
#> circlize 0.4.16 2024-02-20 [2] CRAN (R 4.5.0)
#> cli 3.6.5 2025-04-23 [2] CRAN (R 4.5.0)
#> clue 0.3-66 2024-11-13 [2] CRAN (R 4.5.0)
#> cluster 2.1.8.1 2025-03-12 [3] CRAN (R 4.5.0)
#> codetools 0.2-20 2024-03-31 [3] CRAN (R 4.5.0)
#> colorspace 2.1-1 2024-07-26 [2] CRAN (R 4.5.0)
#> ComplexHeatmap 2.24.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> config 0.3.2 2023-08-30 [2] CRAN (R 4.5.0)
#> cowplot 1.1.3 2024-01-22 [2] CRAN (R 4.5.0)
#> crayon 1.5.3 2024-06-20 [2] CRAN (R 4.5.0)
#> curl 6.2.2 2025-03-24 [2] CRAN (R 4.5.0)
#> data.table 1.17.0 2025-02-22 [2] CRAN (R 4.5.0)
#> DBI 1.2.3 2024-06-02 [2] CRAN (R 4.5.0)
#> dbplyr * 2.5.0 2024-03-19 [2] CRAN (R 4.5.0)
#> DelayedArray 0.34.1 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> DelayedMatrixStats 1.30.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> dichromat 2.0-0.1 2022-05-02 [2] CRAN (R 4.5.0)
#> digest 0.6.37 2024-08-19 [2] CRAN (R 4.5.0)
#> doParallel 1.0.17 2022-02-07 [2] CRAN (R 4.5.0)
#> dplyr 1.1.4 2023-11-17 [2] CRAN (R 4.5.0)
#> dqrng 0.4.1 2024-05-28 [2] CRAN (R 4.5.0)
#> DropletUtils 1.28.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> DT 0.33 2024-04-04 [2] CRAN (R 4.5.0)
#> edgeR 4.6.1 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> evaluate 1.0.3 2025-01-10 [2] CRAN (R 4.5.0)
#> ExperimentHub 2.16.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> farver 2.1.2 2024-05-13 [2] CRAN (R 4.5.0)
#> fastmap 1.2.0 2024-05-15 [2] CRAN (R 4.5.0)
#> filelock 1.0.3 2023-12-11 [2] CRAN (R 4.5.0)
#> foreach 1.5.2 2022-02-02 [2] CRAN (R 4.5.0)
#> generics * 0.1.3 2022-07-05 [2] CRAN (R 4.5.0)
#> GenomeInfoDb * 1.44.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> GenomeInfoDbData 1.2.14 2025-04-10 [2] Bioconductor
#> GenomicAlignments 1.44.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> GenomicRanges * 1.60.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> GetoptLong 1.0.5 2020-12-15 [2] CRAN (R 4.5.0)
#> ggbeeswarm 0.7.2 2023-04-29 [2] CRAN (R 4.5.0)
#> ggplot2 3.5.2 2025-04-09 [2] CRAN (R 4.5.0)
#> ggrepel 0.9.6 2024-09-07 [2] CRAN (R 4.5.0)
#> GlobalOptions 0.1.2 2020-06-10 [2] CRAN (R 4.5.0)
#> glue 1.8.0 2024-09-30 [2] CRAN (R 4.5.0)
#> golem 0.5.1 2024-08-27 [2] CRAN (R 4.5.0)
#> gridExtra 2.3 2017-09-09 [2] CRAN (R 4.5.0)
#> gtable 0.3.6 2024-10-25 [2] CRAN (R 4.5.0)
#> h5mread 1.0.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> HDF5Array 1.36.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> htmltools 0.5.8.1 2024-04-04 [2] CRAN (R 4.5.0)
#> htmlwidgets 1.6.4 2023-12-06 [2] CRAN (R 4.5.0)
#> httpuv 1.6.16 2025-04-16 [2] CRAN (R 4.5.0)
#> httr 1.4.7 2023-08-15 [2] CRAN (R 4.5.0)
#> IRanges * 2.42.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> irlba 2.3.5.1 2022-10-03 [2] CRAN (R 4.5.0)
#> iterators 1.0.14 2022-02-05 [2] CRAN (R 4.5.0)
#> jquerylib 0.1.4 2021-04-26 [2] CRAN (R 4.5.0)
#> jsonlite 2.0.0 2025-03-27 [2] CRAN (R 4.5.0)
#> KEGGREST 1.48.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> knitr 1.50 2025-03-16 [2] CRAN (R 4.5.0)
#> labeling 0.4.3 2023-08-29 [2] CRAN (R 4.5.0)
#> later 1.4.2 2025-04-08 [2] CRAN (R 4.5.0)
#> lattice 0.22-7 2025-04-02 [3] CRAN (R 4.5.0)
#> lazyeval 0.2.2 2019-03-15 [2] CRAN (R 4.5.0)
#> lifecycle 1.0.4 2023-11-07 [2] CRAN (R 4.5.0)
#> limma 3.64.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> lobstr * 1.1.2 2022-06-22 [2] CRAN (R 4.5.0)
#> locfit 1.5-9.12 2025-03-05 [2] CRAN (R 4.5.0)
#> lubridate 1.9.4 2024-12-08 [2] CRAN (R 4.5.0)
#> magick 2.8.6 2025-03-23 [2] CRAN (R 4.5.0)
#> magrittr 2.0.3 2022-03-30 [2] CRAN (R 4.5.0)
#> Matrix 1.7-3 2025-03-11 [3] CRAN (R 4.5.0)
#> MatrixGenerics * 1.20.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> matrixStats * 1.5.0 2025-01-07 [2] CRAN (R 4.5.0)
#> memoise 2.0.1 2021-11-26 [2] CRAN (R 4.5.0)
#> mime 0.13 2025-03-17 [2] CRAN (R 4.5.0)
#> paletteer 1.6.0 2024-01-21 [2] CRAN (R 4.5.0)
#> pillar 1.10.2 2025-04-05 [2] CRAN (R 4.5.0)
#> pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.5.0)
#> plotly 4.10.4 2024-01-13 [2] CRAN (R 4.5.0)
#> plyr 1.8.9 2023-10-02 [2] CRAN (R 4.5.0)
#> png 0.1-8 2022-11-29 [2] CRAN (R 4.5.0)
#> prettyunits 1.2.0 2023-09-24 [2] CRAN (R 4.5.0)
#> prismatic 1.1.2 2024-04-10 [2] CRAN (R 4.5.0)
#> promises 1.3.2 2024-11-28 [2] CRAN (R 4.5.0)
#> purrr 1.0.4 2025-02-05 [2] CRAN (R 4.5.0)
#> R.methodsS3 1.8.2 2022-06-13 [2] CRAN (R 4.5.0)
#> R.oo 1.27.0 2024-11-01 [2] CRAN (R 4.5.0)
#> R.utils 2.13.0 2025-02-24 [2] CRAN (R 4.5.0)
#> R6 2.6.1 2025-02-15 [2] CRAN (R 4.5.0)
#> rappdirs 0.3.3 2021-01-31 [2] CRAN (R 4.5.0)
#> RColorBrewer 1.1-3 2022-04-03 [2] CRAN (R 4.5.0)
#> Rcpp 1.0.14 2025-01-12 [2] CRAN (R 4.5.0)
#> RCurl 1.98-1.17 2025-03-22 [2] CRAN (R 4.5.0)
#> RefManageR * 1.4.0 2022-09-30 [2] CRAN (R 4.5.0)
#> rematch2 2.1.2 2020-05-01 [2] CRAN (R 4.5.0)
#> restfulr 0.0.15 2022-06-16 [2] CRAN (R 4.5.0)
#> rhdf5 2.52.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> rhdf5filters 1.20.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> Rhdf5lib 1.30.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> rjson 0.2.23 2024-09-16 [2] CRAN (R 4.5.0)
#> rlang 1.1.6 2025-04-11 [2] CRAN (R 4.5.0)
#> rmarkdown 2.29 2024-11-04 [2] CRAN (R 4.5.0)
#> Rsamtools 2.24.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> RSQLite 2.3.9 2024-12-03 [2] CRAN (R 4.5.0)
#> rsvd 1.0.5 2021-04-16 [2] CRAN (R 4.5.0)
#> rtracklayer * 1.68.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> S4Arrays 1.8.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> S4Vectors * 0.46.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> sass 0.4.10 2025-04-11 [2] CRAN (R 4.5.0)
#> ScaledMatrix 1.16.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> scales 1.4.0 2025-04-24 [2] CRAN (R 4.5.0)
#> scater 1.36.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> scuttle 1.18.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> sessioninfo * 1.2.3 2025-02-05 [2] CRAN (R 4.5.0)
#> shape 1.4.6.1 2024-02-23 [2] CRAN (R 4.5.0)
#> shiny 1.10.0 2024-12-14 [2] CRAN (R 4.5.0)
#> shinyWidgets 0.9.0 2025-02-21 [2] CRAN (R 4.5.0)
#> SingleCellExperiment * 1.30.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> SparseArray 1.8.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> sparseMatrixStats 1.20.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> SpatialExperiment * 1.18.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> spatialLIBD * 1.20.1 2025-05-01 [1] Bioconductor 3.21 (R 4.5.0)
#> statmod 1.5.0 2023-01-06 [2] CRAN (R 4.5.0)
#> stringi 1.8.7 2025-03-27 [2] CRAN (R 4.5.0)
#> stringr 1.5.1 2023-11-14 [2] CRAN (R 4.5.0)
#> SummarizedExperiment * 1.38.1 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> tibble 3.2.1 2023-03-20 [2] CRAN (R 4.5.0)
#> tidyr 1.3.1 2024-01-24 [2] CRAN (R 4.5.0)
#> tidyselect 1.2.1 2024-03-11 [2] CRAN (R 4.5.0)
#> timechange 0.3.0 2024-01-18 [2] CRAN (R 4.5.0)
#> UCSC.utils 1.4.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> vctrs 0.6.5 2023-12-01 [2] CRAN (R 4.5.0)
#> vipor 0.4.7 2023-12-18 [2] CRAN (R 4.5.0)
#> viridis 0.6.5 2024-01-29 [2] CRAN (R 4.5.0)
#> viridisLite 0.4.2 2023-05-02 [2] CRAN (R 4.5.0)
#> withr 3.0.2 2024-10-28 [2] CRAN (R 4.5.0)
#> xfun 0.52 2025-04-02 [2] CRAN (R 4.5.0)
#> XML 3.99-0.18 2025-01-01 [2] CRAN (R 4.5.0)
#> xml2 1.3.8 2025-03-14 [2] CRAN (R 4.5.0)
#> xtable 1.8-4 2019-04-21 [2] CRAN (R 4.5.0)
#> XVector 0.48.0 2025-04-30 [2] Bioconductor 3.21 (R 4.5.0)
#> yaml 2.3.10 2024-07-26 [2] CRAN (R 4.5.0)
#>
#> [1] /tmp/RtmphidzXQ/Rinst356951d91c5fb
#> [2] /home/biocbuild/bbs-3.21-bioc/R/site-library
#> [3] /home/biocbuild/bbs-3.21-bioc/R/library
#> * ── Packages attached to the search path.
#>
#> ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Bibliography
This vignette was generated using BiocStyle (Oleś, 2025) with knitr (Xie, 2025) and rmarkdown (Allaire, Xie, Dervieux et al., 2024) running behind the scenes.
Citations made with RefManageR (McLean, 2017).
[1]J. Allaire, Y. Xie, C. Dervieux, et al.rmarkdown: Dynamic Documents for R. R package version 2.29. 2024. URL: https://github.com/rstudio/rmarkdown.
[2]K. R. Maynard, L. Collado-Torres, L. M. Weber, et al. “Transcriptome-scale spatial gene expression in the human dorsolateral prefrontal cortex”. In: Nature Neuroscience (2021). DOI: 10.1038/s41593-020-00787-0. URL: https://www.nature.com/articles/s41593-020-00787-0.
[3]M. W. McLean. “RefManageR: Import and Manage BibTeX and BibLaTeX References in R”. In: The Journal of Open Source Software (2017). DOI: 10.21105/joss.00338.
[4]A. Oleś.BiocStyle: Standard styles for vignettes and other Bioconductor documents. R package version 2.36.0. 2025. DOI: 10.18129/B9.bioc.BiocStyle. URL: https://bioconductor.org/packages/BiocStyle.
[5]B. Pardo, A. Spangler, L. M. Weber, et al. “spatialLIBD: an R/Bioconductor package to visualize spatially-resolved transcriptomics data”. In: BMC Genomics (2022). DOI: 10.1186/s12864-022-08601-w. URL: https://doi.org/10.1186/s12864-022-08601-w.
[6]R Core Team.R: A Language and Environment for Statistical Computing. R Foundation for Statistical Computing. Vienna, Austria, 2025. URL: https://www.R-project.org/.
[7]M. N. Tran, K. R. Maynard, A. Spangler, et al. “Single-nucleus transcriptome analysis reveals cell-type-specific molecular signatures across reward circuitry in the human brain”. In: Neuron (2021). DOI: 10.1016/j.neuron.2021.09.001.
[8]H. Wickham. “testthat: Get Started with Testing”. In: The R Journal 3 (2011), pp. 5–10. URL: https://journal.r-project.org/archive/2011-1/RJournal_2011-1_Wickham.pdf.
[9]H. Wickham, W. Chang, R. Flight, et al.sessioninfo: R Session Information. R package version 1.2.3. 2025. DOI: 10.32614/CRAN.package.sessioninfo. URL: https://CRAN.R-project.org/package=sessioninfo.
[10]Y. Xie.knitr: A General-Purpose Package for Dynamic Report Generation in R. R package version 1.50. 2025. URL: https://yihui.org/knitr/.