de — differential expression¶
Important
The model formulas in this module use detk's formula mini-language. Read that first before writing your models.
Also remember to filter prior to differential expression — the number of genes provided for hypothesis testing affects the results. You may need to filter out genes with zero expression in all samples of interest.
Each method accepts a design formula, a counts matrix file, and a column data file. Both methods run in R via the wrapr bridge and require the corresponding R package.
deseq2¶
Command line interface to a canonical DESeq2 analysis:
detk-de deseq2 "counts ~ AgeOfDeath + Status" raw_counts.csv column_data.csv > deseq2_results.csv
Tip
- You can provide the whole raw counts matrix with a column data file containing only the samples you care about — detk subsets for you.
- Add brackets with the name of the reference group to control what you
are comparing against, e.g.
"counts ~ Status[control]".
This is roughly equivalent to the following R:
library(DESeq2)
counts <- read.csv("raw_counts.csv", rownames=1)
design.mat <- read.csv("column_data.csv")
dds <- DESeqDataSetFromMatrix(
countData = counts,
colData = design.mat,
design = ~ AgeOfDeath + Status
)
dds <- DESeq(dds, minReplicatesForReplace=Inf)
write.csv(results(dds, independentFiltering=FALSE, cooksCutoff=Inf), de.out.fn)
The analysis implemented here differs from the default DESeq2 analysis in the following ways:
- the design formula must have
countsas the only term on the left hand side - no outlier mean trimming based on Cook's distance is performed
- no p-values or adjusted p-values are flagged or omitted due to outliers
- estimated parameters, statistics, and p-values are reported for all
variables in the model, rather than just the last term (request the DESeq2
default with
--last-term-only) - no independent filtering is performed
- every output column is prefixed with its model term, e.g.
Status__case__log2FoldChangefor thecaselevel ofStatus
usage: detk-de deseq2 [options] <design> <counts_fn> <cov_fn>
positional arguments:
<design> Model formula, quoted, such as "counts ~ group"
<counts_fn> Counts file: features in rows, samples in columns, delimited
<cov_fn> Sample information file: samples in rows, the first column their
names
options:
-h, --help Print this help and exit
-o, --output FILE Destination of primary output (default: stdout)
--routput-dir DIR Directory to keep the R script, its inputs and outputs in,
for debugging
--rda FILE File to saveRDS() the R result objects of the analysis to
--strict Require the counts file's sample columns to be the same as,
and in the same order as, the rows of the sample
information file
--norm-counts Do not let DESeq2 normalize the counts: they are already
normalized
--last-term-only Report the parameters of the model's last term only
(DESeq2's default)
--gene-wise-disp Use estimateDispersionsGeneEst instead of
estimateDispersions
--cores N Number of cores DESeq2 uses (needs the BiocParallel
package) (default: none)
firth¶
When comparing two classes of samples, Firth's logistic regression as described by Choi et al has desirable statistical properties: a better controlled type I error rate, and less loss of power from including additional covariates, compared with other DE methods including DESeq2. It uses a penalized likelihood to avoid complete separation of the data, a common occurrence in RNA-seq. The trade-off is that it needs more samples than negative-binomial methods — at least ~10 replicates per condition.
A counts term must be included on the right hand side of the design
formula, with the sample class on the left:
detk-de firth "Status ~ AgeOfDeath + counts" norm_counts.csv column_data.csv > firth_results.csv
usage: detk-de firth [options] <design> <counts_fn> <cov_fn>
positional arguments:
<design> Model formula, quoted, such as "counts ~ group"
<counts_fn> Counts file: features in rows, samples in columns, delimited
<cov_fn> Sample information file: samples in rows, the first column their
names
options:
-h, --help Print this help and exit
-o, --output FILE Destination of primary output (default: stdout)
--routput-dir DIR Directory to keep the R script, its inputs and outputs in,
for debugging
--rda FILE File to saveRDS() the R result objects of the analysis to
--strict Require the counts file's sample columns to be the same as,
and in the same order as, the rows of the sample
information file
--standardize Standardize the counts first, so the coefficients are
directly comparable
--cores N Number of cores R uses (needs the parallel R package)
(default: none)