The following examples demonstrate how to shuttle data between DESeqDataSet and DGEList containers. Before we start, let's first load the required packages.
library(DESeq2) library(edgeR) library(DEFormats)
We will illustrate the functionality of the package on a mock expression
data set of an RNA-seq experiment. The sample counts table can be generated
using the function provided by
counts = simulateRnaSeqData()
The resulting object is a matrix with rows corresponding to genomic features and columns to samples.
In order to construct a DGEList object we need to provide, apart from the counts matrix, the sample grouping.
group = rep(c("A", "B"), each = 3) dge = DGEList(counts, group = group) dge
A DGEList object can be easily converted to a DESeqDataSet object with the
help of the function
dds = as.DESeqDataSet(dge) dds
Just to make sure that the coercions conserve the data and metadata, we now
dds back to a DGEList and compare the result to the original
Note that because of the use of reference classes in the SummarizedExperiment
class which DESeqDataSet extends,
identical will return
FALSE for any two
DESeqDataSet instances, even for ones constructed from the same input:
dds1 = DESeqDataSetFromMatrix(counts, data.frame(condition=group), ~ condition) dds2 = DESeqDataSetFromMatrix(counts, data.frame(condition=group), ~ condition) identical(dds1, dds2)
Instead of a count matrix,
simulateRnaSeqData can also return an
annotated RangedSummarizedExperiment object. The advantage of such an object
is that, apart from the counts matrix stored in the
assay slot, it also
contains sample description in
colData, and gene information stored in
rowRanges as a
se = simulateRnaSeqData(output = "RangedSummarizedExperiment") se
se object can be readily used to construct a DESeqDataSet object,
dds = DESeqDataSet(se, design = ~ condition)
which can be converted to a DGEList using the familiar method.
dge = as.DGEList(dds) dge
Note the additional
genes element on the
dge list compared to the object
from the previous section.
Similarly as for the
DESeqDataSet constructor from
it is possible to directly use RangedSummarizedExperiment objects as input to
DGEList constructor defined in
r Rpackage("DEFormats"). This
allows you to use common input objects regardless of whether you are applying
r Rpackage("DESeq2") or
r Rpackage("edgeR") to perform your analysis, or to
easily switch between these two tools in your pipeline.
names(colData(se)) = "group" dge = DGEList(se) dge
We renamed the
condition column of
group in order to allow
r Rpackage("edgeR") to automatically pick up the correct sample grouping.
Another way of specifying this is through the argument
Even though there is no direct method to go from a DGEList to a RangedSummarizedExperiment, the coercion can be easily performed by first converting the object to a DESeqDataSet, which is a subclass of RangedSummarizedExperiment, and then coercing the resulting object to its superclass.
dds = as.DESeqDataSet(dge) rse = as(dds, "RangedSummarizedExperiment") rse
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.