RangedSparseSummarizedExperiment-class: RangedSparseSummarizedExperiment objects

Description Usage Arguments Details Constructor Accessors GRanges compatibility (rowRanges access) Subsetting Extension Author(s) See Also Examples

Description

The RangedSparseSummarizedExperiment class extends the RangedSummarizedExperiment class by adding the sparseAssays slot, which contains a SparseAssays object.

RangedSummarizedSparseExperiment is a subclass of both SparseSummarizedExperiment and RangedSummarizedExperiment, with the former having precedence. As such, all the methods documented in ?SparseSummarizedExperiment and ?RangedSummarizedExperiment also work on a RangedSparseSummarizedExperiment object. See SparseSummarizedExperiment for details.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
## Constructor

SparseSummarizedExperiment(sparseAssays, ...)

## S4 method for signature 'SparseAssays'
SparseSummarizedExperiment(sparseAssays,
  assays = SimpleList(), rowData = NULL, rowRanges = GRangesList(),
  colData = DataFrame(), metadata = list())

## S4 method for signature 'missing'
SparseSummarizedExperiment(sparseAssays, ...)

Arguments

sparseAssays

A SparseAssays object.

assays

A list or SimpleList of matrix elements, or a matrix. All elements of the list must have the same dimensions, and dimension names (if present) must be consistent across elements and with the row names of rowRanges and colData.

rowData

A DataFrame object describing the rows. Row names, if present, become the row names of the SummarizedExperiment object. The number of rows of the DataFrame must equal the number of rows of the matrices in assays.

rowRanges

A GRanges or GRangesList object describing the ranges of interest. Names, if present, become the row names of the SummarizedExperiment object. The length of the GRanges or GRangesList must equal the number of rows of the matrices in assays. If rowRanges is missing, a SummarizedExperiment instance is returned.

colData

An optional DataFrame describing the samples. Row names, if present, become the column names of the RangedSummarizedExperiment.

metadata

An optional list of arbitrary content describing the overall experiment.

...

For SummarizedExperiment, S4 methods list and matrix, arguments identical to those of the SimpleList method.

For rowRanges, ignored.

Details

See SparseAssays and RangedSummarizedExperiment.

Constructor

RangedSparseSummarizedExperiment instances are constructed using the SparseSummarizedExperiment function with arguments outlined above.

Accessors

See SparseAssays and RangedSummarizedExperiment.

GRanges compatibility (rowRanges access)

See RangedSummarizedExperiment.

Subsetting

See RangedSummarizedExperiment.

Extension

RangedSparseSummarizedExperiment is implemented as an S4 class, and can be extended in the usual way, using contains = "RangedSparseSummarizedExperiment" in the new class definition.

Author(s)

Peter Hickey, peter.hickey@gmail.com

See Also

Examples

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
sl1 <- SimpleList(
s1 = SimpleList(key = as.integer(c(NA, 1, NA, NA, 2, NA, 3, NA, 4, 5)),
                value = matrix(1:10, ncol = 2)),
s2 = SimpleList(key = as.integer(c(NA, NA, 1, 2, NA, NA, 3, 4, NA, NA)),
                value = matrix(8:1, ncol = 2)))

sl2 <- SimpleList(
  s1 = SimpleList(key = as.integer(c(NA, 1, NA, 2, 2, NA, 1, NA, NA, 1)),
                  value = matrix(1:2, ncol = 1)),
  s2 = SimpleList(key = as.integer(c(1, 1, 1, 2, NA, NA, NA, NA, NA, NA)),
                  value = matrix(4:3, ncol = 1)))
sa <- SparseAssays(SimpleList(sa1 = sl1, sa2 = sl2))
colData <- DataFrame(Genotype = c("WT", "KO"),
                     row.names = c("s1", "s2"))
sse <- SparseSummarizedExperiment(sparseAssays = sa,
                                  colData = colData)
rowRanges <- GRanges(rep(c("chr1", "chr2"), c(3, 7)),
                     IRanges(c(1, 5, 11, 15, 21, 100, 200, 300, 5000, 5010),
                             width = 50),
                     strand = rep(c("+", "-"), times = 5),
                     feature_id = paste0("f", 1:10))
rsse <- SparseSummarizedExperiment(sparseAssays = sa,
                                   rowRanges = rowRanges,
                                   colData = colData)
rsse
dim(rsse)
dimnames(rsse)
sparseAssayNames(rsse)
sparseAssay(rsse)
# densify the first sparse assay.
# In general its a bad idea to use densify = TRUE, but these data are small
# enough not to worry.
densify(sparseAssay(rsse), 1, 1:2)[[1]]
# TODO: Implement saapply
#sparseAssays(rsse) <- saapply(assays(rse), asinh)
sparseAssay(rsse)
# densify the first sparse assay
densify(sparseAssay(rsse), 1, 1:2)[[1]]

rowRanges(rsse)
rowData(rsse)  # same as 'mcols(rowRanges(rsse))'

rsse[, rsse$Genotype == "WT"]

## cbind() combines objects with the same features of interest
## but different samples:
rsse1 <- rsse
rsse2 <- rsse1[, 1]
colnames(rsse2) <- "s3"
cmb1 <- cbind(rsse1, rsse2)
dim(cmb1)
dimnames(cmb1)

## rbind() combines objects with the same samples but different
## features of interest:
rsse1 <- rsse
rsse2 <- rsse1[1:5, ]
rownames(rsse2) <- letters[1:nrow(rsse2)]
cmb2 <- rbind(rsse1, rsse2)
dim(cmb2)
dimnames(cmb2)

## combine() combines objects with potentially different genomic ranges of
## interest and different samples, by finding matching genomic ranges:
rsse1 <- rsse[1:5, ]
names(rsse1) <- letters[1:5]
rsse2 <- rsse[3:8, 2]
names(rsse2) <- letters[3:8]
cmb3 <- combine(rsse1, rsse2)
dim(cmb3)
dimnames(cmb3)

## Coercion to/from SparseSummarizedExperiment:
sse <- as(rsse, "SparseSummarizedExperiment")
sse

as(sse, "RangedSparseSummarizedExperiment")
## Coercion to/from RangedSummarizedExperiment
## Using as() drops the sparseAssays slot
rse <- as(rsse, "RangedSummarizedExperiment")
as(rse, "RangedSparseSummarizedExperiment")
## But using makeSEFromSSE() preserves the sparseAssays slot by densifying and
## storing it in the assays slot.
rse2 <- makeSEFromSSE(rsse)
assays(rse2)
## However, converting back does not re-sparsify the sparse assays
rsse2 <- as(rse2, "RangedSparseSummarizedExperiment")
sparseAssays(rsse2)

## Setting rowRanges on a SparseSummarizedExperiment object turns it into a
## RangedSparseSummarizedExperiment object:
sse2 <- sse
rowRanges(sse) <- rowRanges
sse  # RangedSparseSummarizedExperiment

## Sanity checks:
stopifnot(identical(assays(sse), assays(rsse)))
stopifnot(identical(dim(sse), dim(rsse)))
stopifnot(identical(dimnames(sse), dimnames(rsse)))
stopifnot(identical(rowData(sse), rowData(rsse)))
stopifnot(identical(colData(sse), colData(rsse)))

PeteHaitch/SparseSummarizedExperiment documentation built on May 8, 2019, 1:31 a.m.