Lesson 2 of 13 · 12 min
Experimental Design and Replicates
The choices that decide whether an RNA-Seq experiment can answer its question are made before a single read is sequenced. No amount of clever analysis can rescue a design that is underpowered or confounded, because the pipeline can only measure the signal your design lets through. Every decision here feeds directly into the DESeq2 design formula you will write in a later lesson.
Factors and conditions
A factor is a variable you deliberately vary, such as treatment or genotype, and each value it takes is a level, also called a condition, such as control or treated. Differential expression compares the levels of a factor, so you need at least two levels and several independent samples at each level. You record each factor as a column in a sample sheet, where the condition column below holds the control and treated levels, and that sample sheet becomes the colData that DESeq2 turns into terms of the design formula.
sample condition batch
ctrl_1 control A
ctrl_2 control B
ctrl_3 control A
treat_1 treated B
treat_2 treated A
treat_3 treated BBiological vs technical replicates
A biological replicate is an independent biological unit, such as a separate animal or a separately grown and treated culture, while a technical replicate re-measures the same sample, such as one library split across two lanes. Biological replicates capture the biological variation you want to generalize over; technical replicates only capture measurement noise. DESeq2 estimates per-gene dispersion from biological variation, so its p-values are valid across biological replicates and never across technical ones.
Warning: if one library was sequenced on several lanes, sum the per-lane counts into a single sample before analysis; in DESeq2 you can do this with collapseReplicates(). Treating lanes as replicates fakes low variance, shrinks the dispersion estimates, and inflates false positives without adding any real statistical power.
Two biological replicates per condition will run in DESeq2, but they estimate within-group variance so poorly that a single outlier can dominate the outcome. Three is the practical minimum for reliable dispersion estimates, and it also lets the analysis survive dropping one failed library. Beyond roughly 20 to 30 million reads per sample, adding replicates buys far more power than adding depth, because depth lowers technical noise but not biological variance.
Batch effects and confounding
A batch effect is unwanted technical variation tied to how samples were processed, such as extraction day, reagent lot, or sequencing run. It becomes fatal when it is confounded with your factor of interest, meaning the two vary together so no model can separate them; if every control is prepped on Monday and every treated sample on Tuesday, a treatment effect is indistinguishable from a day effect. A balanced design that places each condition in each batch, with samples assigned to batches at random, keeps batch and condition independent so you can adjust for batch instead of being defeated by it.
library(DESeq2)
coldata <- read.table("samples.tsv", header = TRUE, row.names = 1)
coldata$condition <- relevel(factor(coldata$condition), ref = "control")
# nuisance factor first, factor of interest last: DESeq2 tests the last term
dds <- DESeqDataSetFromMatrix(countData = counts,
colData = coldata,
design = ~ batch + condition)converting counts to integer mode
Warning message:
In DESeqDataSet(se, design = design, ignoreRank) :
some variables in design formula are characters, converting to factors