Package 'LoomExperiment'

Title: LoomExperiment container
Description: The LoomExperiment package provide a means to easily convert the Bioconductor "Experiment" classes to loom files and vice versa.
Authors: Martin Morgan, Daniel Van Twisk
Maintainer: Bioconductor Package Maintainer <[email protected]>
License: Artistic-2.0
Version: 1.25.0
Built: 2024-10-30 07:37:22 UTC
Source: https://github.com/bioc/LoomExperiment

Help Index


Export LoomExperiment to LoomFile

Description

Exports a LoomExperiment to a LoomFile. Note the colGraph and rowGraph contained within the LoomExperimnet object are 1-indexed in R and are converted to 0-indexed in the loom file.

Usage

## S4 method for signature 'LoomExperiment,LoomFile,ANY'
export(object, con,
    matrix=assayNames(object)[1], rownames_attr="rownames", colnames_attr="colnames")

Arguments

object

A LoomExperiment object to be exported. File must have the .loom extension.

con

The connection from which data is loaded or to which data is saved. If this is a character vector, it is assumed to be a filename and a corresponding file connection is created and then closed after exporting the object. If a RTLFile derivative, the data is loaded from or saved to the underlying resource.

matrix

A matrix in which the column and rows for the Loom file will be derived. The default argument is dervied from the the first assay in the LoomExperiment object.

rownames_attr

A character vector indicating the name of the rowData attribute to represent the names rownames in the LoomExperiment object.

colnames_attr

A character vector indicating the name of the colData attribute to represent the names colnames in the LoomExperiment object.

Value

An error code indiciating whether the operation was successful.

See Also

LoomExperiment, LoomFile,

Examples

counts <- matrix(rpois(100, lambda = 10), ncol=10, nrow=10)
sce <- SingleCellExperiment(assays = list(counts = counts))
scle <- SingleCellLoomExperiment(sce)
tempfile <- tempfile(fileext=".loom")
export(scle, tempfile)

Import LoomExperiment from LoomFile

Description

Imports a LoomExperiment from a LoomFile. Note the colGraph and rowGraph contained within the 0-indexed loom file will be converted to the 1-indexed represnetation in the resulting LoomExperiment object.

Usage

## S4 method for signature 'LoomFile,ANY,ANY'
import(con, ...,
    type = c("SingleCellLoomExperiment", "LoomExperiment", "RangedLoomExperiment"),
    rownames_attr=NULL, colnames_attr=NULL)

Arguments

con

A character indicating the loom file to be created. File must have the .loom extension.

...

Additional arguments

type

Either "SingleCellLoomExperiment", "LoomExperiment", or "RangedLoomExperiment". This value decides what type of object that will be returned by import. If left empty import will either determine what type of class should be used by the context of the file. If it cannot be determined, the LoomExperiment type will default to SingleCellLoomExperiment.

rownames_attr

A character vector indicating the name of the rowData attribute to represent the names rownames in the LoomExperiment object.

colnames_attr

A character vector indicating the name of the colData attribute to represent the names colnames in the LoomExperiment object.

Value

An object of class LoomExperiment

See Also

LoomExperiment, LoomFile,

Examples

l1_file <- system.file("extdata", "L1_DRG_20_example.loom", package = "LoomExperiment")
scle <- import(l1_file, type="SingleCellLoomExperiment")
scle

L1_DRG_20_example.loom

Description

An example hdf5 file in the Loom file format obtained from the Linnarson Lab.

The original file was imported using LoomExperiment and truncated using the package's subsetting methods. The purpose of this truncation was to reduce the total size of the data as the file's purpose is simply to demonstrate LoomExperiment's functionality.

The data set has dimensions of 20x20. The file contains 7 rowData and 103 colData entries each corresponding to readings generated by high-throughput sequencing experiments. In addition, a colGraphs entry encoding aLoomGraph containing two LoomGraph objects are also included.

Format

An hdf5 file in the Loom format

Examples

## Load L1_DRG_20_example.loom using LoomExperiment's import() method
l1_file <- system.file("extdata", "L1_DRG_20_example.loom", package = "LoomExperiment")
scle <- import(l1_file, type="SingleCellLoomExperiment")
scle

LoomExperiment, RangedLoomExperiment, and SingleCellLoomExperiment classes

Description

The LoomExperiment family of classes is used as a bridge between Bioconductor's "Experiment" classes and the Linnarson Lab's http://linnarssonlab.org/loompy/index.html. The family of LoomExperiment classes all inherit from the class LoomExperiment as well as their respectively named parent classes. The LoomExperiment class inheirts from SummarizedExperiment.

Usage

## Constructor

LoomExperiment(..., colGraphs = LoomGraphs(), rowGraphs = LoomGraphs())
RangedLoomExperiment(..., colGraphs = LoomGraphs(), rowGraphs = LoomGraphs())
SingleCellLoomExperiment(..., colGraphs = LoomGraphs(), rowGraphs = LoomGraphs())

## Accessors

## S4 method for signature 'LoomExperiment'
colGraphs(x, ...)
## S4 replacement method for signature 'LoomExperiment'
colGraphs(x, ...) <- value
## S4 method for signature 'LoomExperiment'
rowGraphs(x, ...)
## S4 replacement method for signature 'LoomExperiment'
rowGraphs(x, ...) <- value

