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 stageObject() function to save its contents to file:

library(alabaster.spatial)

tmp <- tempfile()
dir.create(tmp, showWarnings=FALSE)
meta <- stageObject(spe, dir=tmp, "spe", stage.only=TRUE)
.writeMetadata(meta, tmp)
## $type
## [1] "local"
## 
## $path
## [1] "spe/experiment.json"
list.files(tmp, recursive=TRUE)
##  [1] "spe/assay-1/matrix.h5"               "spe/assay-1/matrix.h5.json"         
##  [3] "spe/coldata/simple.csv.gz"           "spe/coldata/simple.csv.gz.json"     
##  [5] "spe/experiment.json"                 "spe/rowdata/simple.csv.gz"          
##  [7] "spe/rowdata/simple.csv.gz.json"      "spe/spatial/coords/array.h5"        
##  [9] "spe/spatial/coords/array.h5.json"    "spe/spatial/images/image-1.png"     
## [11] "spe/spatial/images/image-1.png.json" "spe/spatial/images/image-2.png"     
## [13] "spe/spatial/images/image-2.png.json"

This goes through the usual saving process for SingleCellExperiments, with an additional saving step for the image data (see the spatial/ subdirectory). We can then load it back in using the loadObject() function:

remeta <- acquireMetadata(tmp, "spe/experiment.json")
roundtrip <- loadObject(remeta, tmp)
spe2
## 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 AAAGTGCCATCAATTA-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
plot(imgRaster(getImg(spe2, "section1")))