Contents

1 Overview

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.

2 Quick start

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     34-55      * | 0.8215020
##     [2]     chrA    65-107      * | 0.8601954
##     [3]     chrA     26-82      * | 0.0387724
##     [4]     chrA    58-135      * | 0.2652218
##     [5]     chrA    89-127      * | 0.8544463
##     ...      ...       ...    ... .       ...
##    [96]     chrA    99-125      * |  0.962629
##    [97]     chrA     72-74      * |  0.711735
##    [98]     chrA    87-177      * |  0.018991
##    [99]     chrA    40-118      * |  0.537430
##   [100]     chrA     43-67      * |  0.212416
##   -------
##   seqinfo: 1 sequence from an unspecified genome

The same can be done for GRangesList and CompressedList subclasses.

2.1 Further comments

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.8215020
## 2   0.8601954
## 3   0.0387724
## 4   0.2652218
## 5   0.8544463
## ...       ...
## 96   0.962629
## 97   0.711735
## 98   0.018991
## 99   0.537430
## 100  0.212416
seqinfo(roundtrip)
## Seqinfo object with 1 sequence from an unspecified genome:
##   seqnames seqlengths isCircular genome
##   chrA           1000         NA   <NA>

Session information

sessionInfo()
## R Under development (unstable) (2024-01-16 r85808)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 22.04.3 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.19-bioc/R/lib/libRblas.so 
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.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.ranges_1.3.3 alabaster.base_1.3.19  GenomicRanges_1.55.2  
## [4] GenomeInfoDb_1.39.5    IRanges_2.37.1         S4Vectors_0.41.3      
## [7] BiocGenerics_0.49.1    BiocStyle_2.31.0      
## 
## loaded via a namespace (and not attached):
##  [1] cli_3.6.2               knitr_1.45              rlang_1.1.3            
##  [4] xfun_0.41               jsonlite_1.8.8          RCurl_1.98-1.14        
##  [7] htmltools_0.5.7         sass_0.4.8              rmarkdown_2.25         
## [10] evaluate_0.23           jquerylib_0.1.4         bitops_1.0-7           
## [13] fastmap_1.1.1           Rhdf5lib_1.25.1         alabaster.schemas_1.3.1
## [16] yaml_2.3.8              lifecycle_1.0.4         bookdown_0.37          
## [19] BiocManager_1.30.22     compiler_4.4.0          Rcpp_1.0.12            
## [22] rhdf5filters_1.15.1     XVector_0.43.1          rhdf5_2.47.2           
## [25] digest_0.6.34           R6_2.5.1                GenomeInfoDbData_1.2.11
## [28] bslib_0.6.1             tools_4.4.0             zlibbioc_1.49.0        
## [31] cachem_1.0.8