mergeRows/mergeCols merge data on rows or columns of a SummarizedExperiment as defined by a factor alongside the chosen dimension. Metadata from the rowData or colData are retained as defined by archetype.

mergeRows(x, f, archetype = 1L, ...)

mergeCols(x, f, archetype = 1L, ...)

mergeFeatures(x, f, archetype = 1L, ...)

mergeSamples(x, f, archetype = 1L, ...)

# S4 method for SummarizedExperiment
mergeRows(x, f, archetype = 1L, ...)

# S4 method for SummarizedExperiment
mergeCols(x, f, archetype = 1L, ...)

# S4 method for SummarizedExperiment
mergeFeatures(x, f, archetype = 1L, ...)

# S4 method for SummarizedExperiment
mergeSamples(x, f, archetype = 1L, ...)

# S4 method for TreeSummarizedExperiment
mergeRows(x, f, archetype = 1L, mergeTree = FALSE, mergeRefSeq = FALSE, ...)

# S4 method for TreeSummarizedExperiment
mergeCols(x, f, archetype = 1L, mergeTree = FALSE, ...)

# S4 method for TreeSummarizedExperiment
mergeFeatures(
  x,
  f,
  archetype = 1L,
  mergeTree = FALSE,
  mergeRefSeq = FALSE,
  ...
)

# S4 method for TreeSummarizedExperiment
mergeSamples(x, f, archetype = 1L, mergeTree = FALSE, ...)

Arguments

x

a SummarizedExperiment or a TreeSummarizedExperiment

f

A factor for merging. Must be the same length as nrow(x)/ncol(x). Rows/Cols corresponding to the same level will be merged. If length(levels(f)) == nrow(x)/ncol(x), x will be returned unchanged.

archetype

Of each level of f, which element should be regarded as the archetype and metadata in the columns or rows kept, while merging? This can be single integer value or an integer vector of the same length as levels(f). (Default: archetype = 1L, which means the first element encountered per factor level will be kept)

...

Optional arguments:

mergeTree

TRUE or FALSE: Should rowTree() also be merged? (Default: mergeTree = FALSE)

mergeRefSeq

TRUE or FALSE: Should a consensus sequence be calculated? If set to FALSE, the result from archetype is returned; If set to TRUE the result from DECIPHER::ConsensusSequence is returned. (Default: mergeRefSeq = FALSE)

Value

An object of the same class as x with the specified entries merged into one entry in all relevant components.

Details

assay are agglomerated, i.e. summed up. If the assay contains values other than counts or absolute values, this can lead to meaningless values being produced.

These functions are similar to sumCountsAcrossFeatures. However, additional support for TreeSummarizedExperiment was added and science field agnostic names were used. In addition the archetype argument lets the user select how to preserve row or column data.

For merge data of assays the function from scuttle are used.

Examples

data(esophagus)
esophagus
#> class: TreeSummarizedExperiment 
#> dim: 58 3 
#> metadata(0):
#> assays(1): counts
#> rownames(58): 59_8_22 59_5_13 ... 65_9_9 59_2_6
#> rowData names(0):
#> colnames(3): B C D
#> colData names(0):
#> reducedDimNames(0):
#> mainExpName: NULL
#> altExpNames(0):
#> rowLinks: a LinkDataFrame (58 rows)
#> rowTree: 1 phylo tree(s) (58 leaves)
#> colLinks: NULL
#> colTree: NULL
plot(rowTree(esophagus))

# get a factor for merging
f <- factor(regmatches(rownames(esophagus),
                       regexpr("^[0-9]*_[0-9]*",rownames(esophagus))))
merged <- mergeRows(esophagus,f, mergeTree = TRUE)
plot(rowTree(merged))

#
data(GlobalPatterns)
GlobalPatterns
#> class: TreeSummarizedExperiment 
#> dim: 19216 26 
#> metadata(0):
#> assays(1): counts
#> rownames(19216): 549322 522457 ... 200359 271582
#> rowData names(7): Kingdom Phylum ... Genus Species
#> colnames(26): CL3 CC1 ... Even2 Even3
#> colData names(7): X.SampleID Primer ... SampleType Description
#> reducedDimNames(0):
#> mainExpName: NULL
#> altExpNames(0):
#> rowLinks: a LinkDataFrame (19216 rows)
#> rowTree: 1 phylo tree(s) (19216 leaves)
#> colLinks: NULL
#> colTree: NULL
merged <- mergeCols(GlobalPatterns,colData(GlobalPatterns)$SampleType)
merged
#> class: TreeSummarizedExperiment 
#> dim: 19216 9 
#> metadata(0):
#> assays(1): counts
#> rownames(19216): 549322 522457 ... 200359 271582
#> rowData names(7): Kingdom Phylum ... Genus Species
#> colnames(9): Feces Freshwater ... Soil Tongue
#> colData names(7): X.SampleID Primer ... SampleType Description
#> reducedDimNames(0):
#> mainExpName: NULL
#> altExpNames(0):
#> rowLinks: a LinkDataFrame (19216 rows)
#> rowTree: 1 phylo tree(s) (19216 leaves)
#> colLinks: NULL
#> colTree: NULL