Batch Correction
A batch effect is a difference between your samples that comes from how they were processed rather than from the biology you are testing. Sequencing lane, library preparation date, kit version, instrument: any step that one group of samples went through separately from another group leaves a mark on the counts, and that mark can be larger than the treatment effect you paid to measure.
This section shows what a batch effect looks like in real counts, and the two standard answers to it. One answer puts the batch in the design formula and lets the model absorb it. The other, ComBat, rewrites the data and removes the batch before any model runs. The two serve different purposes, and the last page shows how their results differ.
Every figure and every number on these pages comes from a real run of the code you can
read on the page, in one pinned container, on the Bioconductor pasilla dataset.
The LC-MS drift lesson tests acquisition trends with eight pooled QC injections. It uses held-out QC error before accepting a correction for an ion feature.
The path
Section titled “The path”| Page | What it does |
|---|---|
| What is a batch effect | where batch effects come from, and the design table that records one |
| Detecting batch effects | PCA on variance-stabilized counts, with the batch on the second axis |
| Batch in the design | one extra term in the DESeq2 formula, and what it does to the results |
| ComBat and its limits | matrix adjustment for exploration, ComBat-seq for counts, and the limits of this comparison |
The dataset
Section titled “The dataset”The pasilla dataset, from Brooks et al.
2011, holds RNA-seq counts from Drosophila
melanogaster cells in which the pasilla gene was knocked down by RNA interference. Three
treated samples and four controls. It ships in the Bioconductor pasilla package
together with its sample annotation, and that annotation carries a type column:
three libraries were prepared single-read and four paired-end.
The library type is a batch. It is a processing difference that has nothing to do with
the knockdown, and it is recorded, which is exactly what a batch column should be. The
RNA-seq section computes on the airway dataset, which has no batch
column because its design paired every treatment inside one preparation. pasilla is
the dataset for this section because its batch is real, visible, and partially
confounded with the condition, which is the situation a batch column is usually in.
R only
Section titled “R only”These examples use the R implementations in DESeq2 and sva. They compare the two approaches within one environment, and the pages are R only.
Run an example
Section titled “Run an example”The companion repository is private. Its
batch correction setup instructions
and design table runner
require repository access. This image depends on the older rnaseq:0.4.0 image;
the current RNA-seq recipe builds a newer version. Read the
older image instructions
before the batch image build. Once the section image is available, run
bash guides/batch-correction/what-is-batch/run.sh from the repository root.
It reads the packaged pasilla counts and metadata and writes printed results to
guides/batch-correction/what-is-batch/outputs/page_output_r.txt.
For your own experiment, cross-tabulate condition and batch before choosing a method. The design lesson explains why complete confounding prevents separate estimates. A corrected PCA plot cannot recover a comparison the experiment never observed.
Sources
Section titled “Sources”The DESeq2 vignette documents the pasilla import and multifactor design used throughout this section.
Further reading
Section titled “Further reading”The pasilla preparation vignette describes the source experiment and the sample annotation.