scplotter to work with seqFISH data prepared by Giotto¶

The technology. seqFISH reads a targeted panel of transcripts by repeatedly hybridising and imaging fluorescent probes, using sequential barcodes to identify each molecule and redundant barcodes to correct errors. It is an imaging method, so every transcript keeps its subcellular position, and the panel — not the whole transcriptome — defines what can be measured.

What this notebook covers. Loading a compact seqFISH object, clustering it, and exercising the scplotter spatial and compositional views on a small object — a quick, low-cost notebook for checking that an installation works end to end.

Data. The mini seqFISH cortex object distributed through GiottoData, so no external download is needed.

Before you run. A Giotto Python environment for Leiden/UMAP.

Upstream tutorial.

  • https://giottosuite.com/articles/mini_seqfish.html

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

In [1]:
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
In [2]:
seqfish_mini <- GiottoData::loadGiottoMini("seqfish")
seqfish_mini
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:  cell 
>Active feat_type:  rna 
dimensions    : 1774, 118 (features, cells)
[SUBCELLULAR INFO]
[AGGREGATE INFO]
expression -----------------------
  [cell][rna] raw
spatial locations ----------------
  [cell] raw


Use objHistory() to see steps and params used
In [3]:
seqfish_mini <- filterGiotto(gobject = seqfish_mini,
                             expression_threshold = 0.5,
                             feat_det_in_min_cells = 20,
                             min_det_feats_per_cell = 0)

seqfish_mini <- normalizeGiotto(gobject = seqfish_mini,
                                scalefactor = 6000,
                                verbose = TRUE)

seqfish_mini <- addStatistics(gobject = seqfish_mini)

seqfish_mini <- adjustGiottoMatrix(gobject = seqfish_mini,
                                   expression_values = "normalized",
                                   covariate_columns = c("nr_feats", "total_expr"))
seqfish_mini <- calculateHVF(gobject = seqfish_mini)
seqfish_mini <- runPCA(gobject = seqfish_mini)
seqfish_mini <- runUMAP(seqfish_mini,
                        dimensions_to_use = 1:5,
                        n_threads = 2)
seqfish_mini <- runtSNE(seqfish_mini,
                        dimensions_to_use = 1:5)
seqfish_mini <- createNearestNetwork(gobject = seqfish_mini,
                                     dimensions_to_use = 1:5,
                                     k = 5)

seqfish_mini <- doLeidenCluster(gobject = seqfish_mini,
                                resolution = 0.4,
                                n_iterations = 1000)
clusters_cell_types <- setNames(
    paste("cell", sort(unique(as.character(seqfish_mini$leiden_clus)))),
    sort(unique(as.character(seqfish_mini$leiden_clus)))
)

seqfish_mini <- annotateGiotto(gobject = seqfish_mini,
                               annotation_vector = clusters_cell_types,
                               cluster_column = "leiden_clus",
                               name = "cell_types")
seqfish_mini <- createSpatialNetwork(gobject = seqfish_mini,
                                     minimum_k = 2,
                                     maximum_distance_delaunay = 400)

seqfish_mini <- createSpatialNetwork(gobject = seqfish_mini,
                                     minimum_k = 2,
                                     method = "kNN",
                                     k = 10)
km_spatialfeats <- binSpect(seqfish_mini)
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:  0  out of  118 
Number of feats removed:  435  out of  1774 
first scale feats and then cells

Setting expression [cell][rna] normalized

Setting expression [cell][rna] scaled

calculating statistics for "normalized" expression

design matrix of interest not specified. Assuming a one-group experiment.

Setting expression [cell][rna] custom

"hvf" column was found in the feats metadata information and will be
 used to select highly variable features

