scplotter to work with 10x Visium data prepared by Seurat¶
See: https://satijalab.org/seurat/articles/spatial_vignette#x-visium
Go back to scplotter documentation: https://pwwang.github.io/scplotter/
Mouse brain¶
InĀ [1]:
suppressPackageStartupMessages({
library(Seurat)
library(SeuratData)
})
# Load the scplotter package
# library(scplotter)
devtools::load_all()
ā¹ Loading scplotter
InĀ [2]:
suppressWarnings(suppressMessages({
brain <- LoadData("stxBrain", type = "anterior1")
brain <- SCTransform(brain, assay = "Spatial", verbose = FALSE)
brain <- RunPCA(brain, assay = "SCT", verbose = FALSE)
brain <- FindNeighbors(brain, reduction = "pca", dims = 1:30)
brain <- FindClusters(brain, verbose = FALSE)
brain <- RunUMAP(brain, reduction = "pca", dims = 1:30)
}))
brain
An object of class Seurat 48721 features across 2696 samples within 2 assays Active assay: SCT (17668 features, 3000 variable features) 3 layers present: counts, data, scale.data 1 other assay present: Spatial 2 dimensional reductions calculated: pca, umap 1 spatial field of view present: anterior1
InĀ [10]:
options(repr.plot.width = 12, repr.plot.height = 6)
devtools::load_all()
plot1 <- FeatureStatPlot(brain, features = "nCount_Spatial",
ident = "orig.ident", add_point = TRUE, legend.position = "none")
plot2 <- SpatFeaturePlot(brain, features = "nCount_Spatial")
plot1 + plot2
ā¹ Loading scplotter
InĀ [11]:
options(repr.plot.width = 10, repr.plot.height = 5)
SpatFeaturePlot(brain, features = c("Hpca", "Ttr"),
color_name = "Expression", # alias for `points_color_name`
size = 1.2 # alias for `points_size`
)
InĀ [12]:
# Plot without image
options(repr.plot.width = 10, repr.plot.height = 10)
p1 <- SpatFeaturePlot(brain, image = FALSE, features = c("Hpca", "Ttr"),
color_name = "Expression" # alias for `points_color_name`
)
# or provide only points layers, and with a different palette
p2 <- SpatFeaturePlot(brain, layers = "points", features = c("Hpca", "Ttr"),
color_name = "Expression", palette = "Reds")
p1 / p2
InĀ [14]:
options(repr.plot.width = 10, repr.plot.height = 5)
p1 <- SpatFeaturePlot(brain, features = "Ttr",
shape = 21, # alias of points_shape
size = 1.2, # alias of points_size
border_size = 0.1 # alias of points_border_size
)
p2 <- SpatFeaturePlot(brain, features = "Ttr",
points_shape = 21, points_border_alpha = 0.1, points_border_size = 0.1,
points_size = 1.2)
p1 + p2
ā¹ Loading scplotter
InĀ [15]:
options(repr.plot.width = 10, repr.plot.height = 5)
p1 <- CellDimPlot(brain, label_insitu = TRUE)
p2 <- SpatDimPlot(brain, points_size = 0.8, label = TRUE)
p1 + p2
Forcing label to be TRUE when label_repel or label_insitu is TRUE.
InĀ [16]:
options(repr.plot.width = 6, repr.plot.height = 5)
SpatDimPlot(brain, points_size = 0.8,
label = TRUE, label_insitu = TRUE,
highlight_color = "red", highlight_stroke = 1.6,
highlight = 'seurat_clusters %in% c("2", "5", "8")')
InĀ [17]:
de_markers <- FindMarkers(brain, ident.1 = 5, ident.2 = 6)
options(repr.plot.width = 15, repr.plot.height = 5)
SpatFeaturePlot(brain, features = rownames(de_markers)[1:3])
InĀ [18]:
# brain <- suppressMessages({
# FindSpatiallyVariableFeatures(
# brain, assay = "SCT", features = VariableFeatures(brain)[1:1000],
# selection.method = "moransi")
# })
# top.features <- head(SpatiallyVariableFeatures(brain, selection.method = "moransi"), 6)
top.features <- c("Calb2", "Gng4", "Ttr", "S100a5", "Nrgn", "Fabp7")
options(repr.plot.width = 15, repr.plot.height = 10)
SpatFeaturePlot(brain, features = top.features)
InĀ [19]:
coords <- GetTissueCoordinates(brain, image = "anterior1")
scale_factor <- brain@images$anterior1@scale.factors$lowres
coords$x <- coords$x * scale_factor
coords$y <- coords$y * scale_factor
cells <- coords[coords$y > 150 & coords$y < 500 & coords$x > 0 & coords$x < 400, "cell"]
suppressWarnings({
cortex <- subset(brain, cells = cells)
cortex <- subset(cortex, idents = c(1, 2, 3, 4, 6, 7))
})
options(repr.plot.width = 14, repr.plot.height = 6)
p1 <- SpatDimPlot(cortex, label = TRUE, label_size = 6, points_size = 2.5)
p2 <- SpatDimPlot(cortex, label = TRUE, points_size = 1, crop = FALSE)
p1 + p2
InĀ [20]:
options(repr.plot.width = 6, repr.plot.height = 5)
# Or use extent
# We are using brain (uncropped) object
brain123467 <- suppressWarnings(subset(brain, idents = c(1, 2, 3, 4, 6, 7)))
SpatDimPlot(brain123467, ext = c(140, 500, 120, 400), label = TRUE, label_size = 6,
points_size = 2.5, theme = "theme_this")
Mouse kidney¶
InĀ [21]:
# https://s3-eu-west-1.amazonaws.com/pfigshare-u-files/49797231/Visium_FFPE_Mouse_Kidney.tar.gz?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIYCQYOYV5JSSROOA/20250602/eu-west-1/s3/aws4_request&X-Amz-Date=20250602T214211Z&X-Amz-Expires=10&X-Amz-SignedHeaders=host&X-Amz-Signature=c71d8aca8e60a009323d7dfefa7df0dc08e9769df54ab2f3c6800a17ba045afd
kidney <- Seurat::Load10X_Spatial("data/Visium_FFPE_Mouse_Kidney/")
InĀ [22]:
options(repr.plot.width = 10, repr.plot.height = 5)
SpatFeaturePlot(kidney, features = c("nCount_Spatial", "nFeature_Spatial"))
InĀ [23]:
options(repr.plot.width = 10, repr.plot.height = 5)
kidney$log_nCount_Spatial <- log(kidney$nCount_Spatial)
kidney$log_nFeature_Spatial <- log(kidney$nFeature_Spatial)
SpatFeaturePlot(kidney, features = c("log_nCount_Spatial", "log_nFeature_Spatial"))
Visium V1¶
InĀ [24]:
# https://figshare.com/articles/dataset/10X_visium_data_for_spatial-informed_cell-cell_communication/23621151?file=41446839
load("data/visium_mouse_cortex_annotated.RData")
visium.brain
An object of class Seurat 1320 features across 1073 samples within 3 assays Active assay: Spatial (648 features, 0 variable features) 2 layers present: counts, data 2 other assays present: SCT, predictions 2 dimensional reductions calculated: pca, umap 1 image present: anterior1
InĀ [25]:
options(repr.plot.width = 14, repr.plot.height = 5)
p1 <- SpatDimPlot(visium.brain, theme = "theme_this")
p2 <- SpatDimPlot(visium.brain, theme = "theme_this", image = "black")
p1 + p2
InĀ [2]:
x <- sessionInfo()
x <- capture.output(print(x))
# hide the BLAS/LAPACK paths
x <- x[!startsWith(x, "BLAS/LAPACK:")]
cat(paste(x, collapse = "\n"))
R version 4.3.3 (2024-02-29) Platform: x86_64-conda-linux-gnu (64-bit) Running under: Red Hat Enterprise Linux 8.10 (Ootpa) Matrix products: default locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=C [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C time zone: America/Chicago tzcode source: system (glibc) attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] scplotter_0.4.0 stxKidney.SeuratData_0.1.0 [3] stxBrain.SeuratData_0.1.2 ssHippo.SeuratData_3.1.4 [5] pbmc3k.SeuratData_3.1.4 bmcite.SeuratData_0.3.0 [7] SeuratData_0.2.2.9001 Seurat_5.3.0 [9] SeuratObject_5.0.2 sp_2.1-4 loaded via a namespace (and not attached): [1] cubature_2.1.1 RcppAnnoy_0.0.22 [3] splines_4.3.3 later_1.3.2 [5] pbdZMQ_0.3-11 bitops_1.0-7 [7] tibble_3.2.1 polyclip_1.10-6 [9] fastDummies_1.7.3 lifecycle_1.0.4 [11] rprojroot_2.0.4 globals_0.16.3 [13] lattice_0.22-6 MASS_7.3-60.0.1 [15] magrittr_2.0.3 plotly_4.10.4 [17] remotes_2.5.0 httpuv_1.6.15 [19] sctransform_0.4.1 spam_2.11-0 [21] sessioninfo_1.2.2 pkgbuild_1.4.4 [23] spatstat.sparse_3.1-0 reticulate_1.38.0 [25] cowplot_1.1.3 pbapply_1.7-2 [27] RColorBrewer_1.1-3 abind_1.4-5 [29] pkgload_1.3.4 zlibbioc_1.48.0 [31] Rtsne_0.17 GenomicRanges_1.54.1 [33] purrr_1.0.2 ggraph_2.2.1 [35] BiocGenerics_0.48.1 RCurl_1.98-1.13 [37] tweenr_2.0.3 evmix_2.12 [39] rappdirs_0.3.3 circlize_0.4.16 [41] GenomeInfoDbData_1.2.11 IRanges_2.36.0 [43] S4Vectors_0.40.2 ggrepel_0.9.6 [45] irlba_2.3.5.1 listenv_0.9.1 [47] spatstat.utils_3.1-1 iNEXT_3.0.1 [49] MatrixModels_0.5-3 goftest_1.2-3 [51] RSpectra_0.16-1 scRepertoire_2.2.1 [53] spatstat.random_3.2-3 fitdistrplus_1.1-11 [55] parallelly_1.38.0 codetools_0.2-20 [57] DelayedArray_0.28.0 xml2_1.3.6 [59] ggforce_0.4.2 shape_1.4.6.1 [61] tidyselect_1.2.1 farver_2.1.2 [63] viridis_0.6.5 matrixStats_1.1.0 [65] stats4_4.3.3 base64enc_0.1-3 [67] spatstat.explore_3.2-6 jsonlite_1.8.8 [69] tidygraph_1.3.0 ellipsis_0.3.2 [71] progressr_0.14.0 ggalluvial_0.12.5 [73] ggridges_0.5.6 survival_3.7-0 [75] ggnewscale_0.5.0 tools_4.3.3 [77] stringdist_0.9.12 ica_1.0-3 [79] Rcpp_1.0.13 glue_1.8.0 [81] gridExtra_2.3 SparseArray_1.2.2 [83] MatrixGenerics_1.14.0 usethis_2.2.3 [85] GenomeInfoDb_1.38.1 IRdisplay_1.1 [87] dplyr_1.1.4 withr_3.0.1 [89] fastmap_1.2.0 fansi_1.0.6 [91] SparseM_1.84 digest_0.6.37 [93] R6_2.5.1 mime_0.12 [95] colorspace_2.1-1 scattermore_1.2 [97] tensor_1.5 spatstat.data_3.1-2 [99] utf8_1.2.4 tidyr_1.3.1 [101] generics_0.1.3 data.table_1.15.4 [103] graphlayouts_1.1.0 httr_1.4.7 [105] htmlwidgets_1.6.4 S4Arrays_1.2.0 [107] uwot_0.1.16 pkgconfig_2.0.3 [109] gtable_0.3.5 lmtest_0.9-40 [111] SingleCellExperiment_1.24.0 XVector_0.42.0 [113] htmltools_0.5.8.1 profvis_0.3.8 [115] dotCall64_1.2 scales_1.3.0 [117] Biobase_2.62.0 png_0.1-8 [119] ggdendro_0.2.0 rstudioapi_0.16.0 [121] rjson_0.2.21 reshape2_1.4.4 [123] uuid_1.2-0 nlme_3.1-165 [125] GlobalOptions_0.1.2 repr_1.1.7 [127] cachem_1.1.0 zoo_1.8-12 [129] stringr_1.5.1 KernSmooth_2.23-24 [131] parallel_4.3.3 miniUI_0.1.1.1 [133] desc_1.4.3 pillar_1.9.0 [135] grid_4.3.3 vctrs_0.6.5 [137] RANN_2.6.1 VGAM_1.1-12 [139] urlchecker_1.0.1 promises_1.3.0 [141] xtable_1.8-4 cluster_2.1.6 [143] evaluate_0.24.0 truncdist_1.0-2 [145] cli_3.6.3 compiler_4.3.3 [147] rlang_1.1.4 crayon_1.5.3 [149] future.apply_1.11.2 forcats_1.0.0 [151] plyr_1.8.9 fs_1.6.4 [153] stringi_1.8.7 viridisLite_0.4.2 [155] deldir_2.0-4 assertthat_0.2.1 [157] gsl_2.1-8 munsell_0.5.1 [159] lazyeval_0.2.2 devtools_2.4.5 [161] spatstat.geom_3.2-9 quantreg_5.98 [163] Matrix_1.6-5 IRkernel_1.3.2 [165] RcppHNSW_0.6.0 patchwork_1.3.0 [167] future_1.34.0 ggplot2_3.5.1 [169] shiny_1.8.1.1 plotthis_0.7.0 [171] SummarizedExperiment_1.32.0 evd_2.3-7.1 [173] ROCR_1.0-11 gridtext_0.1.5 [175] igraph_1.5.1 memoise_2.0.1