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 the alabaster.base for more details on the motivation and concepts of the alabaster framework.

2 Quick start

Given some genomic ranges, we can use stageObject() 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()
dir.create(tmp)
meta <- stageObject(gr, tmp, "gr")
.writeMetadata(meta, tmp)
## $type
## [1] "local"
## 
## $path
## [1] "gr/ranges.csv.gz"
list.files(tmp, recursive=TRUE)
## [1] "gr/mcols/simple.csv.gz"        "gr/mcols/simple.csv.gz.json"  
## [3] "gr/other/list.json.gz"         "gr/other/list.json.gz.json"   
## [5] "gr/ranges.csv.gz"              "gr/ranges.csv.gz.json"        
## [7] "gr/seqinfo/simple.csv.gz"      "gr/seqinfo/simple.csv.gz.json"

We can then easily load it back in with loadObject().

meta <- acquireMetadata(tmp, "gr/ranges.csv.gz")
roundtrip <- loadObject(meta, tmp)
class(roundtrip)
## [1] "GRanges"
## attr(,"package")
## [1] "GenomicRanges"

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.477742
## 2    0.441576
## 3    0.906051
## 4    0.101847
## 5    0.454376
## ...       ...
## 96   0.344774
## 97   0.449083
## 98   0.918393
## 99   0.502446
## 100  0.951081
seqinfo(roundtrip)
## Seqinfo object with 1 sequence from an unspecified genome:
##   seqnames seqlengths isCircular genome
##   chrA           1000         NA   <NA>

Session information

sessionInfo()
## R version 4.3.1 (2023-06-16)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 22.04.3 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.18-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.2.0 alabaster.base_1.2.0   GenomicRanges_1.54.0  
## [4] GenomeInfoDb_1.38.0    IRanges_2.36.0         S4Vectors_0.40.0      
## [7] BiocGenerics_0.48.0    BiocStyle_2.30.0      
## 
## loaded via a namespace (and not attached):
##  [1] cli_3.6.1               knitr_1.44              rlang_1.1.1            
##  [4] xfun_0.40               jsonlite_1.8.7          RCurl_1.98-1.12        
##  [7] V8_4.4.0                htmltools_0.5.6.1       sass_0.4.7             
## [10] rmarkdown_2.25          evaluate_0.22           jquerylib_0.1.4        
## [13] bitops_1.0-7            fastmap_1.1.1           Rhdf5lib_1.24.0        
## [16] alabaster.schemas_1.2.0 yaml_2.3.7              bookdown_0.36          
## [19] jsonvalidate_1.3.2      BiocManager_1.30.22     compiler_4.3.1         
## [22] rhdf5filters_1.14.0     Rcpp_1.0.11             XVector_0.42.0         
## [25] rhdf5_2.46.0            digest_0.6.33           R6_2.5.1               
## [28] curl_5.1.0              GenomeInfoDbData_1.2.11 bslib_0.5.1            
## [31] tools_4.3.1             zlibbioc_1.48.0         cachem_1.0.8