Contents

1 Overview

The SpatialExperiment class (from the SpatialExperiment package) provides a representation of spatial transcriptomics data that is compatible with Bioconductor’s SummarizedExperiment ecosystem. The alabaster.spatial package contains methods to save and load SpatialExperiment objects into and out of file. Check out the alabaster.base for more details on the motivation and concepts of the alabaster framework.

2 Quick start

To demonstrate, we’ll use the example dataset provided in the SpatialExperiment package:

library(SpatialExperiment)
example(read10xVisium, echo=FALSE)

# Making the column names unique.
colnames(spe) <- make.unique(colnames(spe))

spe
## class: SpatialExperiment 
## dim: 50 99 
## metadata(0):
## assays(1): counts
## rownames(50): ENSMUSG00000051951 ENSMUSG00000089699 ...
##   ENSMUSG00000005886 ENSMUSG00000101476
## rowData names(1): symbol
## colnames(99): AAACAACGAATAGTTC-1 AAACAAGTATCTCCCA-1 ...
##   AAAGTCGACCCTCAGT-1.1 AAAGTGCCATCAATTA-1.1
## colData names(4): in_tissue array_row array_col sample_id
## reducedDimNames(0):
## mainExpName: NULL
## altExpNames(0):
## spatialCoords names(2) : pxl_col_in_fullres pxl_row_in_fullres
## imgData names(4): sample_id image_id data scaleFactor

We call the usual saveObject() function to save its contents to file:

library(alabaster.spatial)
tmp <- tempfile()
saveObject(spe, tmp)
list.files(tmp, recursive=TRUE)
##  [1] "OBJECT"                       "assays/0/OBJECT"             
##  [3] "assays/0/matrix.h5"           "assays/names.json"           
##  [5] "column_data/OBJECT"           "column_data/basic_columns.h5"
##  [7] "coordinates/OBJECT"           "coordinates/array.h5"        
##  [9] "images/0.png"                 "images/1.png"                
## [11] "images/mapping.h5"            "row_data/OBJECT"             
## [13] "row_data/basic_columns.h5"

This goes through the usual saving process for SingleCellExperiments, with an additional saving step for the spatial data (see the coordinates/ and images/ subdirectories). We can then load it back in using the readObject() function:

roundtrip <- readObject(tmp)
plot(imgRaster(getImg(roundtrip, "section1")))

More details on the metadata and on-disk layout are provided in the schema.

Session info

sessionInfo()
## R Under development (unstable) (2023-11-11 r85510)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 22.04.3 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.19-bioc/R/lib/libRblas.so 
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_GB              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/New_York
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats4    stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] alabaster.spatial_1.3.1     alabaster.base_1.3.14      
##  [3] SpatialExperiment_1.13.0    SingleCellExperiment_1.25.0
##  [5] SummarizedExperiment_1.33.1 Biobase_2.63.0             
##  [7] GenomicRanges_1.55.1        GenomeInfoDb_1.39.5        
##  [9] IRanges_2.37.0              S4Vectors_0.41.3           
## [11] BiocGenerics_0.49.1         MatrixGenerics_1.15.0      
## [13] matrixStats_1.2.0           BiocStyle_2.31.0           
## 
## loaded via a namespace (and not attached):
##  [1] rjson_0.2.21              xfun_0.41                
##  [3] bslib_0.6.1               rhdf5_2.47.1             
##  [5] lattice_0.22-5            rhdf5filters_1.15.1      
##  [7] tools_4.4.0               bitops_1.0-7             
##  [9] parallel_4.4.0            highr_0.10               
## [11] R.oo_1.25.0               Matrix_1.6-4             
## [13] sparseMatrixStats_1.15.0  dqrng_0.3.2              
## [15] lifecycle_1.0.4           GenomeInfoDbData_1.2.11  
## [17] compiler_4.4.0            statmod_1.5.0            
## [19] alabaster.se_1.3.3        codetools_0.2-19         
## [21] htmltools_0.5.7           sass_0.4.8               
## [23] alabaster.matrix_1.3.5    RCurl_1.98-1.13          
## [25] yaml_2.3.8                crayon_1.5.2             
## [27] jquerylib_0.1.4           R.utils_2.12.3           
## [29] BiocParallel_1.37.0       DelayedArray_0.29.0      
## [31] cachem_1.0.8              limma_3.59.1             
## [33] magick_2.8.2              abind_1.4-5              
## [35] locfit_1.5-9.8            digest_0.6.33            
## [37] bookdown_0.37             fastmap_1.1.1            
## [39] grid_4.4.0                cli_3.6.2                
## [41] SparseArray_1.3.2         magrittr_2.0.3           
## [43] S4Arrays_1.3.1            edgeR_4.1.6              
## [45] DelayedMatrixStats_1.25.1 rmarkdown_2.25           
## [47] XVector_0.43.0            DropletUtils_1.23.0      
## [49] R.methodsS3_1.8.2         beachmat_2.19.0          
## [51] alabaster.sce_1.3.3       HDF5Array_1.31.1         
## [53] evaluate_0.23             knitr_1.45               
## [55] rlang_1.1.2               Rcpp_1.0.11              
## [57] scuttle_1.13.0            BiocManager_1.30.22      
## [59] alabaster.ranges_1.3.2    alabaster.schemas_1.3.1  
## [61] jsonlite_1.8.8            R6_2.5.1                 
## [63] Rhdf5lib_1.25.1           zlibbioc_1.49.0