alabaster.spatial 1.6.1
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.
To demonstrate, we’ll use the example dataset provided in the SpatialExperiment package:
library(SpatialExperiment)
# Copying the example from ?read10xVisium.
dir <- system.file("extdata", "10xVisium", package = "SpatialExperiment")
sample_ids <- c("section1", "section2")
samples <- file.path(dir, sample_ids, "outs")
spe <- read10xVisium(
samples,
sample_ids,
type = "sparse",
data = "raw",
images = "lowres",
load = FALSE
)
colnames(spe) <- make.unique(colnames(spe)) # Making the column names unique.
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 SingleCellExperiment
s, 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.
sessionInfo()
## R version 4.4.1 (2024-06-14)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.1 LTS
##
## Matrix products: default
## BLAS: /media/volume/teran2_disk/biocbuild/bbs-3.20-bioc/R/lib/libRblas.so
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.12.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.6.1 alabaster.base_1.6.1
## [3] SpatialExperiment_1.16.0 SingleCellExperiment_1.28.1
## [5] SummarizedExperiment_1.36.0 Biobase_2.66.0
## [7] GenomicRanges_1.58.0 GenomeInfoDb_1.42.0
## [9] IRanges_2.40.0 S4Vectors_0.44.0
## [11] BiocGenerics_0.52.0 MatrixGenerics_1.18.0
## [13] matrixStats_1.4.1 BiocStyle_2.34.0
##
## loaded via a namespace (and not attached):
## [1] rjson_0.2.23 xfun_0.49
## [3] bslib_0.8.0 rhdf5_2.50.0
## [5] lattice_0.22-6 rhdf5filters_1.18.0
## [7] tools_4.4.1 parallel_4.4.1
## [9] R.oo_1.27.0 Matrix_1.7-1
## [11] sparseMatrixStats_1.18.0 dqrng_0.4.1
## [13] lifecycle_1.0.4 GenomeInfoDbData_1.2.13
## [15] compiler_4.4.1 tinytex_0.54
## [17] statmod_1.5.0 alabaster.se_1.6.0
## [19] codetools_0.2-20 htmltools_0.5.8.1
## [21] sass_0.4.9 alabaster.matrix_1.6.0
## [23] yaml_2.3.10 crayon_1.5.3
## [25] jquerylib_0.1.4 R.utils_2.12.3
## [27] BiocParallel_1.40.0 DelayedArray_0.32.0
## [29] cachem_1.1.0 limma_3.62.1
## [31] magick_2.8.5 abind_1.4-8
## [33] locfit_1.5-9.10 digest_0.6.37
## [35] bookdown_0.41 fastmap_1.2.0
## [37] grid_4.4.1 cli_3.6.3
## [39] SparseArray_1.6.0 magrittr_2.0.3
## [41] S4Arrays_1.6.0 edgeR_4.4.0
## [43] DelayedMatrixStats_1.28.0 UCSC.utils_1.2.0
## [45] rmarkdown_2.29 XVector_0.46.0
## [47] httr_1.4.7 DropletUtils_1.26.0
## [49] R.methodsS3_1.8.2 beachmat_2.22.0
## [51] alabaster.sce_1.6.0 HDF5Array_1.34.0
## [53] evaluate_1.0.1 knitr_1.49
## [55] rlang_1.1.4 Rcpp_1.0.13-1
## [57] scuttle_1.16.0 BiocManager_1.30.25
## [59] alabaster.ranges_1.6.0 alabaster.schemas_1.6.0
## [61] jsonlite_1.8.9 R6_2.5.1
## [63] Rhdf5lib_1.28.0 zlibbioc_1.52.0