scplotter to work with Nanostring CosMx data prepared by Seurat¶

See: https://satijalab.org/seurat/articles/seurat5_spatial_vignette_2#human-lung-nanostring-cosmx-spatial-molecular-imager

Go back to scplotter documentation: https://pwwang.github.io/scplotter/

InĀ [1]:
options(future.globals.maxSize = 512 * 1024^3) # 512 GB
suppressPackageStartupMessages({
    library(Seurat)
})
# Load the scplotter package
# library(scplotter)
devtools::load_all()
# devtools::load_all("../../../plotthis")

# see also the vignette for scplotter to work with CosMx data prepared by Giotto
data.dir <- "data/CosMx_Quarter_Brain/Quarter_Brain"
obj <- LoadNanostring(data.dir = data.dir, fov = 'fov')
obj
ℹ Loading scplotter
An object of class Seurat 
960 features across 38987 samples within 1 assay 
Active assay: Nanostring (960 features, 0 variable features)
 1 layer present: counts
 1 spatial field of view present: fov
InĀ [13]:
options(repr.plot.width = 8, repr.plot.height = 4.5)

SpatDimPlot(obj, points_size = 0.5)
ℹ Loading scplotter
No description has been provided for this image
InĀ [14]:
# add fake annotations

obj$celltype <- sample(LETTERS[1:10], size = ncol(obj), replace = TRUE)
obj$celltype <- factor(obj$celltype, levels = LETTERS[1:10])
Idents(obj) <- "celltype"

options(repr.plot.width = 8, repr.plot.height = 4.5)
SpatDimPlot(obj, image = "black", group_by = "celltype", points_size = 0.5,
    theme = "theme_this")
No description has been provided for this image
InĀ [15]:
options(repr.plot.width = 8, repr.plot.height = 4.5)

subobj <- subset(obj, celltype %in% c("A", "B", "C"))

SpatFeaturePlot(subobj, image = "black", group_by = "celltype", points_size = 0.5)
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 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ā€
Warning message:
ā€œNot validating FOV objectsā€
Warning message:
ā€œNot validating Centroids objectsā€
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:
ā€œAdding image with unordered cellsā€
Warning message:
ā€œNot validating Seurat objectsā€
No description has been provided for this image
InĀ [16]:
options(repr.plot.width = 8, repr.plot.height = 9)

p1 <- SpatFeaturePlot(obj, image = "black", features = "Chrna4", layer = "counts", points_size = 0.5)
p2 <- SpatDimPlot(obj, image = "black", features = c('Chrna4', 'Slc6a1', 'Cd109', 'Ldha', 'Aldoc'),
    points_size = 0.25, nmols = 10000)

p1 / p2
No description has been provided for this image
InĀ [17]:
options(repr.plot.width = 12, repr.plot.height = 5)

# Note that Crop() swapped x and y
crop <- Crop(obj[["fov"]], y = c(130000, 135000), x = c(0, 5000))
obj[["zoom1"]] <- crop
DefaultBoundary(obj[["zoom1"]]) <- "segmentation"
# devtools::load_all()

# Use cropped fov
p1 <- SpatDimPlot(obj, fov = "zoom1", points = FALSE, shapes_fill_by = "celltype",
    shapes_border_size = 0.1, theme = "theme_this")

# Or just pass the desired extent
# Note that the extent is in the right x and y order
p2 <- SpatDimPlot(obj, fov = "fov", points = FALSE, shapes_fill_by = "celltype",
    shapes = "segmentation",  # pass the boundary name, since centroids are the default
    shapes_border_size = 0.1, ext = c(130000, 135000, 0, 5000), theme = "theme_this")

p1 + p2
Warning message:
ā€œKey ā€˜Nanostring_’ taken, using ā€˜zoom1_’ insteadā€
Warning message:
ā€œAdding image with unordered cellsā€
No description has been provided for this image
InĀ [18]:
options(repr.plot.width = 6, repr.plot.height = 5)

