QC and Filtering
A count matrix fresh out of a pipeline is mostly genes with counts at or near zero in every sample. Those rows carry no information about differences between conditions, and they add noise to the variance estimate. The first step is to drop them. The second is to look at how the samples relate before any model is fit, when a swapped label or an outlier is still easy to catch.
Filter low-count genes
Section titled “Filter low-count genes”The common rule keeps a gene when it has at least 10 reads summed across all samples. The threshold applies to the raw counts, before normalization, and it works as a floor rather than a parameter to tune. A gene under that floor has too few observations for a differential expression test to have any power.
The total-count filter below matches the prefilter in the DESeq2 1.30.1 vignette. The DESeq2 1.52.0 vignette instead applies a sample-count threshold. These comparisons do not identify the revision used during code generation. The source package licenses this vignette under LGPL version 3 or later.
The count object comes from Michael Love’s airway 1.32.0 data package, which declares LGPL. It represents the Himes and colleagues experiment, deposited as GSE52778 and SRP033351. The source and license notice identifies the original object. This lesson derives its summaries and analysis results from that object.
The compared DESeq2 1.30.1 vignette by Michael I. Love, Simon Anders, and Wolfgang Huber ships in the package source archive. Its package license is LGPL version 3 or later. The LGPL text and its GPL terms accompany this reference.
library(DESeq2)library(airway)
data(airway)dds <- DESeqDataSet(airway, design = ~ cell + dex)dds$dex <- relevel(dds$dex, ref = "untrt")
# Keep genes with at least 10 reads total.keep <- rowSums(counts(dds)) >= 10dds <- dds[keep, ]
# Genes before and after filtering.nrow(airway)nrow(dds)[1] 63677[1] 22369DESeqDataSet needs a design, so the formula ~ cell + dex and the untreated reference
level are set here. The DESeq2 page explains both.
Neither the filter above nor the blind transform below uses them.
Variance-stabilizing transformation
Section titled “Variance-stabilizing transformation”Raw counts make a poor input for PCA, because the samples differ in sequencing depth and
the variance of a count grows with its mean. The
normalization page explains both problems and the
variance-stabilizing transform, vst, that answers them.
# Variance-stabilizing transform, blind to the design for QC.vsd <- vst(dds, blind = TRUE)
# Transformed dimensions match the filtered gene set.dim(assay(vsd))[1] 22369 8With blind = TRUE, the transform ignores the design, which suits an unsupervised look
at the samples. The normalization page compares it with blind = FALSE.
When the samples separate by condition on a PCA of the transformed counts, the treatment has a detectable effect. A sample sitting far from its own group points to a swapped label or a bad library.
# PCA data: one row per sample. plotPCA returns every column of the sample# metadata, so select the two axes and the covariates that the design uses.pca_data <- plotPCA(vsd, intgroup = c("dex", "cell"), returnData = TRUE)head(pca_data[, c("PC1", "PC2", "group", "dex", "cell")])
# The fraction of variance on each axis.attr(pca_data, "percentVar") PC1 PC2 group dex cellSRR1039508 -20.261251 -4.3138021 untrt:N61311 untrt N61311SRR1039509 9.600245 -0.9134282 trt:N61311 trt N61311SRR1039512 -11.226224 -4.4215017 untrt:N052611 untrt N052611SRR1039513 20.313084 -2.5411925 trt:N052611 trt N052611SRR1039516 -17.032150 17.8512194 untrt:N080611 untrt N080611SRR1039517 11.716744 23.1974284 trt:N080611 trt N080611[1] 0.4094782 0.2613781plotPCA keeps the 500 genes with the highest variance across the samples, so the
percentVar attribute is the fraction of their variance that each axis carries. The
first axis carries 0.4094782 of it, and in the six rows printed every untreated sample
has a negative PC1 and every treated sample a positive one. That split is the signal
that the treatment moved expression. The
visualization page draws the PCA as
a figure from the blind = FALSE transform, so its percentages differ from these.
Scientific references
Section titled “Scientific references”Love, Huber, and Anders, 2014 describe the DESeq2 count model and its shrinkage of dispersion and fold change estimates.
Himes and colleagues, 2014 report the airway smooth muscle RNA-seq experiment that the airway data package holds.
Further reading
Section titled “Further reading”The DESeq2 transformation and PCA guide explains blind dispersion estimation and sample exploration. It helps distinguish a QC plot from a treatment-effect test.
The airway dataset vignette documents the donor and dexamethasone labels. These labels provide the biological context for sample distances and PCA.