alabaster.bumpy 1.0.0
The BumpyMatrix
class provides a representation of complex ragged data structures - see the BumpyMatrix package for more information.
This is used to coerce immune repertoire, spatial transcriptomics and drug response data into a familiar 2D array for easy manipulation.
The alabaster.bumpy package allows users to save a BumpyMatrix
to file within the alabaster framework.
BumpyMatrix
Let’s make a BumpyMatrix
to demonstrate:
library(BumpyMatrix)
library(S4Vectors)
df <- DataFrame(x=runif(100), y=runif(100))
f <- factor(sample(letters[1:20], nrow(df), replace=TRUE), letters[1:20])
mat <- BumpyMatrix(split(df, f), c(5, 4))
Saving it to file involves calling stageObject
:
library(alabaster.bumpy)
tmp <- tempfile()
dir.create(tmp)
meta <- stageObject(mat, tmp, "bumpy")
.writeMetadata(meta, tmp)
## $type
## [1] "local"
##
## $path
## [1] "bumpy/groups.csv.gz"
list.files(file.path(tmp, "bumpy"), recursive=TRUE)
## [1] "concatenated/simple.csv.gz" "concatenated/simple.csv.gz.json"
## [3] "groups.csv.gz" "groups.csv.gz.json"
BumpyMatrix
The loading procedure is even simpler as the metadata of the saved BumpyMatrix
remembers how it was saved.
We can just use alabaster.base::loadObject()
or related functions, and the R interface will automatically do the rest.
loadObject(meta, tmp)
## 5 x 4 BumpyDataFrameMatrix
## rownames: NULL
## colnames: NULL
## preview [1,1]:
## DataFrame with 6 rows and 2 columns
## x y
## <numeric> <numeric>
## 1 0.2926935 0.518175
## 2 0.0923591 0.983292
## 3 0.1254521 0.232736
## 4 0.7932127 0.852598
## 5 0.6853166 0.548240
## 6 0.3877253 0.415254
sessionInfo()
## R version 4.3.0 RC (2023-04-13 r84266)
## Platform: aarch64-apple-darwin20 (64-bit)
## Running under: macOS Monterey 12.6.1
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib; LAPACK version 3.11.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.bumpy_1.0.0 alabaster.base_1.0.0 S4Vectors_0.38.1
## [4] BiocGenerics_0.46.0 BumpyMatrix_1.8.0 BiocStyle_2.28.0
##
## loaded via a namespace (and not attached):
## [1] cli_3.6.1 knitr_1.42 rlang_1.1.0
## [4] xfun_0.38 jsonlite_1.8.4 V8_4.3.0
## [7] htmltools_0.5.5 sass_0.4.5 rmarkdown_2.21
## [10] grid_4.3.0 evaluate_0.20 jquerylib_0.1.4
## [13] fastmap_1.1.1 Rhdf5lib_1.22.0 alabaster.schemas_1.0.1
## [16] yaml_2.3.7 IRanges_2.34.0 bookdown_0.33
## [19] jsonvalidate_1.3.2 BiocManager_1.30.20 compiler_4.3.0
## [22] rhdf5filters_1.12.1 Rcpp_1.0.10 rhdf5_2.44.0
## [25] lattice_0.21-8 digest_0.6.31 R6_2.5.1
## [28] curl_5.0.0 bslib_0.4.2 Matrix_1.5-4
## [31] tools_4.3.0 cachem_1.0.7