scplotter to work with Vizgen MERSCOPE data prepared by Giotto¶
The technology. MERSCOPE (Vizgen) is a MERFISH instrument: transcripts are identified by combinatorial FISH barcodes and decoded per molecule, and the run also produces cell-boundary segmentations and multi-channel images. Like other imaging platforms it measures a defined gene panel at subcellular resolution rather than the whole transcriptome.
What this notebook covers. Creating a Giotto object from a MERSCOPE output directory, normalising, clustering, and plotting the result with scplotter's spatial methods — including overlaying expression on the segmented cells.
Data. The mouse brain MERSCOPE bundle from the Giotto website tutorial.
Before you run. A Giotto Python environment for clustering; the object is built from the vendor's flat files.
Upstream tutorial.
Go back to scplotter documentation: https://pwwang.github.io/scplotter/
library(Giotto)
# Ensure Giotto can access a python env
genv_exists <- suppressMessages(checkGiottoEnvironment())
print(genv_exists)
python_path <- Sys.getenv("GIOTTO_PYTHON")
Sys.setenv(RETICULATE_PYTHON = python_path)
invisible(capture.output(suppressMessages(set_giotto_python_path(python_path = python_path))))
# library(scplotter)
devtools::load_all()
Loading required package: GiottoClass
Giotto Suite 4.2.3
[1] TRUE
ℹ Loading scplotter
g <- GiottoData::loadGiottoMini(dataset = "vizgen")
g
1. read Giotto object
2. read Giotto feature information
3. read Giotto spatial information
4. read Giotto image information
python already initialized in this session active environment : 'giotto_env' python version : 3.10
Warning message: “Some of Giotto's expected python module(s) were not found: leidenalg, sklearn (This is fine if python-based functions are not needed) ** Python path used: "/fslustre/qhs/ext_wang_panwen_mayo_edu/scplotter-giotto/envs/giotto_env/bin/python"”
An object of class giotto >Active spat_unit: z0 >Active feat_type: rna dimensions : 337, 498 (features, cells) [SUBCELLULAR INFO] polygons : z0 z1 aggregate features : rna [AGGREGATE INFO] expression ----------------------- [z0][rna] raw [z1][rna] raw [aggregate][rna] raw normalized scaled pearson spatial locations ---------------- [z0] raw [z1] raw [aggregate] raw spatial networks ----------------- [aggregate] Delaunay_network kNN_network spatial enrichments -------------- [aggregate][rna] cluster_metagene dim reduction -------------------- [aggregate][rna] pca umap tsne nearest neighbor networks -------- [aggregate][rna] sNN.pca attached images ------------------ images : 4 items... Use objHistory() to see steps and params used
options(repr.plot.width = 7, repr.plot.height = 6)
SpatDimPlot(g)
options(repr.plot.width = 14, repr.plot.height = 6)
p1 <- SpatDimPlot(g, group_by = "leiden_clus", spat_unit = "aggregate")
p2 <- SpatDimPlot(g, group_by = "louvain_clus", spat_unit = "aggregate", palette = "Reds")
p1 + p2
options(repr.plot.width = 14, repr.plot.height = 6)
p1 <- SpatDimPlot(g, image = "dapi_z0", group_by = "leiden_clus", spat_unit = "aggregate")
p2 <- SpatFeaturePlot(g, image = "dapi_z0", features = "nr_feats", spat_unit = "aggregate")
p1 + p2
options(repr.plot.width = 7, repr.plot.height = 6)
p1 <- SpatFeaturePlot(g, features = "Slc47a1", spat_unit = "aggregate",
size = 3)
p1
options(repr.plot.width = 14, repr.plot.height = 6)
p1 <- SpatDimPlot(g, features = c("Oxgr1", "Htr1a", "Gjc3", "Axl", "Gfap", "Olig1", "Epha7"),
shapes_feat_type = "z0", shapes = TRUE, image = "black", shapes_fill_by = "white",
shapes_alpha = 1)
p2 <- SpatDimPlot(g, features = c("Oxgr1", "Htr1a", "Gjc3", "Axl", "Gfap", "Olig1", "Epha7"),
shapes_feat_type = "z0", shapes = TRUE, image = "black", shapes_fill_by = "white",
# put shpaes on top of points
shapes_alpha = 1, layers = c("image", "points", "shapes"))
p1 + p2
# Zoom in further and visualize with image
vizgen_subcellular_zoom <- subsetGiottoLocs(
g, poly_info = "z0",
x_min = 6600, x_max = 6800, y_min = -5000, y_max = -4800)
options(repr.plot.width = 14, repr.plot.height = 6)
p1 <- SpatDimPlot(vizgen_subcellular_zoom, image = TRUE,
features = c("Oxgr1", "Htr1a", "Gjc3", "Axl", "Gfap", "Olig1", "Epha7"),
shapes_feat_type = "z0", shapes = TRUE)
p2 <- SpatDimPlot(g, image = TRUE, ext = c(6600, 6800, -5000, -4800), # use ext to zoom in
features = c("Oxgr1", "Htr1a", "Gjc3", "Axl", "Gfap", "Olig1", "Epha7"),
shapes_feat_type = "z0", shapes = TRUE)
p1 + p2
x <- sessionInfo()
x <- capture.output(print(x))
# hide the BLAS/LAPACK paths
x <- x[!startsWith(x, "BLAS/LAPACK:")]
cat(paste(x, collapse = "\n"))
Warning message in system("timedatectl", intern = TRUE):
“running command 'timedatectl' had status 1”
R version 4.5.1 (2025-06-13) Platform: x86_64-pc-linux-gnu Running under: Rocky Linux 8.10 (Green Obsidian) Matrix products: default BLAS: /usr/lib64/libblas.so.3.8.0 LAPACK: /usr/lib64/liblapack.so.3.8.0 LAPACK version 3.8.0 locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [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: UTC tzcode source: system (glibc) attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] scplotter_0.8.2 testthat_3.3.2 Giotto_4.2.3 GiottoClass_0.5.1 loaded via a namespace (and not attached): [1] fs_2.1.0 matrixStats_1.5.0 [3] spatstat.sparse_3.2-0 sf_1.1-2 [5] devtools_2.5.2 httr_1.4.9 [7] RColorBrewer_1.1-3 repr_1.1.7 [9] tools_4.5.1 sctransform_0.4.3 [11] backports_1.5.1 R6_2.6.1 [13] uwot_0.2.5 withr_3.0.3 [15] sp_2.2-3 gridExtra_2.3.1 [17] GiottoUtils_0.2.9 progressr_1.0.0 [19] quantreg_6.1 cli_3.6.6 [21] Biobase_2.70.0 textshaping_1.0.5 [23] Cairo_1.7-0 spatstat.explore_3.8-2 [25] fastDummies_1.7.6 iNEXT_3.0.2 [27] labeling_0.4.3 Seurat_5.5.1 [29] S7_0.2.2 spatstat.data_3.1-9 [31] proxy_0.4-29 ggridges_0.5.7 [33] pbapply_1.7-5 systemfonts_1.3.2 [35] pbdZMQ_0.3-14 stringdist_0.9.17 [37] dichromat_2.0-1 parallelly_1.48.0 [39] sessioninfo_1.2.4 VGAM_1.1-14 [41] rstudioapi_0.19.0 generics_0.1.4 [43] shape_1.4.6.1 gtools_3.9.5 [45] ica_1.0-3 spatstat.random_3.5-1 [47] dplyr_1.2.1 Matrix_1.7-6 [49] S4Vectors_0.48.1 abind_1.4-8 [51] terra_1.9-1 lifecycle_1.0.5 [53] SummarizedExperiment_1.40.0 SparseArray_1.10.10 [55] Rtsne_0.17 grid_4.5.1 [57] promises_1.5.0 crayon_1.5.3 [59] miniUI_0.1.2 lattice_0.23-1 [61] cowplot_1.2.0 magick_2.9.1 [63] pillar_1.11.1 GenomicRanges_1.62.1 [65] rjson_0.2.23 future.apply_1.20.2 [67] codetools_0.2-20 glue_1.8.1 [69] getPass_0.2-4 spatstat.univar_3.2-0 [71] data.table_1.18.6.1 vctrs_0.7.3 [73] png_0.1-9 spam_2.11-4 [75] gtable_0.3.6 assertthat_0.2.1 [77] cachem_1.1.0 S4Arrays_1.10.1 [79] mime_0.13 tidygraph_1.3.1 [81] Seqinfo_1.0.0 survival_3.8-12 [83] SingleCellExperiment_1.32.0 units_1.0-1 [85] bluster_1.20.0 GiottoData_0.3.8 [87] ellipsis_0.3.3 scRepertoire_2.2.1 [89] fitdistrplus_1.2-6 ROCR_1.0-12 [91] nlme_3.1-171 usethis_3.2.1 [93] RcppAnnoy_0.0.23 evd_2.3-7.1 [95] rprojroot_2.1.1 irlba_2.3.7 [97] KernSmooth_2.23-27 otel_0.2.0 [99] DBI_1.3.0 plotthis_0.14.1 [101] colorspace_2.1-3 BiocGenerics_0.56.0 [103] tidyselect_1.2.1 compiler_4.5.1 [105] BiocNeighbors_2.4.0 SparseM_1.84-2 [107] xml2_1.6.0 desc_1.4.3 [109] ggdendro_0.2.0 DelayedArray_0.36.1 [111] plotly_4.12.1 checkmate_2.3.4 [113] scales_1.4.0 classInt_0.4-11 [115] lmtest_0.9-40 rappdirs_0.3.4 [117] goftest_1.2-3 stringr_1.6.0 [119] SpatialExperiment_1.20.0 digest_0.6.39 [121] spatstat.utils_3.2-4 XVector_0.50.0 [123] htmltools_0.5.9 GiottoVisuals_0.2.15.1 [125] pkgconfig_2.0.3 base64enc_0.1-6 [127] MatrixGenerics_1.22.0 fastmap_1.2.0 [129] rlang_1.3.0 GlobalOptions_0.1.4 [131] htmlwidgets_1.6.4 shiny_1.14.0 [133] farver_2.1.2 zoo_1.9-0 [135] jsonlite_2.0.0 BiocParallel_1.44.0 [137] magrittr_2.0.5 dotCall64_1.2 [139] patchwork_1.3.2 IRkernel_1.3.2 [141] Rcpp_1.1.2 evmix_2.12 [143] ggnewscale_0.5.2 viridis_0.6.5 [145] reticulate_1.47.0 truncdist_1.0-2 [147] stringi_1.8.9 ggalluvial_0.12.6 [149] ggraph_2.2.2 brio_1.1.5 [151] MASS_7.3-66 plyr_1.8.9 [153] pkgbuild_1.4.8 parallel_4.5.1 [155] listenv_1.0.0 ggrepel_0.9.8 [157] forcats_1.0.1 deldir_2.0-4 [159] graphlayouts_1.2.5 IRdisplay_1.1 [161] splines_4.5.1 gridtext_0.1.6 [163] tensor_1.5.1 circlize_0.4.18 [165] colorRamp2_0.1.1 igraph_2.3.3 [167] uuid_1.2-2 spatstat.geom_3.8-2 [169] cubature_2.1.4-1 RcppHNSW_0.7.0 [171] reshape2_1.4.5 stats4_4.5.1 [173] pkgload_1.5.3 evaluate_1.0.5 [175] SeuratObject_5.4.0 tweenr_2.0.3 [177] httpuv_1.6.17 MatrixModels_0.5-4 [179] RANN_2.6.3 tidyr_1.3.2 [181] purrr_1.2.2 polyclip_1.10-7 [183] future_1.75.0 scattermore_1.2 [185] ggplot2_4.0.3 ggforce_0.5.0 [187] xtable_1.8-8 e1071_1.7-17 [189] RSpectra_0.16-2 later_1.4.8 [191] class_7.3-24 viridisLite_0.4.3 [193] ragg_1.5.2 gsl_2.1-9 [195] tibble_3.3.1 memoise_2.0.1 [197] IRanges_2.44.0 cluster_2.1.8.3 [199] globals_0.19.1