## Subsetting

## S4 method for signature 'LoomExperiment'
x[i, j, ..., drop=TRUE]

## Binding

## S4 method for signature 'LoomExperiment'
rbind(..., deparse.level=1)
## S4 method for signature 'LoomExperiment'
cbind(..., deparse.level=1)

Arguments

x

A LoomExperiment object

colGraphs, rowGraphs

LoomGraphs to be placed in either the colGraphs or rowGraphs slot respectively

value

For colGraphs<- and rowGraphs<-, value will be the replacement to the slot. For dropHits<-, indices to replace selected indices with.

...

For constructors, ... will be passed on to the respective Experiment constructor.

i, j

For subsetting, indices specifying elements to subset LoomGraph by. For dropHits, numeric indicating the node number

drop

For matrices and arrays. If 'TRUE' the result is coerced to the lowest posible dimesnion. This only woeks for extracting elements, not for the replacement.

deparse.level

See '?base::cbind' for a description of this argument.

Details

The LoomExperiment class is a virtual class meant to to act as an interface for other "_LoomExperiment" classes. It contains two slots:

colGraphs:

A LoomGraphs object containing col_graph data as specified by the loom format.

rowGraphs:

A LoomGraphs object containing row_graph data as specified by the loom format.

The intended use of this class is as an interface that allows various slots and operations necessary for subsequent "_LoomExperiment" classes to be defined.

The colGraphs and rowGraphs slot stores a LoomGraphs object that stores a graph of edges between vertices and possibly associated weights. These slots may be NULL.

Value

An object of class LoomExperiment

Author(s)

Daniel Van Twisk

See Also

SummarizedExperiment, RangedSummarizedExperiment, SingleCellExperiment

Examples

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

## Get and replace rowGraphs and colGraphs
colGraphs(scle)
rowGraphs(scle)

a <- c(1, 2, 3)
b <- c(3, 2, 1)
w <- c(100, 10, 1)
lg <- LoomGraph(a, b, weight=w)
lgs <- LoomGraphs(lg, lg)
names(lgs) <- c('lg1', 'lg2')
lgs

colGraphs(scle) <- lgs
rowGraphs(scle) <- lgs

colGraphs(scle)
rowGraphs(scle)
colGraphs(scle)[[1]]
rowGraphs(scle)[[1]]

## Subsetting
scle2 <- scle[c(1, 3), 1:2]
colGraphs(scle2)[[1]]
rowGraphs(scle2)[[1]]

LoomFile objects

Description

A LoomFile class represents a loom file based on the Linnarson Lab's http://linnarssonlab.org/loompy/index.html. A loom file is encoded as an hdf5 file. A loom file consists of a main matrix, optional additional layers, a variable number of row and column annotations and sparse graph objects. It is used to efficienctly stroe very large omics datasets.

The LoomFile class extends the functionality of the BiocFile from the BiocIO package.

Author(s)

Daniel Van Twisk


LoomGraph class

Description

The LoomGraph class extends the SelfHits class. The SelfHits class represents a set of hits between a set of left node and right nodes. Only the Hits are stored in a SelfHits object. The LoomGraph class is meant to store graph information and was created to be used in conjunction with the LoomExperiment class. Its purpose is to store either a col_graph or row_graph as specified by the loom file format. Attributes from and to indicate an edge between two vertices. The w column indicates the weight of the corresponding edge and is optional.

Usage

LoomGraph(from, to, nnode=max(from, to), ..., weight=NULL)

## S4 method for signature 'LoomGraph'
rbind(..., deparse.level=1)
## S4 method for signature 'LoomGraph'
cbind(..., deparse.level=1)

Arguments

...

Arguments to pass to the SelfHits constructor.

from

A numeric vector of nodes indicating one side of the graph's edge.

to

A numeric vector of node indicating the second side of the graph's edge.

nnode

An integer indicating the maximum number of nodes in the graph.

weight

A numeric vector indicating the weight between the prospective edges.

deparse.level

See '?base::cbind' for a description of this argument

Value

A LoomGraph object is returned from the constructor.

Author(s)

Daniel Van Twisk

See Also

LoomExperiment, LoomGraphs, SelfHits

Examples

## Construction
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

## Subsetting
lg[c(1, 2)]
lg[-c(2)]

LoomGraphs class

Description

The LoomGraphs class extends the SimpleList class. It is meant to store multiple LoomGraph objects and was created to be used in conjunction with the LoomExperiment class. Its purpose is to store multiple col_graph or row_graph as specified by the loom file format. Only LoomGraph obects may be stored in a LoomGraphs object.

Usage

LoomGraphs(...)

## S4 method for signature 'LoomGraphs'
rbind(..., deparse.level=1)
## S4 method for signature 'LoomGraphs'
cbind(..., deparse.level=1)

Arguments

...

LoomGraph objects.

deparse.level

See '?base::cbind' for a description of this argument

Value

A LoomGraphs object is returned from the constructor.

Author(s)

Daniel Van Twisk

See Also

LoomExperiment, LoomGraph, SimpleList

Examples

## Construction
lg1 <- LoomGraph(c(1, 2, 3), c(3, 2, 1), weight=c(4, 7, 8))
lg2 <- LoomGraph(c(3, 3, 1), c(3, 1, 2))
lgs <- LoomGraphs(lg1, lg2)
lgs