Skip to contents

Builds a geneda object from a SummarizedExperiment, including DESeqDataSet objects from DESeq2 and DESeqTransform objects returned by DESeq2::vst() or DESeq2::rlog(). Raw counts, normalized values, and sample metadata (colData) are carried over, so the object is ready for FindVariableFeatures(), RunPCA(), and the plotting functions.

Usage

as.geneda(x, ...)

# S4 method for class 'SummarizedExperiment'
as.geneda(
  x,
  normalized = NULL,
  counts = "counts",
  transform = c("vst", "logcpm"),
  DEGs = NULL,
  ...
)

Arguments

x

A SummarizedExperiment (or subclass such as DESeqDataSet or DESeqTransform) with features as rows and samples as columns.

...

Not used.

normalized

Where the normalized values come from. One of:

  • NULL (default): computed from the counts assay using transform. If x is a DESeqTransform, its transformed values are used instead.

  • A single assay name or index in x.

  • A SummarizedExperiment with the same features and samples as x, for example the output of DESeq2::vst(x). Its first assay is used.

  • A matrix with the same row and column names as x.

counts

Name or index of the raw counts assay in x, or NULL to leave the counts slot empty. Default "counts". If the assay is not present, the counts slot is left empty, unless counts are needed to compute normalized.

transform

Normalization used when normalized = NULL: "vst" (variance stabilizing transformation from DESeq2, blind = TRUE) or "logcpm" (log2 counts per million with a pseudocount of 1). Default "vst", which requires the DESeq2 package and integer counts.

DEGs

Optional named list of DEG tables (data.frame or DESeqResults) to store with SetDEGs(), using the list names as assay names.

Value

A geneda object.

Details

Sample metadata are taken from colData(x) and converted to a data.frame. Columns added by DESeq2, such as sizeFactor, are kept and can be tested with PlotEigenCorr() like any other covariate.

Assays stored as sparse or delayed matrices are converted to base matrices with as.matrix().

See also

GenEDA() to build a geneda object from matrices.

Examples

data(Snail1KO)
counts <- as.matrix(Snail1KO$rawCounts)
counts <- counts[rowSums(counts >= 10) >= 3, ]
meta <- Snail1KO$metadata
rownames(meta) <- meta$Sample

se <- SummarizedExperiment::SummarizedExperiment(
    assays = list(counts = counts),
    colData = meta
)
obj <- as.geneda(se, transform = "logcpm")
#> Normalizing counts with log2(CPM + 1).
obj
#> geneda object
#>   features: 11247
#>   samples:  6
#>   HVGs: 0
#>   DimReduction: 0
#>   counts: present
#>   DEGs: none

# From a DESeqDataSet, with VST-normalized values and DEGs
if (requireNamespace("DESeq2", quietly = TRUE)) {
    meta$Genotype <- factor(meta$Genotype, levels = c("WT", "Snai1_KO"))
    dds <- DESeq2::DESeqDataSetFromMatrix(counts, meta, design = ~Genotype)
    dds <- DESeq2::DESeq(dds, quiet = TRUE)
    obj <- as.geneda(dds,
        normalized = DESeq2::vst(dds),
        DEGs = list(KO_vs_WT = DESeq2::results(dds))
    )
    obj
}
#> geneda object
#>   features: 11247
#>   samples:  6
#>   HVGs: 0
#>   DimReduction: 0
#>   counts: present
#>   DEGs: KO_vs_WT