1 Overview

This vignette demonstrates how to load the stxBrain spatial transcriptomics dataset from SeuratData, preprocess it with Seurat (Hao et al. 2023), convert the resulting object into a GraphSpace object using RGraphSpace (Sysbiolab Team 2026), align the graph coordinates to the tissue image, and save the normalized GraphSpace object.

This vignette aims to save the stxBrain for the further analysis of cell-cell communication visualization. Please see the vignette: Plotting cell-cell communication in spatially resolved transcriptomics. This framework follows the same procedures presented in RGraphSpace: Spatial Data vignette.

2 Check required versions

# Check required versions
if (packageVersion("RGraphSpace") < "1.4.1") {
  message("Need to update 'RGraphSpace' for this vignette")
  remotes::install_github("sysbiolab/RGraphSpace")
}

if (packageVersion("PathwaySpace") < "1.4.1") {
  message("Need to update 'PathwaySpace' for this vignette")
  remotes::install_github("sysbiolab/PathwaySpace")
}

if (packageVersion("Seurat") < "5.5.0") {
  message("Need to update 'Seurat' for this vignette")
  remotes::install_github("satijalab/Seurat")
}

3 Load packages

library("RGraphSpace")
## Carregando pacotes exigidos: ggplot2
library("PathwaySpace")
library("Seurat")
## Carregando pacotes exigidos: SeuratObject
## Carregando pacotes exigidos: sp
## 
## Anexando pacote: 'SeuratObject'
## Os seguintes objetos são mascarados por 'package:base':
## 
##     intersect, t
library("SeuratObject")
library("SeuratData")
## ── Installed datasets ──────────────────────────────── SeuratData v0.2.2.9002 ──
## ✔ stxBrain 0.1.2
## ────────────────────────────────────── Key ─────────────────────────────────────
## ✔ Dataset loaded successfully
## ❯ Dataset built with a newer version of Seurat than installed
## ❓ Unknown version of Seurat installed
library("patchwork")
library("dplyr")
## 
## Anexando pacote: 'dplyr'
## Os seguintes objetos são mascarados por 'package:stats':
## 
##     filter, lag
## Os seguintes objetos são mascarados por 'package:base':
## 
##     intersect, setdiff, setequal, union
library("igraph")
## 
## Anexando pacote: 'igraph'
## Os seguintes objetos são mascarados por 'package:dplyr':
## 
##     as_data_frame, groups, union
## O seguinte objeto é mascarado por 'package:Seurat':
## 
##     components
## Os seguintes objetos são mascarados por 'package:stats':
## 
##     decompose, spectrum
## O seguinte objeto é mascarado por 'package:base':
## 
##     union

4 Install the Seurat dataset

The stxBrain dataset only needs to be installed once. To check which datasets are already installed, run:

SeuratData::InstalledData()
##                      Dataset Version                                 Summary
## stxBrain.SeuratData stxBrain   0.1.2 10X Genomics Visium Mouse Brain Dataset
##                     species system ncells   tech seurat default.dataset
## stxBrain.SeuratData   mouse  brain  12167 visium   <NA>              NA
##                     disk.datasets                               other.datasets
## stxBrain.SeuratData          <NA> posterior1, posterior2, anterior1, anterior2
##                                                                                         notes
## stxBrain.SeuratData One sample split across four datasets as paired anterior/posterior slices
##                     Installed InstalledVersion
## stxBrain.SeuratData      TRUE            0.1.2
if("stxBrain" %in% SeuratData::InstalledData()$Dataset ){
  message("stxBrain is already installed, no need to install it again.")
}else{
 SeuratData::InstallData("stxBrain") 
}
## stxBrain is already installed, no need to install it again.

5 Load the stxBrain dataset

LoadData() may print conversion warnings when loading older SeuratData objects.

seurat_obj <- LoadData("stxBrain", type = "anterior1")
## Validating object structure
## Updating object slots
## Ensuring keys are in the proper structure
## Ensuring keys are in the proper structure
## Ensuring feature names don't have underscores or pipes
## Updating slots in Spatial
## Updating slots in anterior1
## Warning: Not validating Centroids objects
## Updated Centroids object 'centroids' in FOV 'anterior1'
## Updated boundaries in FOV 'anterior1'
## Validating object structure for Assay5 'Spatial'
## Validating object structure for VisiumV2 'anterior1'
## Object representation is consistent with the most current Seurat version

6 Preprocess the Seurat object

The dataset is normalized using SCTransform(), reduced using PCA, and clustered using the standard Seurat workflow. Please see the spatial transcriptomics vignette from Seurat.

