alabaster.ranges 1.9.1
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().
roundtrip <- readObject(tmp)
roundtrip
## GRanges object with 100 ranges and 1 metadata column:
## seqnames ranges strand | score
## <Rle> <IRanges> <Rle> | <numeric>
## [1] chrA 89-101 * | 0.4440570
## [2] chrA 68-100 * | 0.0376108
## [3] chrA 35-129 * | 0.8993773
## [4] chrA 87-186 * | 0.9557704
## [5] chrA 8-53 * | 0.9285340
## ... ... ... ... . ...
## [96] chrA 94-164 * | 0.464552
## [97] chrA 27-92 * | 0.407128
## [98] chrA 54-144 * | 0.985039
## [99] chrA 73-106 * | 0.268780
## [100] chrA 23-78 * | 0.551898
## -------
## seqinfo: 1 sequence from an unspecified genome
The same can be done for GRangesList and CompressedList subclasses.
Metadata is preserved during this round-trip:
metadata(roundtrip)
## $genome
## [1] "Aaron"
mcols(roundtrip)
## DataFrame with 100 rows and 1 column
## score
## <numeric>
## 1 0.4440570
## 2 0.0376108
## 3 0.8993773
## 4 0.9557704
## 5 0.9285340
## ... ...
## 96 0.464552
## 97 0.407128
## 98 0.985039
## 99 0.268780
## 100 0.551898
seqinfo(roundtrip)
## Seqinfo object with 1 sequence from an unspecified genome:
## seqnames seqlengths isCircular genome
## chrA 1000 NA <NA>
sessionInfo()
## R version 4.5.1 (2025-06-13 ucrt)
## Platform: x86_64-w64-mingw32/x64
## Running under: Windows Server 2022 x64 (build 20348)
##
## Matrix products: default
## LAPACK version 3.12.1
##
## locale:
## [1] LC_COLLATE=C
## [2] LC_CTYPE=English_United States.utf8
## [3] LC_MONETARY=English_United States.utf8
## [4] LC_NUMERIC=C
## [5] LC_TIME=English_United States.utf8
##
## time zone: America/New_York
## tzcode source: internal
##
## attached base packages:
## [1] stats4 stats graphics grDevices utils datasets methods
## [8] base
##
## other attached packages:
## [1] alabaster.ranges_1.9.1 alabaster.base_1.9.4 GenomicRanges_1.61.1
## [4] Seqinfo_0.99.2 IRanges_2.43.0 S4Vectors_0.47.0
## [7] BiocGenerics_0.55.0 generics_0.1.4 BiocStyle_2.37.0
##
## loaded via a namespace (and not attached):
## [1] cli_3.6.5 knitr_1.50 rlang_1.1.6
## [4] xfun_0.52 jsonlite_2.0.0 htmltools_0.5.8.1
## [7] sass_0.4.10 rmarkdown_2.29 evaluate_1.0.4
## [10] jquerylib_0.1.4 fastmap_1.2.0 Rhdf5lib_1.31.0
## [13] alabaster.schemas_1.9.0 yaml_2.3.10 lifecycle_1.0.4
## [16] bookdown_0.43 BiocManager_1.30.26 compiler_4.5.1
## [19] Rcpp_1.1.0 rhdf5filters_1.21.0 XVector_0.49.0
## [22] rhdf5_2.53.3 digest_0.6.37 R6_2.6.1
## [25] bslib_0.9.0 tools_4.5.1 cachem_1.1.0