Contents

1TheLoomExperimentclass

1.1Definition

TheLoomExperimentfamily of classes inherits from the main classLoomExperimentas well as the Experiment class that they are named after. For example, theSingleCellLoomExperimentclass inherits from bothLoomExperimentandSingleCellExperiment.

The purpose of theLoomExperimentclass is to act as an intermediary between Bioconductor’s Experiment classes and the Linnarson Lab’s Loom File Format (http://linnarssonlab.org/loompy/index.html). The Loom File Format uses HDF5 to store Experiment data.

TheLoomExperimentfamily of classes contain the following slots.

  • colGraphs
  • rowGraphs

Both of these slots areLoomGraphs对象s that describe thecol_graphandrow_graphattributes as specified by the Loom File Format.

1.2Create instances of LoomExperiment

There are several ways to create instances of aLoomExperimentclass of object. One can plug an existing SummarizedExperiment type class into the appropriate constructor:

library(LoomExperiment) counts <- matrix(rpois(100, lambda = 10), ncol=10, nrow=10) sce <- SingleCellExperiment(assays = list(counts = counts)) scle <- SingleCellLoomExperiment(sce) ## OR scle <- LoomExperiment(sce)

One can also simply plug the arguments into the appropriate constructor, since allLoomExperimentconstructors call the applicable class’s constructor

scle <- SingleCellLoomExperiment(assays = list(counts = counts))

Also, it is also possible to create aLoomExperimentextending class via coercion:

scle <- as(sce, "SingleCellLoomExperiment") scle
## class: SingleCellLoomExperiment ## dim: 10 10 ## metadata(0): ## assays(1): counts ## rownames: NULL ## rowData names(0): ## colnames: NULL ## colData names(0): ## reducedDimNames(0): ## mainExpName: NULL ## altExpNames(0): ## rowGraphs(0): NULL ## colGraphs(0): NULL

Finally, one can create aLoomExperiment对象from importing a Loom File.

1.3Setting up a simple example

We will use the followingSingleCellLoomExperimentfor the remainder of the vignette.

l1_file <- system.file("extdata", "L1_DRG_20_example.loom", package = "LoomExperiment") scle <- import(l1_file, type="SingleCellLoomExperiment") scle
## class: SingleCellLoomExperiment ## dim: 20 20 ## metadata(4): CreatedWith LOOM_SPEC_VERSION LoomExperiment-class ## MatrixName ## assays(1): matrix ## rownames: NULL ## rowData names(7): Accession Gene ... X_Total X_Valid ## colnames: NULL ## colData names(103): Age AnalysisPool ... cDNA_Lib_Ok ngperul_cDNA ## reducedDimNames(0): ## mainExpName: NULL ## altExpNames(0): ## rowGraphs(0): NULL ## colGraphs(2): KNN MKNN

All the following methods apply to allLoomExperimentclasses.

2TheLoomGraphclass

ThecolGraphsandrowGraphsslots of LoomExperiments correspond to thecol_graphsandrow_graphsfields in the Loom File format. Both of these slots requireLoomGraphs对象s.

ALoomGraphclass extends theSelfHitsclass from theS4Vectorspackage with the requirements that aLoomGraph对象must:

The columnstoandfromcorrespond to eitherroworcolindices in theLoomExperiment对象whilewis an optional column that specifies the weight.

LoomGraph可以构建在两个方面:

a <- c(1, 2, 3) b <- c(3, 2, 1) w <- c(100, 10, 1) df <- DataFrame(a, b, w) lg <- as(df, "LoomGraph") ## OR lg <- LoomGraph(a, b, weight = w) lg
## LoomGraph object with 3 hits and 1 metadata column: ## from to | w ##   |  ## [1] 1 3 | 100 ## [2] 2 2 | 10 ## [3] 3 1 | 1 ## ------- ## nnode: 3

LoomGraph对象s can be subset by the ‘row’/‘col’ indices.

lg[c(1, 2)]
## LoomGraph object with 2 hits and 1 metadata column: ## from to | w ##   |  ## [1] 1 3 | 100 ## [2] 2 2 | 10 ## ------- ## nnode: 3
lg[-c(2)]
## LoomGraph object with 2 hits and 1 metadata column: ## from to | w ##   |  ## [1] 1 3 | 100 ## [2] 3 1 | 1 ## ------- ## nnode: 3

3TheLoomGraphsclass

ALoomGraphs对象extends theS4Vectors:SimpleList对象. It contains multipleLoomGraph对象s with its only requirement being that it must containLoomGraph对象s.

It can be created simply by usingLoomGraph对象s in theLoomGraphsconstructor

lgs < - LoomGraphs (lg、lg)的名字(lgs) < - c(“lg1”、“lg2') lgs
## LoomGraphs of length 2 ## names(2): lg1 lg2

4Available methods for theLoomExperiment

TheLoomGraphsassigned to thesecolGraphsandrowGraphsslots can be obtained by their eponymous methods:

colGraphs(scle)
## LoomGraphs of length 2 ## names(2): KNN MKNN
rowGraphs(scle)
## LoomGraphs of length 0

The same symbols can also be used to replace the respectiveLoomGraphs

colGraphs(scle) <- lgs rowGraphs(scle) <- lgs colGraphs(scle)
## LoomGraphs of length 2 ## names(2): lg1 lg2
rowGraphs(scle)
## LoomGraphs of length 2 ## names(2): lg1 lg2
colGraphs(scle)[[1]]
## LoomGraph object with 3 hits and 1 metadata column: ## from to | w ##   |  ## [1] 1 3 | 100 ## [2] 2 2 | 10 ## [3] 3 1 | 1 ## ------- ## nnode: 20
rowGraphs(scle)[[1]]
## LoomGraph object with 3 hits and 1 metadata column: ## from to | w ##   |  ## [1] 1 3 | 100 ## [2] 2 2 | 10 ## [3] 3 1 | 1 ## ------- ## nnode: 20

LoomExperiment对象s can be subsetting in such a way that theassays,colGraphs, androwGraphswill all be subsetted.assayswill will be subsetted as anymatrixwould. Theielement in the subsetting operation will subset therowGraphsslot and thejelement in the subsetting operation will subset thecolGraphsslot, as we’ve seen from the subsetting method fromLoomGraphs.

scle2 <- scle[c(1, 3), 1:2] colGraphs(scle2)[[1]]
## LoomGraph object with 1 hit and 1 metadata column: ## from to | w ##   |  ## [1] 2 2 | 10 ## ------- ## nnode: 2
rowGraphs(scle2)[[1]]
## LoomGraph object with 2 hits and 1 metadata column: ## from to | w ##   |  ## [1] 1 2 | 100 ## [2] 2 1 | 1 ## ------- ## nnode: 2
scle3 <- rbind(scle, scle) scle3
## class: SingleCellLoomExperiment ## dim: 40 20 ## metadata(8): CreatedWith LOOM_SPEC_VERSION ... LoomExperiment-class ## MatrixName ## assays(1): matrix ## rownames: NULL ## rowData names(7): Accession Gene ... X_Total X_Valid ## colnames: NULL ## colData names(103): Age AnalysisPool ... cDNA_Lib_Ok ngperul_cDNA ## reducedDimNames(0): ## mainExpName: NULL ## altExpNames(0): ## rowGraphs(2): lg1 lg2 ## colGraphs(4): lg1 lg2 lg1 lg2
colGraphs(scle3)
## LoomGraphs of length 4 ## names(4): lg1 lg2 lg1 lg2
rowGraphs(scle3)
## LoomGraphs of length 2 ## names(2): lg1 lg2
colGraphs(scle3)[[1]]
## LoomGraph object with 3 hits and 1 metadata column: ## from to | w ##   |  ## [1] 1 3 | 100 ## [2] 2 2 | 10 ## [3] 3 1 | 1 ## ------- ## nnode: 20
rowGraphs(scle3)[[1]]
## LoomGraph object with 6 hits and 1 metadata column: ## from to | w ##   |  ## [1] 1 3 | 100 ## [2] 2 2 | 10 ## [3] 3 1 | 1 ## [4] 21 23 | 100 ## [5] 22 22 | 10 ## [6] 23 21 | 1 ## ------- ## nnode: 40

Finally, theLoomExperiment对象can be exported.

temp <- tempfile(fileext='.loom') export(scle2, temp)

5Session Info

sessionInfo()
## R version 4.2.0 RC (2022-04-21 r82226) ## Platform: x86_64-pc-linux-gnu (64-bit) ## Running under: Ubuntu 20.04.4 LTS ## ## Matrix products: default ## BLAS: /home/biocbuild/bbs-3.16-bioc/R/lib/libRblas.so ## LAPACK: /home/biocbuild/bbs-3.16-bioc/R/lib/libRlapack.so ## ## 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 ## ## attached base packages: ## [1] stats4 stats graphics grDevices utils datasets methods ## [8] base ## ## other attached packages: ## [1] LoomExperiment_1.15.0 BiocIO_1.7.0 ## [3] rhdf5_2.41.0 SingleCellExperiment_1.19.0 ## [5] SummarizedExperiment_1.27.0 Biobase_2.57.0 ## [7] GenomicRanges_1.49.0 GenomeInfoDb_1.33.0 ## [9] IRanges_2.31.0 MatrixGenerics_1.9.0 ## [11] matrixStats_0.62.0 S4Vectors_0.35.0 ## [13] BiocGenerics_0.43.0 BiocStyle_2.25.0 ## ## loaded via a namespace (and not attached): ## [1] bslib_0.3.1 compiler_4.2.0 BiocManager_1.30.17 ## [4] jquerylib_0.1.4 XVector_0.37.0 rhdf5filters_1.9.0 ## [7] bitops_1.0-7 tools_4.2.0 zlibbioc_1.43.0 ## [10] digest_0.6.29 jsonlite_1.8.0 evaluate_0.15 ## [13] lattice_0.20-45 rlang_1.0.2 Matrix_1.4-1 ## [16] DelayedArray_0.23.0 cli_3.3.0 yaml_2.3.5 ## [19] xfun_0.30 fastmap_1.1.0 GenomeInfoDbData_1.2.8 ## [22] stringr_1.4.0 knitr_1.38 sass_0.4.1 ## [25] grid_4.2.0 R6_2.5.1 HDF5Array_1.25.0 ## [28] rmarkdown_2.14 bookdown_0.26 Rhdf5lib_1.19.0 ## [31] magrittr_2.0.3 htmltools_0.5.2 stringi_1.7.6 ## [34] RCurl_1.98-1.6