Warning message:
“[runPCA] ncp (100) >= minimum dimension of input (82), setting ncp = 81”
Warning message in (function (A, nv = 5, nu = nv, maxit = 1000, work = nv + 7, reorth = TRUE, :
“You're computing too large a percentage of total singular values, use a standard svd instead.”
Warning message in (function (A, nv = 5, nu = nv, maxit = 1000, work = nv + 7, reorth = TRUE, :
“did not converge--results might be invalid!; try increasing work or maxit”
Setting dimension reduction [cell][rna] pca

Setting dimension reduction [cell][rna] umap

Setting dimension reduction [cell][rna] tsne

As of Giotto 4.2.3 doLeidenCluster() works via {igraph}
 For the python implementation, use doLeidenClusterPython()
 This message appears once per session.

Getting values from [cell][rna] cell metadata

Getting values from [cell][rna] cell metadata

Setting spatial network [cell] Delaunay_network

Setting spatial network [cell] kNN_network

This is the single parameter version of binSpect

1. matrix binarization complete

2. spatial enrichment test completed

3. (optional) average expression of high
 expressing cells calculated

4. (optional) number of high expressing cells
 calculated

In [4]:
options(repr.plot.width = 14, repr.plot.height = 12)

p1 <- CellDimPlot(seqfish_mini, group_by = "cell_types")
p2 <- CellDimPlot(seqfish_mini, group_by = "cell_types", reduction = "umap")
p3 <- CellDimPlot(seqfish_mini, group_by = "cell_types", reduction = "tsne")
p4 <- CellDimPlot(seqfish_mini, group_by = "leiden_clus", reduction = "umap",
    graph = TRUE, pt_size = 2.5)

(p1 + p2) / (p3 + p4)
No description has been provided for this image
In [5]:
options(repr.plot.width = 14, repr.plot.height = 6)

seqfish_mini@cell_metadata$cell$rna$leiden_clus <- factor(
    seqfish_mini@cell_metadata$cell$rna$leiden_clus
)

p1 <- SpatDimPlot(seqfish_mini,
            size = 5,
            group_by = "leiden_clus")
p2 <- SpatDimPlot(seqfish_mini,
            size = 5,
            group_by = "cell_types")

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

p1 <- SpatDimPlot(seqfish_mini,
    size = 2,
    graph = "Delaunay_network",
    edge_color = "blue",
    edge_size = 1,
    edge_alpha = 0.5,
    group_by = "leiden_clus")
p2 <- SpatDimPlot(seqfish_mini,
    size = 2,
    graph = "kNN_network",
    edge_color = "blue",
    edge_size = 1,
    edge_alpha = 0.5,
    group_by = "leiden_clus")
p1 + p2
No description has been provided for this image
In [7]:
options(repr.plot.width = 10, repr.plot.height = 10)

SpatFeaturePlot(
    seqfish_mini,
    layer = "scaled",
    shape = 21,
    size = 3.5,
    border_color = "lightgrey",
    features = km_spatialfeats[1:4]$feats
)
No description has been provided for this image
In [8]:
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           limma_3.66.0               
 [43] VGAM_1.1-14                 rstudioapi_0.19.0          
 [45] FNN_1.1.4.1                 generics_0.1.4             
 [47] shape_1.4.6.1               gtools_3.9.5               
 [49] ica_1.0-3                   spatstat.random_3.5-1      
 [51] dplyr_1.2.1                 Matrix_1.7-6               
 [53] S4Vectors_0.48.1            abind_1.4-8                
 [55] R.methodsS3_1.8.2           terra_1.9-1                
 [57] lifecycle_1.0.5             SummarizedExperiment_1.40.0
 [59] SparseArray_1.10.10         Rtsne_0.17                 
 [61] grid_4.5.1                  promises_1.5.0             
 [63] crayon_1.5.3                miniUI_0.1.2               
 [65] lattice_0.23-1              beachmat_2.26.0            
 [67] cowplot_1.2.0               magick_2.9.1               
 [69] pillar_1.11.1               GenomicRanges_1.62.1       
 [71] rjson_0.2.23                future.apply_1.20.2        
 [73] codetools_0.2-20            glue_1.8.1                 
 [75] getPass_0.2-4               spatstat.univar_3.2-0      
 [77] data.table_1.18.6.1         vctrs_0.7.3                
 [79] png_0.1-9                   spam_2.11-4                
 [81] gtable_0.3.6                assertthat_0.2.1           
 [83] cachem_1.1.0                S4Arrays_1.10.1            
 [85] mime_0.13                   tidygraph_1.3.1            
 [87] Seqinfo_1.0.0               survival_3.8-12            
 [89] SingleCellExperiment_1.32.0 units_1.0-1                
 [91] statmod_1.5.2               bluster_1.20.0             
 [93] GiottoData_0.3.8            ellipsis_0.3.3             
 [95] scRepertoire_2.2.1          fitdistrplus_1.2-6         
 [97] ROCR_1.0-12                 nlme_3.1-171               
 [99] usethis_3.2.1               RcppAnnoy_0.0.23           
[101] evd_2.3-7.1                 rprojroot_2.1.1            
[103] irlba_2.3.7                 KernSmooth_2.23-27         
[105] otel_0.2.0                  DBI_1.3.0                  
[107] plotthis_0.14.1             colorspace_2.1-3           
[109] BiocGenerics_0.56.0         tidyselect_1.2.1           
[111] compiler_4.5.1              BiocNeighbors_2.4.0        
[113] SparseM_1.84-2              xml2_1.6.0                 
[115] desc_1.4.3                  ggdendro_0.2.0             
[117] DelayedArray_0.36.1         plotly_4.12.1              
[119] checkmate_2.3.4             scales_1.4.0               
[121] classInt_0.4-11             lmtest_0.9-40              
[123] rappdirs_0.3.4              goftest_1.2-3              
[125] stringr_1.6.0               SpatialExperiment_1.20.0   
[127] digest_0.6.39               spatstat.utils_3.2-4       
[129] XVector_0.50.0              htmltools_0.5.9            
[131] GiottoVisuals_0.2.15.1      pkgconfig_2.0.3            
[133] base64enc_0.1-6             sparseMatrixStats_1.22.0   
[135] MatrixGenerics_1.22.0       fastmap_1.2.0              
[137] rlang_1.3.0                 GlobalOptions_0.1.4        
[139] htmlwidgets_1.6.4           shiny_1.14.0               
[141] farver_2.1.2                zoo_1.9-0                  
[143] jsonlite_2.0.0              BiocParallel_1.44.0        
[145] R.oo_1.27.1                 BiocSingular_1.26.1        
[147] magrittr_2.0.5              dotCall64_1.2              
[149] patchwork_1.3.2             IRkernel_1.3.2             
[151] Rcpp_1.1.2                  evmix_2.12                 
[153] ggnewscale_0.5.2            viridis_0.6.5              
[155] reticulate_1.47.0           truncdist_1.0-2            
[157] stringi_1.8.9               ggalluvial_0.12.6          
[159] ggraph_2.2.2                brio_1.1.5                 
[161] MASS_7.3-66                 plyr_1.8.9                 
[163] pkgbuild_1.4.8              parallel_4.5.1             
[165] listenv_1.0.0               ggrepel_0.9.8              
[167] forcats_1.0.1               deldir_2.0-4               
[169] graphlayouts_1.2.5          IRdisplay_1.1              
[171] splines_4.5.1               gridtext_0.1.6             
[173] tensor_1.5.1                circlize_0.4.18            
[175] colorRamp2_0.1.1            igraph_2.3.3               
[177] uuid_1.2-2                  spatstat.geom_3.8-2        
[179] cubature_2.1.4-1            RcppHNSW_0.7.0             
[181] ScaledMatrix_1.18.0         reshape2_1.4.5             
[183] stats4_4.5.1                pkgload_1.5.3              
[185] evaluate_1.0.5              SeuratObject_5.4.0         
[187] tweenr_2.0.3                httpuv_1.6.17              
[189] MatrixModels_0.5-4          RANN_2.6.3                 
[191] tidyr_1.3.2                 purrr_1.2.2                
[193] polyclip_1.10-7             future_1.75.0              
[195] scattermore_1.2             ggplot2_4.0.3              
[197] ggforce_0.5.0               rsvd_1.0.5                 
[199] xtable_1.8-8                e1071_1.7-17               
[201] RSpectra_0.16-2             later_1.4.8                
[203] class_7.3-24                viridisLite_0.4.3          
[205] ragg_1.5.2                  gsl_2.1-9                  
[207] tibble_3.3.1                memoise_2.0.1              
[209] IRanges_2.44.0              cluster_2.1.8.3            
[211] globals_0.19.1