SpatDimPlot(
    obj, fov = "zoom1", image = "black",
    features = c('Chrna4', 'Slc6a1', 'Cd109', 'Ldha', 'Aldoc'),
    points_size = 0.25, nmols = 10000
)
No description has been provided for this image
InĀ [19]:
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] spatstat.data_3.1-2         proxy_0.4-27               
 [31] ggridges_0.5.6              pbapply_1.7-2              
 [33] pbdZMQ_0.3-11               stringdist_0.9.12          
 [35] parallelly_1.38.0           sessioninfo_1.2.2          
 [37] VGAM_1.1-12                 rstudioapi_0.16.0          
 [39] generics_0.1.3              shape_1.4.6.1              
 [41] ica_1.0-3                   spatstat.random_3.2-3      
 [43] dplyr_1.1.4                 Matrix_1.6-5               
 [45] fansi_1.0.6                 S4Vectors_0.40.2           
 [47] abind_1.4-5                 terra_1.8-42               
 [49] lifecycle_1.0.4             SummarizedExperiment_1.32.0
 [51] SparseArray_1.2.2           Rtsne_0.17                 
 [53] grid_4.3.3                  promises_1.3.0             
 [55] crayon_1.5.3                miniUI_0.1.1.1             
 [57] lattice_0.22-6              cowplot_1.1.3              
 [59] pillar_1.9.0                GenomicRanges_1.54.1       
 [61] rjson_0.2.21                future.apply_1.11.2        
 [63] codetools_0.2-20            glue_1.8.0                 
 [65] data.table_1.15.4           remotes_2.5.0              
 [67] vctrs_0.6.5                 png_0.1-8                  
 [69] spam_2.11-0                 testthat_3.2.1.1           
 [71] gtable_0.3.5                assertthat_0.2.1           
 [73] cachem_1.1.0                S4Arrays_1.2.0             
 [75] mime_0.12                   tidygraph_1.3.0            
 [77] survival_3.7-0              SingleCellExperiment_1.24.0
 [79] units_0.8-5                 ellipsis_0.3.2             
 [81] fitdistrplus_1.1-11         scRepertoire_2.2.1         
 [83] ROCR_1.0-11                 nlme_3.1-165               
 [85] usethis_2.2.3               RcppAnnoy_0.0.22           
 [87] evd_2.3-7.1                 GenomeInfoDb_1.38.1        
 [89] rprojroot_2.0.4             irlba_2.3.5.1              
 [91] KernSmooth_2.23-24          plotthis_0.7.1             
 [93] colorspace_2.1-1            BiocGenerics_0.48.1        
 [95] DBI_1.2.3                   tidyselect_1.2.1           
 [97] compiler_4.3.3              SparseM_1.84               
 [99] xml2_1.3.6                  desc_1.4.3                 
[101] ggdendro_0.2.0              DelayedArray_0.28.0        
[103] plotly_4.10.4               scales_1.3.0               
[105] classInt_0.4-10             lmtest_0.9-40              
[107] stringr_1.5.1               digest_0.6.37              
[109] goftest_1.2-3               spatstat.utils_3.1-1       
[111] XVector_0.42.0              htmltools_0.5.8.1          
[113] pkgconfig_2.0.3             base64enc_0.1-3            
[115] MatrixGenerics_1.14.0       fastmap_1.2.0              
[117] rlang_1.1.4                 GlobalOptions_0.1.2        
[119] htmlwidgets_1.6.4           shiny_1.8.1.1              
[121] farver_2.1.2                zoo_1.8-12                 
[123] jsonlite_1.8.8              RCurl_1.98-1.13            
[125] magrittr_2.0.3              GenomeInfoDbData_1.2.11    
[127] dotCall64_1.2               patchwork_1.3.0            
[129] IRkernel_1.3.2              munsell_0.5.1              
[131] Rcpp_1.0.13                 evmix_2.12                 
[133] ggnewscale_0.5.0            viridis_0.6.5              
[135] reticulate_1.38.0           truncdist_1.0-2            
[137] stringi_1.8.7               ggalluvial_0.12.5          
[139] ggraph_2.2.1                brio_1.1.5                 
[141] zlibbioc_1.48.0             MASS_7.3-60.0.1            
[143] plyr_1.8.9                  pkgbuild_1.4.4             
[145] parallel_4.3.3              listenv_0.9.1              
[147] ggrepel_0.9.6               forcats_1.0.0              
[149] deldir_2.0-4                graphlayouts_1.1.0         
[151] IRdisplay_1.1               splines_4.3.3              
[153] gridtext_0.1.5              tensor_1.5                 
[155] circlize_0.4.16             igraph_1.5.1               
[157] uuid_1.2-0                  spatstat.geom_3.2-9        
[159] cubature_2.1.1              RcppHNSW_0.6.0             
[161] reshape2_1.4.4              stats4_4.3.3               
[163] pkgload_1.3.4               evaluate_0.24.0            
[165] tweenr_2.0.3                httpuv_1.6.15              
[167] MatrixModels_0.5-3          RANN_2.6.1                 
[169] tidyr_1.3.1                 purrr_1.0.2                
[171] polyclip_1.10-6             future_1.34.0              
[173] scattermore_1.2             ggplot2_3.5.1              
[175] ggforce_0.4.2               xtable_1.8-4               
[177] e1071_1.7-14                RSpectra_0.16-1            
[179] later_1.3.2                 viridisLite_0.4.2          
[181] class_7.3-22                gsl_2.1-8                  
[183] tibble_3.2.1                memoise_2.0.1              
[185] IRanges_2.36.0              cluster_2.1.6              
[187] globals_0.16.3