alabaster.ranges 1.5.2
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] "other_annotations/OBJECT"
## [3] "other_annotations/list_contents.json.gz"
## [4] "range_annotations/OBJECT"
## [5] "range_annotations/basic_columns.h5"
## [6] "ranges.h5"
## [7] "sequence_information/OBJECT"
## [8] "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 78-132 * | 0.2831892
## [2] chrA 20-73 * | 0.2352008
## [3] chrA 9-72 * | 0.4918707
## [4] chrA 85-163 * | 0.0716023
## [5] chrA 15-74 * | 0.0185077
## ... ... ... ... . ...
## [96] chrA 6-88 * | 0.856192
## [97] chrA 22-64 * | 0.485418
## [98] chrA 27-111 * | 0.540683
## [99] chrA 25-101 * | 0.929933
## [100] chrA 14-70 * | 0.996278
## -------
## 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.2831892
## 2 0.2352008
## 3 0.4918707
## 4 0.0716023
## 5 0.0185077
## ... ...
## 96 0.856192
## 97 0.485418
## 98 0.540683
## 99 0.929933
## 100 0.996278
seqinfo(roundtrip)
## Seqinfo object with 1 sequence from an unspecified genome:
## seqnames seqlengths isCircular genome
## chrA 1000 NA <NA>
sessionInfo()
## R version 4.4.1 RC (2024-06-06 r86719)
## Platform: x86_64-apple-darwin20
## Running under: macOS Monterey 12.7.1
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.4-x86_64/Resources/lib/libRlapack.dylib; LAPACK version 3.12.0
##
## locale:
## [1] C/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## 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.5.2 alabaster.base_1.5.3 GenomicRanges_1.57.1
## [4] GenomeInfoDb_1.41.1 IRanges_2.39.0 S4Vectors_0.43.0
## [7] BiocGenerics_0.51.0 BiocStyle_2.33.1
##
## loaded via a namespace (and not attached):
## [1] httr_1.4.7 cli_3.6.3 knitr_1.47
## [4] rlang_1.1.4 xfun_0.45 UCSC.utils_1.1.0
## [7] jsonlite_1.8.8 htmltools_0.5.8.1 sass_0.4.9
## [10] rmarkdown_2.27 evaluate_0.24.0 jquerylib_0.1.4
## [13] fastmap_1.2.0 Rhdf5lib_1.27.0 alabaster.schemas_1.5.0
## [16] yaml_2.3.8 lifecycle_1.0.4 bookdown_0.39
## [19] BiocManager_1.30.23 compiler_4.4.1 Rcpp_1.0.12
## [22] rhdf5filters_1.17.0 XVector_0.45.0 rhdf5_2.49.0
## [25] digest_0.6.35 R6_2.5.1 GenomeInfoDbData_1.2.12
## [28] bslib_0.7.0 tools_4.4.1 zlibbioc_1.51.1
## [31] cachem_1.1.0