Wrapper function that helps set up lfcShrink() to shrink LFC values for a pairwise contrast via apeglm, without having to manually relevel factor reference levels to use the required coef argument.

apeglmResults(object, ...)

# S4 method for DESeqDataSet
apeglmResults(object, contrast, ...)

Arguments

object

Object.

...

Passes to lfcShrink(), with type = "apeglm" and coef automatically defined. Optionally can pass unshrunken DESeqResults via res argument here and this will set alpha, lfcThreshold automatically.

contrast

character(3). Pairwise contrast vector:

  1. factor: Grouping factor. Corresponds to column name in colData().

  2. numerator: Numerator samples.

  3. denominator: Denominator samples.

Numerator and denominator values correspond to grouping factor column. See results() for details. Note that we're intentionally being more strict about the input format here.

Value

DESeqResults, with apeglm adaptive shrinkage applied to fold change values.

Details

Dynamically sets reference factor levels, as recommended by DESeq2 vignette. Matches contrast input internally to corresponding coef corresponding to values in resultsNames().

Runs nbinomWaldTest() via DESeq(), followed by lfcShrink().

Note

Updated 2019-11-19.

See also

Examples

dds <- DESeq2::makeExampleDESeqDataSet(n = 1000L, m = 12L) dds$condition <- factor(rep(LETTERS[seq_len(4L)], each = 3L)) dds <- DESeq2::DESeq(dds)
#> estimating size factors
#> estimating dispersions
#> gene-wise dispersion estimates
#> mean-dispersion relationship
#> final dispersion estimates
#> fitting model and testing
#> [1] "Intercept" "condition_B_vs_A" "condition_C_vs_A" "condition_D_vs_A"
## Contrast C vs. B. contrast <- c(factor = "condition", numerator = "C", denominator = "B") ## Unshrunken DESeqResults. res <- DESeq2::results(dds, contrast = contrast) class(res)
#> [1] "DESeqResults" #> attr(,"package") #> [1] "DESeq2"
#> [1] "unshrunken"
## Shrunken DESeqResults, using apeglm via `lfcShrink()`. if (requireNamespace("apeglm", quietly = TRUE)) { shrink <- apeglmResults(dds, contrast = contrast) class(shrink) lfcShrinkType(shrink) }
#> Design: ~condition
#> using pre-existing size factors
#> estimating dispersions
#> found already estimated dispersions, replacing these
#> gene-wise dispersion estimates
#> mean-dispersion relationship
#> final dispersion estimates
#> fitting model and testing
#> Contrast: condition_C_vs_B #> Coef: 3
#> [1] "apeglm"