alabaster.spatial 1.7.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")))