scplotter to work with 10x Visium data prepared by Seurat¶
Go back to scplotter documentation: https://pwwang.github.io/scplotter/
Mouse Brain: 10x Genomics Xenium In Situ¶
InĀ [1]:
suppressPackageStartupMessages({
library(Seurat)
})
# Load the scplotter package
# library(scplotter)
devtools::load_all()
# devtools::load_all("../../../plotthis")
path <- "data/xenium_tiny_subset/outs"
# path <- "data/Xenium_Giotto_workshop"
# Load the Xenium data
xenium.obj <- LoadXenium(path, fov = "fov")
# remove cells with 0 counts
xenium.obj <- subset(xenium.obj, subset = nCount_Xenium > 0)
xenium.obj
ā¹ Loading scplotter Warning message: ācells did not contain a segmentation_method column. Skipping...ā Genome matrix has multiple modalities, returning a list of matrices for this genome Warning message: āFeature names cannot have underscores ('_'), replacing with dashes ('-')ā Warning message: āFeature names cannot have underscores ('_'), replacing with dashes ('-')ā Warning message: āFeature names cannot have underscores ('_'), replacing with dashes ('-')ā Warning message: āFeature names cannot have underscores ('_'), replacing with dashes ('-')ā Warning message: āFeature names cannot have underscores ('_'), replacing with dashes ('-')ā Warning message: āFeature names cannot have underscores ('_'), replacing with dashes ('-')ā Warning message: āNot validating FOV objectsā Warning message: āNot validating Centroids objectsā Warning message: āNot validating Centroids objectsā Warning message: āNot validating FOV objectsā Warning message: āNot validating FOV objectsā Warning message: āNot validating FOV objectsā Warning message: āNot validating Seurat objectsā
An object of class Seurat 541 features across 36553 samples within 4 assays Active assay: Xenium (248 features, 0 variable features) 1 layer present: counts 3 other assays present: BlankCodeword, ControlCodeword, ControlProbe 1 spatial field of view present: fov
InĀ [2]:
options(repr.plot.width = 10, repr.plot.height = 5)
FeatureStatPlot(xenium.obj, features = c("nFeature_Xenium", "nCount_Xenium"),
facet_scales = "free_y")
Warning message in GetAssayData.StdAssay(object = object[[assay]], layer = layer): ādata layer is not found and counts layer is usedā
InĀ [7]:
options(repr.plot.width = 6, repr.plot.height = 8)
devtools::load_all()
SpatDimPlot(xenium.obj, image = "black", features = c("Gad1", "Sst", "Pvalb", "Gfap"),
nmols = 20000, points_size = 0.1, points_palette = "Set1")
ā¹ Loading scplotter
InĀ [8]:
options(repr.plot.width = 8, repr.plot.height = 12)
SpatFeaturePlot(xenium.obj, layer = "counts", image = "black",
features = c("Cux2", "Rorb", "Bcl11b", "Foxp2"),
points_size = 0.2, points_color_name = "Expression")
InĀ [9]:
options(repr.plot.width = 11, repr.plot.height = 5, future.globals.maxSize = 1024 ^ 3)
cropped.coords <- Crop(xenium.obj[["fov"]], x = c(1200, 2900), y = c(3750, 4550), coords = "plot")
xenium.obj[["zoom"]] <- cropped.coords
# visualize cropped area with cell segmentations & selected molecules
# The segmentation boundary was not loaded anyway...
# DefaultBoundary(xenium.obj[["zoom"]]) <- "segmentation"
SpatDimPlot(xenium.obj, fov = "zoom", image = "black", features = c("Gad1", "Sst", "Npy2r", "Pvalb", "Nrn1"),
nmols = 10000, points_size = 0.1, points_palette = "Set1", shapes = TRUE)
Warning message: āKey āXenium_ā taken, using āzoom_ā insteadā Warning message in SpatPlot.Seurat.FOV(object, fov = fov, boundaries = boundaries, : ā[SpatPlot] 'shapes' is set to TRUE, meaning the same boundaries as points will be used. You may want to provide a different boundaries for shapes. Otherwise the shapes is plotted as points.ā
InĀ [10]:
xenium.obj <- SCTransform(xenium.obj, assay = "Xenium")
xenium.obj <- RunPCA(xenium.obj, npcs = 30, features = rownames(xenium.obj))
xenium.obj <- RunUMAP(xenium.obj, dims = 1:30)
xenium.obj <- FindNeighbors(xenium.obj, reduction = "pca", dims = 1:30)
xenium.obj <- FindClusters(xenium.obj, resolution = 0.3)
Running SCTransform on assay: Xenium vst.flavor='v2' set. Using model with fixed slope and excluding poisson genes. Calculating cell attributes from input UMI matrix: log_umi Variance stabilizing transformation of count matrix of size 248 by 36553 Model formula is y ~ log_umi Get Negative Binomial regression parameters per gene Using 248 genes, 5000 cells Second step: Get residuals using fitted parameters for 248 genes Computing corrected count matrix for 248 genes Calculating gene attributes Wall clock passed: Time difference of 3.8174 secs Determine variable features Centering data matrix Place corrected count matrix in counts slot Set default assay to SCT PC_ 1 Positive: Slc17a7, Nrn1, Epha4, Neurod6, Nwd2, Gad1, Cpne4, Rasgrf2, Rims3, Lamp5 2010300C02Rik, Dkk3, Slc17a6, Pvalb, Garnl3, Cpne6, Fhod3, Plcxd2, Gad2, Tmem132d Kcnh5, Dner, Calb1, Bhlhe22, Bcl11b, Nell1, Bdnf, Rasl10a, Satb2, Arc Negative: Igf2, Dcn, Fmod, Slc13a4, Fn1, Aldh1a2, Col1a1, Ly6a, Cldn5, Spp1 Gfap, Nr2f2, Gjb2, Cyp1b1, Acta2, Pecam1, Adgrl4, Pdgfra, Acvrl1, Kdr Cd93, Ccn2, Cobll1, Fgd5, Sox17, Igfbp5, Carmn, Lyz2, Pglyrp1, Emcn PC_ 2 Positive: Gjc3, Opalin, Sox10, Gfap, Clmn, Vwc2l, Zfp536, Sema6a, Gpr17, Gng12 Tmem163, Prox1, Adamtsl1, Dpy19l1, Cobll1, Cdh20, Arhgef28, Igfbp5, Chrm2, Sema3d Carmn, Aqp4, Fign, Pdgfra, Cspg4, Ntsr2, Lyz2, Siglech, Adamts2, Rmst Negative: Slc17a7, Fn1, Igf2, Nrn1, Cldn5, Epha4, Neurod6, Ly6a, Dcn, Rasgrf2 Lamp5, Fmod, Aldh1a2, Dkk3, 2010300C02Rik, Slc13a4, Car4, Nwd2, Pecam1, Gad1 Col1a1, Igfbp4, Spp1, Cpne4, Rims3, Igfbp6, Acvrl1, Cpne6, Adgrl4, Calb1 PC_ 3 Positive: Cldn5, Ly6a, Adgrl4, Fn1, Pecam1, Acvrl1, Kdr, Cd93, Pglyrp1, Sox17 Emcn, Car4, Nostrin, Fgd5, Zfp366, Mecom, Slfn5, Paqr5, Arc, Cabp7 Cobll1, Laptm5, Acsbg1, Gjc3, Siglech, Opalin, Kctd12, Ntsr2, Trem2, Sema6a Negative: Slc13a4, Igf2, Dcn, Fmod, Aldh1a2, Nwd2, Col1a1, Vat1l, Calb2, Spp1 Pdgfra, Gjb2, Necab2, Slc17a6, Cyp1b1, Syt6, Nr2f2, Nrp2, Dner, Slit2 Col6a1, Cpne4, Spag16, Strip2, Sncg, Thsd7a, Ppp1r1b, Gucy1a1, Mapk4, Chat PC_ 4 Positive: Slc17a7, Dkk3, Cabp7, Neurod6, 2010300C02Rik, Arc, Epha4, Igfbp4, Bcl11b, Fmod Meis2, Laptm5, Dcn, Gad1, Bhlhe22, Aldh1a2, Cpne6, Rasl10a, Lamp5, Col1a1 Col6a1, Igfbp6, Gfap, Satb2, Trem2, Cplx3, Gm2115, Gfra2, Garnl3, Siglech Negative: Nwd2, Calb2, Slc17a6, Necab2, Syt6, Vat1l, Nrp2, Sncg, Cpne4, Cldn5 Ly6a, Dner, Gucy1a1, Thsd7a, Chat, Kctd8, Tmem163, Tacr1, Tmem255a, Cacna2d2 Adgrl4, Pecam1, Cntnap4, Rmst, Cbln1, Fn1, Kdr, Cd93, Inpp4b, Acvrl1 PC_ 5 Positive: Gad1, Pvalb, Gad2, Rab3b, Opalin, Gjc3, Dpy19l1, Cdh13, Sox10, Garnl3 Parm1, Rims3, Tmem132d, Lamp5, Neto2, Vip, Btbd11, Cntnap4, Plcxd2, Ccn2 Cort, Penk, Fn1, Fhod3, Zfp536, Spp1, Col6a1, Nxph3, Sst, Dcn Negative: Cabp7, Gfap, Aqp4, Laptm5, Ntsr2, Trem2, Siglech, Acsbg1, Cd53, Slc39a12 2010300C02Rik, Kctd12, Cpne4, Cd300c2, Bhlhe22, Gm2115, Ikzf1, Rfx4, Necab2, Igfbp5 Sipa1l3, Cpne6, Cd68, Clmn, Rmst, Nwd2, Nrp2, Orai2, Spi1, Prdm8 Warning message: āThe default method for RunUMAP has changed from calling Python UMAP via reticulate to the R-native UWOT using the cosine metric To use Python UMAP via reticulate, set umap.method to 'umap-learn' and metric to 'correlation' This message will be shown once per sessionā 23:39:15 UMAP embedding parameters a = 0.9922 b = 1.112 Found more than one class "dist" in cache; using the first, from namespace 'spam' Also defined by āBiocGenericsā 23:39:15 Read 36553 rows and found 30 numeric columns 23:39:15 Using Annoy for neighbor search, n_neighbors = 30 Found more than one class "dist" in cache; using the first, from namespace 'spam' Also defined by āBiocGenericsā 23:39:15 Building Annoy index with metric = cosine, n_trees = 50 0% 10 20 30 40 50 60 70 80 90 100% [----|----|----|----|----|----|----|----|----|----| * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | 23:39:19 Writing NN index file to temp file /tmp/m161047/RtmpHUkWS9/file3e09c1184c944 23:39:19 Searching Annoy index using 1 thread, search_k = 3000 23:39:31 Annoy recall = 100% 23:39:31 Commencing smooth kNN distance calibration using 1 thread with target n_neighbors = 30 23:39:33 Initializing from normalized Laplacian + noise (using RSpectra) 23:39:35 Commencing optimization for 200 epochs, with 1669008 positive edges 23:39:53 Optimization finished Computing nearest neighbor graph Computing SNN
Modularity Optimizer version 1.3.0 by Ludo Waltman and Nees Jan van Eck Number of nodes: 36553 Number of edges: 1340890 Running Louvain algorithm... Maximum modularity in 10 random starts: 0.9587 Number of communities: 28 Elapsed time: 4 seconds
InĀ [11]:
options(repr.plot.width = 6, repr.plot.height = 8)
SpatDimPlot(xenium.obj, image = "black", points_size = 0.1)
Warning message: āNo FOV associated with assay 'SCT', using global default FOVā
InĀ [12]:
options(repr.plot.width = 7, repr.plot.height = 8)
SpatFeaturePlot(xenium.obj, layer = "counts", image = "black",
features = "Slc17a7", points_size = 0.2, points_color_name = "Slc17a7 Expression")
Warning message: āNo FOV associated with assay 'SCT', using global default FOVā
InĀ [13]:
options(repr.plot.width = 8, repr.plot.height = 7)
crop <- Crop(xenium.obj[["fov"]], x = c(600, 2100), y = c(900, 4700))
xenium.obj[["crop"]] <- crop
p1 <- SpatFeaturePlot(xenium.obj, fov = "crop", features = "Slc17a7",
image = "black", points_size = 0.2)
# use ext argument to crop
p2 <- SpatFeaturePlot(xenium.obj, ext = c(600, 2100, 900, 4700), features = "Slc17a7",
image = "black", points_size = 0.2)
p1 + p2
Warning message: āKey āXenium_ā taken, using ācrop_ā insteadā Warning message in `[<-.data.frame`(`*tmp*`, , features, value = structure(list(: āreplacement element 1 has 36553 rows to replace 11872 rowsā Warning message: āNo FOV associated with assay 'SCT', using global default FOVā
Mini Xenium Dataset provided by Giotto vignette¶
See: https://drieslab.github.io/giotto_workshop_2024/xenium-1.html
InĀ [14]:
path <- "data/Xenium_Giotto_workshop"
# Load the Xenium data
g <- LoadXenium(path, fov = "fov")
# remove cells with 0 counts
g <- subset(g, subset = nCount_Xenium > 0)
g
Warning message: ācells did not contain a segmentation_method column. Skipping...ā
Error in option$fn(file.path(data.dir, option$filename)) : File not found
10X data contains more than one type and is being returned as a list containing matrices of each type. Warning message: āFeature names cannot have underscores ('_'), replacing with dashes ('-')ā Warning message: āFeature names cannot have underscores ('_'), replacing with dashes ('-')ā Warning message: āFeature names cannot have underscores ('_'), replacing with dashes ('-')ā Warning message: āFeature names cannot have underscores ('_'), replacing with dashes ('-')ā Warning message: āFeature names cannot have underscores ('_'), replacing with dashes ('-')ā Warning message: āFeature names cannot have underscores ('_'), replacing with dashes ('-')ā Warning message: āNot validating FOV objectsā Warning message: āNot validating Centroids objectsā Warning message: āNot validating Centroids objectsā Warning message: āNot validating FOV objectsā Warning message: āNot validating FOV objectsā Warning message: āNot validating FOV objectsā Warning message: āNot validating Seurat objectsā
An object of class Seurat 541 features across 7654 samples within 4 assays Active assay: Xenium (377 features, 0 variable features) 1 layer present: counts 3 other assays present: BlankCodeword, ControlCodeword, ControlProbe 1 spatial field of view present: fov
InĀ [15]:
# Simple Visualization
options(repr.plot.width = 7, repr.plot.height = 6)
SpatDimPlot(
g,
image = "black",
# put shapes at last
layers = c("image", "points", "shapes"),
features = c("ABCC11", "ACE2", "ACKR1", "ACTA2", "ACTG2", "ADAM28"),
shapes_border_color = "cyan",
shapes_border_size = 0.1,
shapes_fill_by = "black",
points_size = 0.1,
nmols = 10000
)
Warning message in SpatPlot.Seurat.FOV(object, fov = fov, boundaries = boundaries, : ā[SpatPlot] 'shapes' is set to TRUE, meaning the same boundaries as points will be used. You may want to provide a different boundaries for shapes. Otherwise the shapes is plotted as points.ā
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 Seurat_5.3.0 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] R.oo_1.26.0 tibble_3.2.1 [9] polyclip_1.10-6 fastDummies_1.7.3 [11] lifecycle_1.0.4 rprojroot_2.0.4 [13] hdf5r_1.3.8 globals_0.16.3 [15] lattice_0.22-6 MASS_7.3-60.0.1 [17] magrittr_2.0.3 plotly_4.10.4 [19] remotes_2.5.0 httpuv_1.6.15 [21] sctransform_0.4.1 spam_2.11-0 [23] sessioninfo_1.2.2 pkgbuild_1.4.4 [25] spatstat.sparse_3.1-0 reticulate_1.38.0 [27] cowplot_1.1.3 pbapply_1.7-2 [29] RColorBrewer_1.1-3 abind_1.4-5 [31] pkgload_1.3.4 zlibbioc_1.48.0 [33] Rtsne_0.17 GenomicRanges_1.54.1 [35] R.utils_2.12.3 purrr_1.0.2 [37] ggraph_2.2.1 BiocGenerics_0.48.1 [39] RCurl_1.98-1.13 tweenr_2.0.3 [41] evmix_2.12 circlize_0.4.16 [43] GenomeInfoDbData_1.2.11 IRanges_2.36.0 [45] S4Vectors_0.40.2 ggrepel_0.9.6 [47] irlba_2.3.5.1 listenv_0.9.1 [49] spatstat.utils_3.1-1 iNEXT_3.0.1 [51] MatrixModels_0.5-3 goftest_1.2-3 [53] RSpectra_0.16-1 scRepertoire_2.2.1 [55] spatstat.random_3.2-3 fitdistrplus_1.1-11 [57] parallelly_1.38.0 codetools_0.2-20 [59] DelayedArray_0.28.0 xml2_1.3.6 [61] ggforce_0.4.2 shape_1.4.6.1 [63] tidyselect_1.2.1 farver_2.1.2 [65] viridis_0.6.5 matrixStats_1.1.0 [67] stats4_4.3.3 base64enc_0.1-3 [69] spatstat.explore_3.2-6 jsonlite_1.8.8 [71] tidygraph_1.3.0 ellipsis_0.3.2 [73] progressr_0.14.0 ggalluvial_0.12.5 [75] ggridges_0.5.6 survival_3.7-0 [77] ggnewscale_0.5.0 tools_4.3.3 [79] stringdist_0.9.12 ica_1.0-3 [81] Rcpp_1.0.13 glue_1.8.0 [83] gridExtra_2.3 SparseArray_1.2.2 [85] MatrixGenerics_1.14.0 usethis_2.2.3 [87] GenomeInfoDb_1.38.1 IRdisplay_1.1 [89] dplyr_1.1.4 withr_3.0.1 [91] fastmap_1.2.0 fansi_1.0.6 [93] SparseM_1.84 digest_0.6.37 [95] R6_2.5.1 mime_0.12 [97] colorspace_2.1-1 scattermore_1.2 [99] tensor_1.5 spatstat.data_3.1-2 [101] R.methodsS3_1.8.2 utf8_1.2.4 [103] tidyr_1.3.1 generics_0.1.3 [105] data.table_1.15.4 graphlayouts_1.1.0 [107] httr_1.4.7 htmlwidgets_1.6.4 [109] S4Arrays_1.2.0 uwot_0.1.16 [111] pkgconfig_2.0.3 gtable_0.3.5 [113] lmtest_0.9-40 SingleCellExperiment_1.24.0 [115] XVector_0.42.0 htmltools_0.5.8.1 [117] profvis_0.3.8 dotCall64_1.2 [119] scales_1.3.0 Biobase_2.62.0 [121] png_0.1-8 ggdendro_0.2.0 [123] rstudioapi_0.16.0 rjson_0.2.21 [125] reshape2_1.4.4 uuid_1.2-0 [127] nlme_3.1-165 GlobalOptions_0.1.2 [129] repr_1.1.7 cachem_1.1.0 [131] zoo_1.8-12 stringr_1.5.1 [133] KernSmooth_2.23-24 parallel_4.3.3 [135] miniUI_0.1.1.1 arrow_19.0.1 [137] desc_1.4.3 pillar_1.9.0 [139] grid_4.3.3 vctrs_0.6.5 [141] RANN_2.6.1 urlchecker_1.0.1 [143] VGAM_1.1-12 promises_1.3.0 [145] xtable_1.8-4 cluster_2.1.6 [147] evaluate_0.24.0 truncdist_1.0-2 [149] cli_3.6.3 compiler_4.3.3 [151] rlang_1.1.4 crayon_1.5.3 [153] future.apply_1.11.2 forcats_1.0.0 [155] plyr_1.8.9 fs_1.6.4 [157] stringi_1.8.7 viridisLite_0.4.2 [159] deldir_2.0-4 assertthat_0.2.1 [161] gsl_2.1-8 munsell_0.5.1 [163] lazyeval_0.2.2 devtools_2.4.5 [165] spatstat.geom_3.2-9 quantreg_5.98 [167] Matrix_1.6-5 IRkernel_1.3.2 [169] RcppHNSW_0.6.0 patchwork_1.3.0 [171] bit64_4.0.5 future_1.34.0 [173] ggplot2_3.5.1 shiny_1.8.1.1 [175] plotthis_0.7.0 SummarizedExperiment_1.32.0 [177] evd_2.3-7.1 ROCR_1.0-11 [179] gridtext_0.1.5 igraph_1.5.1 [181] memoise_2.0.1 bit_4.0.5