seurat_obj <- SCTransform(seurat_obj, assay = "Spatial", verbose = FALSE)

seurat_obj <- RunPCA(seurat_obj, assay = "SCT", verbose = FALSE)

seurat_obj <- FindNeighbors(
  object = seurat_obj,
  reduction = "pca",
  dims = 1:30
)
## Computing nearest neighbor graph
## Computing SNN
seurat_obj <- FindClusters(
  object = seurat_obj,
  verbose = FALSE
)

7 Convert the Seurat object to GraphSpace

The as.GraphSpace() function converts the spatial coordinates and associated metadata from the Seurat object into a GraphSpace object.

gs <- as.GraphSpace(seurat_obj, space = "spatial",scale = "lowres")
## Seurat object converted to GraphSpace:
## ℹ space=spatial, layer=default, features=17668, samples=2696, scale="lowres"
## Node spatial boundaries:
## ℹ x: [76, 493] (cols)
## ℹ y: [138, 541] (rows)

8 Add the tissue image

If available, the tissue image can be extracted from the Seurat object and assigned to the GraphSpace object.

gs_image(gs) <- SeuratObject::GetImage(seurat_obj, mode = "raster")
## Image spatial boundaries:
## ℹ x: [1, 600] (cols)
## ℹ y: [1, 599] (rows)

9 Normalize graph coordinates to image space

The graph coordinates are normalized to the image coordinate system. By default, this attempts to align the graph’s bottom-up coordinates with the image’s top-down matrix layout.

gs <- normalizeGraphSpace(gs)
## Normalizing node coordinates to image space...
## Flipping y-coordinates...

10 Inspect the GraphSpace object

gs
## A GraphSpace-class object for:
## IGRAPH d7bbd08 UN-- 2696 0 -- 
## + attr: x (v/n), y (v/n), name (v/c), nodeLabel (v/c), nodeSize (v/n),
## | cell (v/c), orig.ident (v/x), nCount_Spatial (v/n), nFeature_Spatial
## | (v/n), slice (v/n), region (v/c), nCount_SCT (v/n), nFeature_SCT
## | (v/n), SCT_snn_res.0.8 (v/x), seurat_clusters (v/x), arrowType (e/n)
## + features: 17668 (Xkr4, Sox17, Mrpl15, Lypla1, ...)

11 Save the normalized GraphSpace object

The final object is saved as an .RData file.

save(gs, file = "stxbrain_Normalized_GraphSpace.RData")

12 Session information

