aggregate: Aggregate Rows or Columns

Description Usage Arguments Details Value Methods (by class) Author(s) See Also Examples

Description

Aggregate gene/transcript features (rows) or sample replicates (columns).

Usage

 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
## S4 method for signature 'matrix'
aggregateRows(object, groupings, fun = c("sum",
  "mean"))

## S4 method for signature 'matrix'
aggregateCols(object, groupings, fun = c("sum",
  "mean"))

## S4 method for signature 'sparseMatrix'
aggregateRows(object, groupings, fun = c("sum",
  "mean"))

## S4 method for signature 'sparseMatrix'
aggregateCols(object, groupings, fun = c("sum",
  "mean"))

## S4 method for signature 'SummarizedExperiment'
aggregateRows(object, col = "aggregate",
  fun = c("sum", "mean"))

## S4 method for signature 'SummarizedExperiment'
aggregateCols(object, col = "aggregate",
  fun = c("sum", "mean"))

## S4 method for signature 'SingleCellExperiment'
aggregateCols(object, fun = c("sum",
  "mean"))

Arguments

object

Object.

groupings

factor. Defines the aggregation groupings. The new aggregate names are defined as the factor levels, and the original, unaggregated names are defined as the names.

fun

string. Name of the aggregation function. Uses base::match.arg().

col

string. Name of column in either SummarizedExperiment::rowData() or SummarizedExperiment::colData() that defines the desired aggregation groupings.

Details

aggregateRows() works down the rows, and is designed to aggregate features (e.g. genes or transcripts). Most commonly, the aggregateRows() function can be used to aggregate counts from transcript-level to gene-level.

aggregateCols() works across the columns, and is designed to aggregate sample replicates.

Value

Modified object, with aggregated rows (features) or columns (samples).

Methods (by class)

Author(s)

Michael Steinbaugh, Rory Kirchner

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
## Example data ====
counts <- matrix(
    data = c(
        0L, 1L, 1L, 1L,
        1L, 0L, 1L, 1L,
        1L, 1L, 0L, 1L,
        1L, 1L, 1L, 0L
    ),
    nrow = 4L,
    ncol = 4L,
    byrow = TRUE,
    dimnames = list(
        paste0("transcript", seq_len(4L)),
        paste(
            paste0("sample", rep(seq_len(2L), each = 2L)),
            paste0("replicate", rep(seq_len(2L), times = 2L)),
            sep = "_"
        )
    )
)
print(counts)

genes <- factor(paste0("gene", rep(seq_len(2L), each = 2L)))
names(genes) <- rownames(counts)
print(genes)

samples <- factor(paste0("sample", rep(seq_len(2L), each = 2L)))
names(samples) <- colnames(counts)
print(samples)

cells <- factor(paste0("cell", rep(seq_len(2L), each = 2L)))
names(samples) <- colnames(counts)
print(samples)

## matrix
matrix <- as(counts, "matrix")
class(matrix)
print(matrix)

## sparseMatrix
sparse <- as(matrix, "sparseMatrix")
class(sparse)
print(sparse)

## SummarizedExperiment
se <- SummarizedExperiment::SummarizedExperiment(
    assay = list(counts = sparse),
    colData = S4Vectors::DataFrame(
        sampleName = names(samples),
        aggregate = samples
    ),
    rowData = S4Vectors::DataFrame(aggregate = genes)
)
print(se)

## aggregateRows ====
aggregateRows(matrix, groupings = genes)
aggregateRows(sparse, groupings = genes)
aggregateRows(se)

## aggregateCols ====
aggregateCols(matrix, groupings = samples)
aggregateCols(sparse, groupings = samples)
aggregateCols(se)

steinbaugh/basejump.experiment documentation built on Nov. 5, 2018, 10:36 p.m.