The alabaster.ranges
package implements methods to save genomic ranges (i.e.,
GRanges and GRangesList objects) to file
artifacts and load them back into R. It also supports various
CompressedList subclasses, including the somewhat useful
CompressedSplitDataFrameList. Check out alabaster.base
for more details on the motivation and concepts of the
alabaster framework.
Given some genomic ranges, we can use saveObject() to
save it inside a staging directory:
library(GenomicRanges)
gr <- GRanges("chrA", IRanges(sample(100), width=sample(100)))
mcols(gr)$score <- runif(length(gr))
metadata(gr)$genome <- "Aaron"
seqlengths(gr) <- c(chrA=1000)
library(alabaster.ranges)
tmp <- tempfile()
saveObject(gr, tmp)
list.files(tmp, recursive=TRUE)## [1] "OBJECT"
## [2] "_environment.json"
## [3] "other_annotations/OBJECT"
## [4] "other_annotations/list_contents.json.gz"
## [5] "range_annotations/OBJECT"
## [6] "range_annotations/basic_columns.h5"
## [7] "ranges.h5"
## [8] "sequence_information/OBJECT"
## [9] "sequence_information/info.h5"
We can then easily load it back in with
readObject().
## GRanges object with 100 ranges and 1 metadata column:
## seqnames ranges strand | score
## <Rle> <IRanges> <Rle> | <numeric>
## [1] chrA 63-89 * | 0.9974749
## [2] chrA 58-87 * | 0.0427849
## [3] chrA 42-54 * | 0.4194040
## [4] chrA 82-130 * | 0.9057034
## [5] chrA 94-155 * | 0.6651396
## ... ... ... ... . ...
## [96] chrA 90-103 * | 0.925593
## [97] chrA 35-134 * | 0.523987
## [98] chrA 29-93 * | 0.716438
## [99] chrA 43-82 * | 0.671060
## [100] chrA 10-24 * | 0.951359
## -------
## seqinfo: 1 sequence from an unspecified genome
The same can be done for GRangesList and
CompressedList subclasses.
Metadata is preserved during this round-trip:
## $genome
## [1] "Aaron"
## DataFrame with 100 rows and 1 column
## score
## <numeric>
## 1 0.9974749
## 2 0.0427849
## 3 0.4194040
## 4 0.9057034
## 5 0.6651396
## ... ...
## 96 0.925593
## 97 0.523987
## 98 0.716438
## 99 0.671060
## 100 0.951359
## Seqinfo object with 1 sequence from an unspecified genome:
## seqnames seqlengths isCircular genome
## chrA 1000 NA <NA>
## R version 4.5.2 (2025-10-31)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.3 LTS
##
## Matrix products: default
## BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
## LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so; LAPACK version 3.12.0
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_US.UTF-8 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: Etc/UTC
## tzcode source: system (glibc)
##
## attached base packages:
## [1] stats4 stats graphics grDevices utils datasets methods
## [8] base
##
## other attached packages:
## [1] alabaster.ranges_1.10.0 alabaster.base_1.10.0 GenomicRanges_1.62.0
## [4] Seqinfo_1.0.0 IRanges_2.44.0 S4Vectors_0.48.0
## [7] BiocGenerics_0.56.0 generics_0.1.4 BiocStyle_2.38.0
##
## loaded via a namespace (and not attached):
## [1] cli_3.6.5 knitr_1.50 rlang_1.1.6
## [4] xfun_0.54 jsonlite_2.0.0 buildtools_1.0.0
## [7] htmltools_0.5.8.1 maketools_1.3.2 sys_3.4.3
## [10] sass_0.4.10 rmarkdown_2.30 evaluate_1.0.5
## [13] jquerylib_0.1.4 fastmap_1.2.0 Rhdf5lib_1.32.0
## [16] alabaster.schemas_1.10.0 yaml_2.3.10 lifecycle_1.0.4
## [19] BiocManager_1.30.27 compiler_4.5.2 Rcpp_1.1.0
## [22] rhdf5filters_1.22.0 rhdf5_2.54.0 digest_0.6.38
## [25] R6_2.6.1 bslib_0.9.0 tools_4.5.2
## [28] cachem_1.1.0