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Ā [3]:
options(repr.plot.width = 6, repr.plot.height = 8)
SpatDimPlot(xenium.obj, image = "black", features = c("Gad1", "Sst", "Pvalb", "Gfap"),
nmols = 20000, points_size = 0.1, points_palette = "Set1")
ā¹ Loading scplotter
InĀ [13]:
options(repr.plot.width = 8, repr.plot.height = 12)
SpatFeaturePlot(xenium.obj, layer = "counts", image = "black",
features = c("Cux2", "Rorb", "Bcl11b", "Foxp2"), upper_quantile = 0.9,
points_size = 0.2, points_color_name = "Expression")
Warning message: āNo FOV associated with assay 'SCT', using global default FOVā
InĀ [5]:
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Ā [6]:
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.6532 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ā 17:51:03 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ā 17:51:03 Read 36553 rows and found 30 numeric columns 17:51:03 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ā 17:51:03 Building Annoy index with metric = cosine, n_trees = 50 0% 10 20 30 40 50 60 70 80 90 100% [----|----|----|----|----|----|----|----|----|----| * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | 17:51:07 Writing NN index file to temp file /tmp/m161047/RtmpjO2hoB/fileefcdf3ab23bb2 17:51:07 Searching Annoy index using 1 thread, search_k = 3000 17:51:18 Annoy recall = 100% 17:51:19 Commencing smooth kNN distance calibration using 1 thread with target n_neighbors = 30 17:51:21 Initializing from normalized Laplacian + noise (using RSpectra) 17:51:22 Commencing optimization for 200 epochs, with 1669008 positive edges 17:51:40 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Ā [7]:
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Ā [16]:
options(repr.plot.width = 7, repr.plot.height = 8)
SpatFeaturePlot(xenium.obj, layer = "counts", image = "black", upper_quantile = 0.9,
palette = "Reds", features = "Slc17a7", size = 0.2, color_name = "Slc17a7 Expression")
Warning message: āNo FOV associated with assay 'SCT', using global default FOVā
InĀ [26]:
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", size = 0.2, upper_quantile = .95)
# use ext argument to crop
p2 <- SpatFeaturePlot(xenium.obj, ext = c(600, 2100, 900, 4700), features = "Slc17a7",
image = "black", size = 0.2, upper_quantile = .95)
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Ā [10]:
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Ā [11]:
# 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Ā [12]:
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] fs_1.6.4 matrixStats_1.1.0 [3] spatstat.sparse_3.1-0 bitops_1.0-7 [5] sf_1.0-20 devtools_2.4.5 [7] httr_1.4.7 RColorBrewer_1.1-3 [9] repr_1.1.7 profvis_0.3.8 [11] tools_4.3.3 sctransform_0.4.1 [13] utf8_1.2.4 R6_2.5.1 [15] lazyeval_0.2.2 uwot_0.1.16 [17] urlchecker_1.0.1 withr_3.0.1 [19] gridExtra_2.3 progressr_0.14.0 [21] quantreg_5.98 cli_3.6.3 [23] Biobase_2.62.0 Cairo_1.6-2 [25] spatstat.explore_3.2-6 fastDummies_1.7.3 [27] iNEXT_3.0.1 labeling_0.4.3 [29] arrow_19.0.1 spatstat.data_3.1-2 [31] proxy_0.4-27 ggridges_0.5.6 [33] pbapply_1.7-2 pbdZMQ_0.3-11 [35] R.utils_2.12.3 stringdist_0.9.12 [37] parallelly_1.38.0 sessioninfo_1.2.2 [39] VGAM_1.1-12 rstudioapi_0.16.0 [41] generics_0.1.3 shape_1.4.6.1 [43] ica_1.0-3 spatstat.random_3.2-3 [45] dplyr_1.1.4 Matrix_1.6-5 [47] fansi_1.0.6 S4Vectors_0.40.2 [49] abind_1.4-5 R.methodsS3_1.8.2 [51] terra_1.8-42 lifecycle_1.0.4 [53] SummarizedExperiment_1.32.0 glmGamPoi_1.14.0 [55] SparseArray_1.2.2 Rtsne_0.17 [57] grid_4.3.3 promises_1.3.0 [59] crayon_1.5.3 miniUI_0.1.1.1 [61] lattice_0.22-6 cowplot_1.1.3 [63] pillar_1.9.0 GenomicRanges_1.54.1 [65] rjson_0.2.21 future.apply_1.11.2 [67] codetools_0.2-20 glue_1.8.0 [69] data.table_1.15.4 remotes_2.5.0 [71] vctrs_0.6.5 png_0.1-8 [73] spam_2.11-0 testthat_3.2.1.1 [75] gtable_0.3.5 assertthat_0.2.1 [77] cachem_1.1.0 S4Arrays_1.2.0 [79] mime_0.12 tidygraph_1.3.0 [81] survival_3.7-0 SingleCellExperiment_1.24.0 [83] units_0.8-5 ellipsis_0.3.2 [85] fitdistrplus_1.1-11 scRepertoire_2.2.1 [87] ROCR_1.0-11 nlme_3.1-165 [89] usethis_2.2.3 bit64_4.0.5 [91] RcppAnnoy_0.0.22 evd_2.3-7.1 [93] GenomeInfoDb_1.38.1 rprojroot_2.0.4 [95] irlba_2.3.5.1 KernSmooth_2.23-24 [97] DBI_1.2.3 plotthis_0.7.1 [99] colorspace_2.1-1 BiocGenerics_0.48.1 [101] tidyselect_1.2.1 bit_4.0.5 [103] compiler_4.3.3 hdf5r_1.3.8 [105] SparseM_1.84 xml2_1.3.6 [107] desc_1.4.3 ggdendro_0.2.0 [109] DelayedArray_0.28.0 plotly_4.10.4 [111] scales_1.3.0 classInt_0.4-10 [113] lmtest_0.9-40 stringr_1.5.1 [115] digest_0.6.37 goftest_1.2-3 [117] spatstat.utils_3.1-1 XVector_0.42.0 [119] htmltools_0.5.8.1 pkgconfig_2.0.3 [121] base64enc_0.1-3 sparseMatrixStats_1.14.0 [123] MatrixGenerics_1.14.0 fastmap_1.2.0 [125] rlang_1.1.4 GlobalOptions_0.1.2 [127] htmlwidgets_1.6.4 DelayedMatrixStats_1.24.0 [129] shiny_1.8.1.1 farver_2.1.2 [131] zoo_1.8-12 jsonlite_1.8.8 [133] R.oo_1.26.0 RCurl_1.98-1.13 [135] magrittr_2.0.3 GenomeInfoDbData_1.2.11 [137] dotCall64_1.2 patchwork_1.3.0 [139] IRkernel_1.3.2 munsell_0.5.1 [141] Rcpp_1.0.13 evmix_2.12 [143] ggnewscale_0.5.0 viridis_0.6.5 [145] reticulate_1.38.0 truncdist_1.0-2 [147] stringi_1.8.7 ggalluvial_0.12.5 [149] ggraph_2.2.1 brio_1.1.5 [151] zlibbioc_1.48.0 MASS_7.3-60.0.1 [153] plyr_1.8.9 pkgbuild_1.4.4 [155] parallel_4.3.3 listenv_0.9.1 [157] ggrepel_0.9.6 forcats_1.0.0 [159] deldir_2.0-4 graphlayouts_1.1.0 [161] IRdisplay_1.1 splines_4.3.3 [163] gridtext_0.1.5 tensor_1.5 [165] circlize_0.4.16 igraph_1.5.1 [167] uuid_1.2-0 spatstat.geom_3.2-9 [169] cubature_2.1.1 RcppHNSW_0.6.0 [171] reshape2_1.4.4 stats4_4.3.3 [173] pkgload_1.3.4 evaluate_0.24.0 [175] tweenr_2.0.3 httpuv_1.6.15 [177] MatrixModels_0.5-3 RANN_2.6.1 [179] tidyr_1.3.1 purrr_1.0.2 [181] polyclip_1.10-6 future_1.34.0 [183] scattermore_1.2 ggplot2_3.5.1 [185] ggforce_0.4.2 xtable_1.8-4 [187] e1071_1.7-14 RSpectra_0.16-1 [189] later_1.3.2 class_7.3-22 [191] viridisLite_0.4.2 gsl_2.1-8 [193] tibble_3.2.1 memoise_2.0.1 [195] IRanges_2.36.0 cluster_2.1.6 [197] globals_0.16.3