scplotter to work with Slide-seq data prepared by Giotto¶
The technology. Slide-seq and Slide-seqV2 deposit a lawn of barcoded beads about 10 um across on a puck, then place a tissue section on top. RNA captured by each bead is sequenced, giving near-single-cell resolution without any microscopy — there is no tissue image at all, so spatial plots are drawn on bead coordinates.
What this notebook covers. Building a Giotto object from a bead-location table plus a beads-by-genes matrix, filtering and normalising, clustering, and plotting. Because there is no image, it is a good example of how much of a spatial figure can be carried by points and cluster colour alone.
Data. Mouse cerebellum (Slide-seqV2). The mouse-brain puck originally referenced by the Giotto tutorial lives on NeMO, which is unreachable from many networks; the cerebellum set has the same shape — bead coordinates plus a counts matrix — and is the substitute used here.
Before you run. A Giotto Python environment for the clustering calls.
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
library(Giotto)
## Set instructions
results_folder <- "data/Giotto_SlideSeq.results"
instructions <- createGiottoInstructions(
save_dir = results_folder,
save_plot = FALSE,
show_plot = TRUE,
return_plot = TRUE,
python_path = python_path
)
## Provide the path to the visium folder
data_path <- "data/Giotto_SlideSeq"
expression_matrix <- local({
dge <- data.table::fread(file.path(data_path, "MappedDGEForR.csv"), header = TRUE)
m <- as.matrix(dge[, -1, with = FALSE])
rownames(m) <- dge[[1]]
m
})
spatial_locs <- data.table::fread(file.path(data_path, "BeadLocationsForR.csv"))
spatial_locs <- spatial_locs[spatial_locs$barcodes %in% colnames(expression_matrix),]
giotto_object <- createGiottoObject(
expression = expression_matrix,
spatial_locs = spatial_locs,
instructions = instructions
)
force(giotto_object)
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"”
Warning message: “[createExprObj] param 'expression_matrix_class' is deprecated”
An object of class giotto >Active spat_unit: cell >Active feat_type: rna dimensions : 18671, 25551 (features, cells) [SUBCELLULAR INFO] [AGGREGATE INFO] expression ----------------------- [cell][rna] raw spatial locations ---------------- [cell] raw Use objHistory() to see steps and params used
options(repr.plot.width = 12, repr.plot.height = 6)
# devtools::load_all()
p1 <- SpatDimPlot(giotto_object, points_size = 2, points_color_by = "lightblue")
p2 <- SpatDimPlot(giotto_object, points_size = 2, points_color_by = "lightblue",
points_shape = 21, points_border_color = "grey40")
p1 + p2
giotto_object <- filterGiotto(giotto_object,
min_det_feats_per_cell = 10,
feat_det_in_min_cells = 10)
giotto_object <- normalizeGiotto(giotto_object)
giotto_object <- addStatistics(giotto_object)
giotto_object <- runPCA(giotto_object)
giotto_object <- runUMAP(giotto_object,
dimensions_to_use = 1:10)
giotto_object <- createNearestNetwork(giotto_object)
giotto_object <- doLeidenCluster(giotto_object,
resolution = 1)
completed 1: preparation
completed 2: subset expression data
completed 3: subset spatial locations
completed 4: subset cell metadata
completed 5: subset feature metadata
completed 6: subset spatial network(s)
completed 7: subsetted dimension reductions
completed 8: subsetted nearest network(s)
completed 9: subsetted spatial enrichment results
Feature type: rna Number of cells removed: 210 out of 25551 Number of feats removed: 6582 out of 18671
first scale feats and then cells
Setting expression [cell][rna] normalized
Setting expression [cell][rna] scaled
calculating statistics for "normalized" expression
"hvf" was not found in the gene metadata information. all genes will be used.
Setting dimension reduction [cell][rna] pca
Setting dimension reduction [cell][rna] umap
As of Giotto 4.2.3 doLeidenCluster() works via {igraph}
For the python implementation, use doLeidenClusterPython()
This message appears once per session.
options(repr.plot.width = 7, repr.plot.height = 7)
# devtools::load_all()
SpatFeaturePlot(giotto_object, features = "nr_feats", points_shape = 21,
points_palette = "Reds", points_border_color = "grey")
options(repr.plot.width = 7, repr.plot.height = 7)
SpatDimPlot(giotto_object, group_by = "leiden_clus")
options(repr.plot.width = 14, repr.plot.height = 6.5)
p1 <- CellDimPlot(giotto_object, group_by = "leiden_clus", label = TRUE)
p2 <- CellDimPlot(giotto_object, group_by = "leiden_clus", reduction = "umap", label = 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 dbscan_1.2.6 [37] R.utils_2.13.0 stringdist_0.9.17 [39] dichromat_2.0-1 parallelly_1.48.0 [41] sessioninfo_1.2.4 VGAM_1.1-14 [43] rstudioapi_0.19.0 generics_0.1.4 [45] shape_1.4.6.1 gtools_3.9.5 [47] ica_1.0-3 spatstat.random_3.5-1 [49] dplyr_1.2.1 Matrix_1.7-6 [51] S4Vectors_0.48.1 abind_1.4-8 [53] R.methodsS3_1.8.2 terra_1.9-1 [55] lifecycle_1.0.5 SummarizedExperiment_1.40.0 [57] SparseArray_1.10.10 Rtsne_0.17 [59] grid_4.5.1 promises_1.5.0 [61] crayon_1.5.3 miniUI_0.1.2 [63] lattice_0.23-1 beachmat_2.26.0 [65] cowplot_1.2.0 magick_2.9.1 [67] pillar_1.11.1 GenomicRanges_1.62.1 [69] rjson_0.2.23 future.apply_1.20.2 [71] codetools_0.2-20 glue_1.8.1 [73] getPass_0.2-4 spatstat.univar_3.2-0 [75] data.table_1.18.6.1 vctrs_0.7.3 [77] png_0.1-9 spam_2.11-4 [79] gtable_0.3.6 assertthat_0.2.1 [81] cachem_1.1.0 S4Arrays_1.10.1 [83] mime_0.13 tidygraph_1.3.1 [85] Seqinfo_1.0.0 survival_3.8-12 [87] SingleCellExperiment_1.32.0 units_1.0-1 [89] bluster_1.20.0 ellipsis_0.3.3 [91] scRepertoire_2.2.1 fitdistrplus_1.2-6 [93] ROCR_1.0-12 nlme_3.1-171 [95] usethis_3.2.1 RcppAnnoy_0.0.23 [97] evd_2.3-7.1 rprojroot_2.1.1 [99] irlba_2.3.7 KernSmooth_2.23-27 [101] otel_0.2.0 DBI_1.3.0 [103] plotthis_0.14.1 colorspace_2.1-3 [105] BiocGenerics_0.56.0 tidyselect_1.2.1 [107] compiler_4.5.1 BiocNeighbors_2.4.0 [109] SparseM_1.84-2 xml2_1.6.0 [111] desc_1.4.3 ggdendro_0.2.0 [113] DelayedArray_0.36.1 plotly_4.12.1 [115] checkmate_2.3.4 scales_1.4.0 [117] classInt_0.4-11 lmtest_0.9-40 [119] rappdirs_0.3.4 goftest_1.2-3 [121] stringr_1.6.0 SpatialExperiment_1.20.0 [123] digest_0.6.39 spatstat.utils_3.2-4 [125] XVector_0.50.0 htmltools_0.5.9 [127] GiottoVisuals_0.2.15.1 pkgconfig_2.0.3 [129] base64enc_0.1-6 MatrixGenerics_1.22.0 [131] fastmap_1.2.0 rlang_1.3.0 [133] GlobalOptions_0.1.4 htmlwidgets_1.6.4 [135] shiny_1.14.0 farver_2.1.2 [137] zoo_1.9-0 jsonlite_2.0.0 [139] BiocParallel_1.44.0 R.oo_1.27.1 [141] BiocSingular_1.26.1 magrittr_2.0.5 [143] dotCall64_1.2 patchwork_1.3.2 [145] IRkernel_1.3.2 Rcpp_1.1.2 [147] evmix_2.12 ggnewscale_0.5.2 [149] viridis_0.6.5 reticulate_1.47.0 [151] truncdist_1.0-2 stringi_1.8.9 [153] ggalluvial_0.12.6 ggraph_2.2.2 [155] brio_1.1.5 MASS_7.3-66 [157] plyr_1.8.9 pkgbuild_1.4.8 [159] parallel_4.5.1 listenv_1.0.0 [161] ggrepel_0.9.8 forcats_1.0.1 [163] deldir_2.0-4 graphlayouts_1.2.5 [165] IRdisplay_1.1 splines_4.5.1 [167] gridtext_0.1.6 tensor_1.5.1 [169] circlize_0.4.18 colorRamp2_0.1.1 [171] igraph_2.3.3 uuid_1.2-2 [173] spatstat.geom_3.8-2 cubature_2.1.4-1 [175] RcppHNSW_0.7.0 ScaledMatrix_1.18.0 [177] reshape2_1.4.5 stats4_4.5.1 [179] pkgload_1.5.3 evaluate_1.0.5 [181] SeuratObject_5.4.0 tweenr_2.0.3 [183] httpuv_1.6.17 MatrixModels_0.5-4 [185] RANN_2.6.3 tidyr_1.3.2 [187] purrr_1.2.2 polyclip_1.10-7 [189] future_1.75.0 scattermore_1.2 [191] ggplot2_4.0.3 ggforce_0.5.0 [193] rsvd_1.0.5 xtable_1.8-8 [195] e1071_1.7-17 RSpectra_0.16-2 [197] later_1.4.8 class_7.3-24 [199] viridisLite_0.4.3 ragg_1.5.2 [201] gsl_2.1-9 tibble_3.3.1 [203] memoise_2.0.1 IRanges_2.44.0 [205] cluster_2.1.8.3 globals_0.19.1