sessionInfo()
## R version 4.5.3 (2026-03-11 ucrt)
## Platform: x86_64-w64-mingw32/x64
## Running under: Windows 11 x64 (build 26200)
## 
## Matrix products: default
##   LAPACK version 3.12.1
## 
## locale:
## [1] LC_COLLATE=Portuguese_Brazil.utf8  LC_CTYPE=Portuguese_Brazil.utf8   
## [3] LC_MONETARY=Portuguese_Brazil.utf8 LC_NUMERIC=C                      
## [5] LC_TIME=Portuguese_Brazil.utf8    
## 
## time zone: America/Sao_Paulo
## tzcode source: internal
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] future_1.70.0             igraph_2.3.3             
##  [3] dplyr_1.2.1               patchwork_1.3.2          
##  [5] stxBrain.SeuratData_0.1.2 SeuratData_0.2.2.9002    
##  [7] Seurat_5.5.1              SeuratObject_5.4.0       
##  [9] sp_2.2-1                  PathwaySpace_1.4.1       
## [11] RGraphSpace_1.4.1         ggplot2_4.0.3            
## 
## loaded via a namespace (and not attached):
##   [1] RColorBrewer_1.1-3          rstudioapi_0.19.0          
##   [3] jsonlite_2.0.0              magrittr_2.0.5             
##   [5] spatstat.utils_3.2-3        ggbeeswarm_0.7.3           
##   [7] farver_2.1.2                rmarkdown_2.31             
##   [9] vctrs_0.7.3                 ROCR_1.0-12                
##  [11] DelayedMatrixStats_1.32.0   spatstat.explore_3.8-1     
##  [13] S4Arrays_1.10.1             htmltools_0.5.9            
##  [15] SparseArray_1.10.10         sass_0.4.10                
##  [17] sctransform_0.4.3           parallelly_1.48.0          
##  [19] KernSmooth_2.23-26          bslib_0.11.0               
##  [21] htmlwidgets_1.6.4           ica_1.0-3                  
##  [23] plyr_1.8.9                  plotly_4.12.0              
##  [25] zoo_1.8-15                  cachem_1.1.0               
##  [27] mime_0.13                   lifecycle_1.0.5            
##  [29] pkgconfig_2.0.3             Matrix_1.7-4               
##  [31] R6_2.6.1                    fastmap_1.2.0              
##  [33] MatrixGenerics_1.22.0       fitdistrplus_1.2-6         
##  [35] shiny_1.14.0                digest_0.6.39              
##  [37] colorspace_2.1-2            ggnewscale_0.5.2           
##  [39] S4Vectors_0.48.1            tensor_1.5.1               
##  [41] RSpectra_0.16-2             irlba_2.3.7                
##  [43] GenomicRanges_1.62.1        beachmat_2.26.0            
##  [45] progressr_1.0.0             spatstat.sparse_3.2-0      
##  [47] httr_1.4.8                  polyclip_1.10-7            
##  [49] abind_1.4-8                 compiler_4.5.3             
##  [51] withr_3.0.3                 S7_0.2.2                   
##  [53] fastDummies_1.7.6           MASS_7.3-65                
##  [55] DelayedArray_0.36.1         rappdirs_0.3.4             
##  [57] tools_4.5.3                 vipor_0.4.7                
##  [59] lmtest_0.9-40               otel_0.2.0                 
##  [61] beeswarm_0.4.0              httpuv_1.6.17              
##  [63] future.apply_1.20.2         goftest_1.2-3              
##  [65] glmGamPoi_1.22.0            glue_1.8.1                 
##  [67] nlme_3.1-168                promises_1.5.0             
##  [69] grid_4.5.3                  Rtsne_0.17                 
##  [71] cluster_2.1.8.2             reshape2_1.4.5             
##  [73] generics_0.1.4              gtable_0.3.6               
##  [75] spatstat.data_3.1-9         tidyr_1.3.2                
##  [77] data.table_1.18.4           XVector_0.50.0             
##  [79] tidygraph_1.3.1             BiocGenerics_0.56.0        
##  [81] spatstat.geom_3.8-1         RcppAnnoy_0.0.23           
##  [83] ggrepel_0.9.8               RANN_2.6.2                 
##  [85] pillar_1.11.1               stringr_1.6.0              
##  [87] spam_2.11-4                 RcppHNSW_0.7.0             
##  [89] later_1.4.8                 splines_4.5.3              
##  [91] lattice_0.22-9              survival_3.8-6             
##  [93] deldir_2.0-4                tidyselect_1.2.1           
##  [95] miniUI_0.1.2                pbapply_1.7-4              
##  [97] knitr_1.51                  gridExtra_2.3.1            
##  [99] Seqinfo_1.0.0               IRanges_2.44.0             
## [101] SummarizedExperiment_1.40.0 scattermore_1.2            
## [103] stats4_4.5.3                xfun_0.59                  
## [105] Biobase_2.70.0              matrixStats_1.5.0          
## [107] stringi_1.8.7               lazyeval_0.2.3             
## [109] yaml_2.3.12                 evaluate_1.0.5             
## [111] codetools_0.2-20            tibble_3.3.1               
## [113] cli_3.6.6                   uwot_0.2.4                 
## [115] xtable_1.8-8                reticulate_1.46.0          
## [117] jquerylib_0.1.4             Rcpp_1.1.2                 
## [119] globals_0.19.1              spatstat.random_3.5-0      
## [121] png_0.1-9                   ggrastr_1.0.2              
## [123] spatstat.univar_3.2-0       parallel_4.5.3             
## [125] dotCall64_1.2               sparseMatrixStats_1.22.0   
## [127] listenv_1.0.0               viridisLite_0.4.3          
## [129] scales_1.4.0                ggridges_0.5.7             
## [131] purrr_1.2.2                 crayon_1.5.3               
## [133] rlang_1.2.0                 cowplot_1.2.0

References

Hao, Yuhan, Tim Stuart, Madeline H Kowalski, Saket Choudhary, Paul Hoffman, Austin Hartman, Avi Srivastava, et al. 2023. “Dictionary Learning for Integrative, Multimodal and Scalable Single-Cell Analysis.” Nature Biotechnology. https://doi.org/10.1038/s41587-023-01767-y.
Sysbiolab Team. 2026. RGraphSpace: A Lightweight Interface Between ’Igraph’ and ’Ggplot2’ Graphics. https://CRAN.R-project.org/package=RGraphSpace.