SingleCellExperiment
s to artifacts and back againalabaster.sce 1.6.0
The alabaster.sce package implements methods to save SingleCellExperiment
objects to file artifacts and load them back into R.
Check out the alabaster.base for more details on the motivation and concepts of the alabaster framework.
Given a SingleCellExperiment
, we can use saveObject()
to save it inside a staging directory:
library(SingleCellExperiment)
mat <- matrix(rpois(10000, 10), ncol=10)
colnames(mat) <- letters[1:10]
rownames(mat) <- sprintf("GENE_%i", seq_len(nrow(mat)))
sce <- SingleCellExperiment(list(counts=mat))
sce$stuff <- LETTERS[1:10]
sce$blah <- runif(10)
reducedDims(sce) <- list(
PCA=matrix(rnorm(ncol(sce)*10), ncol=10),
TSNE=matrix(rnorm(ncol(sce)*2), ncol=2)
)
altExps(sce) <- list(spikes=SummarizedExperiment(list(counts=mat[1:2,])))
sce
## class: SingleCellExperiment
## dim: 1000 10
## metadata(0):
## assays(1): counts
## rownames(1000): GENE_1 GENE_2 ... GENE_999 GENE_1000
## rowData names(0):
## colnames(10): a b ... i j
## colData names(2): stuff blah
## reducedDimNames(2): PCA TSNE
## mainExpName: NULL
## altExpNames(1): spikes
library(alabaster.sce)
tmp <- tempfile()
saveObject(sce, tmp)
list.files(tmp, recursive=TRUE)
## [1] "OBJECT"
## [2] "alternative_experiments/0/OBJECT"
## [3] "alternative_experiments/0/assays/0/OBJECT"
## [4] "alternative_experiments/0/assays/0/array.h5"
## [5] "alternative_experiments/0/assays/names.json"
## [6] "alternative_experiments/0/column_data/OBJECT"
## [7] "alternative_experiments/0/column_data/basic_columns.h5"
## [8] "alternative_experiments/0/row_data/OBJECT"
## [9] "alternative_experiments/0/row_data/basic_columns.h5"
## [10] "alternative_experiments/names.json"
## [11] "assays/0/OBJECT"
## [12] "assays/0/array.h5"
## [13] "assays/names.json"
## [14] "column_data/OBJECT"
## [15] "column_data/basic_columns.h5"
## [16] "reduced_dimensions/0/OBJECT"
## [17] "reduced_dimensions/0/array.h5"
## [18] "reduced_dimensions/1/OBJECT"
## [19] "reduced_dimensions/1/array.h5"
## [20] "reduced_dimensions/names.json"
## [21] "row_data/OBJECT"
## [22] "row_data/basic_columns.h5"
We can then load it back into the session with loadObject()
.
roundtrip <- readObject(tmp)
class(roundtrip)
## [1] "SingleCellExperiment"
## attr(,"package")
## [1] "SingleCellExperiment"
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: /home/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.sce_1.6.0 alabaster.base_1.6.0
## [3] SingleCellExperiment_1.28.0 SummarizedExperiment_1.36.0
## [5] Biobase_2.66.0 GenomicRanges_1.58.0
## [7] GenomeInfoDb_1.42.0 IRanges_2.40.0
## [9] S4Vectors_0.44.0 BiocGenerics_0.52.0
## [11] MatrixGenerics_1.18.0 matrixStats_1.4.1
## [13] BiocStyle_2.34.0
##
## loaded via a namespace (and not attached):
## [1] sass_0.4.9 SparseArray_1.6.0 lattice_0.22-6
## [4] alabaster.se_1.6.0 digest_0.6.37 evaluate_1.0.1
## [7] grid_4.4.1 bookdown_0.41 fastmap_1.2.0
## [10] jsonlite_1.8.9 Matrix_1.7-1 alabaster.schemas_1.6.0
## [13] BiocManager_1.30.25 httr_1.4.7 UCSC.utils_1.2.0
## [16] HDF5Array_1.34.0 jquerylib_0.1.4 abind_1.4-8
## [19] cli_3.6.3 rlang_1.1.4 crayon_1.5.3
## [22] XVector_0.46.0 cachem_1.1.0 DelayedArray_0.32.0
## [25] yaml_2.3.10 S4Arrays_1.6.0 tools_4.4.1
## [28] Rhdf5lib_1.28.0 GenomeInfoDbData_1.2.13 alabaster.ranges_1.6.0
## [31] alabaster.matrix_1.6.0 R6_2.5.1 lifecycle_1.0.4
## [34] rhdf5_2.50.0 zlibbioc_1.52.0 bslib_0.8.0
## [37] Rcpp_1.0.13 xfun_0.48 knitr_1.48
## [40] rhdf5filters_1.18.0 htmltools_0.5.8.1 rmarkdown_2.28
## [43] compiler_4.4.1