collapseReplicates: Collapse technical replicates in a RangedSummarizedExperiment...

View source: R/helper.R

collapseReplicatesR Documentation

Collapse technical replicates in a RangedSummarizedExperiment or DESeqDataSet

Description

Collapses the columns in object by summing within levels of a grouping factor groupby. The purpose of this function is to sum up read counts from technical replicates to create an object with a single column of read counts for each sample. This function will issue a warning if there are other assays other than "counts", see details below in 'Value'.

Usage

collapseReplicates(object, groupby, run, renameCols = TRUE)

Arguments

object

A RangedSummarizedExperiment or DESeqDataSet

groupby

a grouping factor, as long as the columns of object

run

optional, the names of each unique column in object. if provided, a new column runsCollapsed will be added to the colData which pastes together the names of run

renameCols

whether to rename the columns of the returned object using the levels of the grouping factor

Details

Note: by "technical replicates", we mean multiple sequencing runs of the same library, in constrast to "biological replicates" in which multiple libraries are prepared from separate biological units. Optionally renames the columns of returned object with the levels of the grouping factor. Note: this function is written very simply and can be easily altered to produce other behavior by examining the source code.

Value

the object with as many columns as levels in groupby. This object has "counts" data which is summed from the various columns which are grouped together, and the colData is subset using the first column for each group in groupby. Other assays are dropped, as it is not unambiguous the correct form of combination, and a warning is printed if they are present, so the user is aware they should take care of such assays manually.

Examples


dds <- makeExampleDESeqDataSet(m=12)

# make data with two technical replicates for three samples
dds$sample <- factor(sample(paste0("sample",rep(1:9, c(2,1,1,2,1,1,2,1,1)))))
dds$run <- paste0("run",1:12)

ddsColl <- collapseReplicates(dds, dds$sample, dds$run)

# examine the colData and column names of the collapsed data
colData(ddsColl)
colnames(ddsColl)

# check that the sum of the counts for "sample1" is the same
# as the counts in the "sample1" column in ddsColl
matchFirstLevel <- dds$sample == levels(dds$sample)[1]
stopifnot(all(rowSums(counts(dds[,matchFirstLevel])) == counts(ddsColl[,1])))


mikelove/DESeq2 documentation built on March 10, 2024, 10:32 a.m.