How we run differential expression analysis, step by step
This is the background to our worked examples. It explains, in plain words, what each step of a standard RNA-seq analysis does and why it is there. You don't need to read it to use the tool.
The question
Differential expression analysis asks one question about every gene: is this gene more active, or less active, in one group of samples than in another? In our examples the groups are tumor tissue and nearby normal tissue from the same patients.
The answer for each gene comes as two numbers: how big the change is (the fold change), and how sure we can be that it is real (the adjusted p-value). The steps below are how we get from raw data to those two numbers, using a widely used method called DESeq2.
1. Start from read counts
RNA sequencing reads short fragments of the RNA in a sample. Each fragment is matched to the gene it came from, and we count how many fragments each gene got. More fragments means the gene was more active.
We use the raw counts, not adjusted values such as FPKM or TPM. The statistics need to know how many fragments were actually seen: 3 fragments and 3,000 fragments carry very different amounts of certainty, even if both turn into the same percentage. Our examples use counts that NCBI made for every public human dataset with one standard pipeline, so every example is processed the same way.
2. Check that each sample was read deeply enough
Each sample should have millions of fragments. A sample with far fewer than the others gives a blurry picture, like a photo taken in poor light. We plot the total for every sample and say on the page if any looks too low.
3. Check that the labels are right
Samples get mixed up in real labs: two tubes swapped, a sheet copied wrongly. One mix-up can blur the whole result, so we check before trusting the labels.
- A map of the samples (PCA). This squeezes thousands of genes into a two-dimensional picture where similar samples sit close together. Tumors should cluster with tumors and normal tissue with normal tissue.
- A label check. For each sample we ask whether it looks more like the average tumor or the average normal sample. A sample that looks like the other group is flagged.
We never remove a sample silently. If we leave one out, the page says which, why, and how much the answer changes with it put back.
4. Set aside weak genes
Many genes are barely switched on in a tissue and get only a handful of fragments. With so little to go on, no test can tell a real change from chance, and including them makes the correction in step 8 stricter for every other gene.
So we keep a gene only if it has at least 10 fragments in at least as many samples as the smaller group has. This is the rule suggested in the DESeq2 guide. It is decided before any comparison is made, so it cannot favour particular results.
5. Compare within each patient
People differ: age, sex, genetics, other illnesses. Those differences show up in gene activity and can hide the tumor effect. When the same patient gave both a tumor and a normal sample, we compare each tumor with that patient's own normal tissue. This is called a paired design. It works like weighing yourself on the same scale before and after: differences between scales stop mattering.
6. Even out sequencing depth
If one sample was sequenced twice as deeply, every gene in it gets roughly twice the fragments. That isn't biology. DESeq2 works out a scaling factor for each sample from the genes that are typical across samples, and uses it so samples are compared on equal terms. This is called normalisation.
7. Measure how much each gene naturally varies
Some genes vary a lot from person to person even in healthy tissue; others are steady. A twofold change means more for a steady gene than for a jumpy one. DESeq2 estimates this natural spread for each gene, and lets genes with similar activity levels "share information", which keeps estimates stable when there are few samples.
8. Test every gene, then correct for testing thousands
For each gene DESeq2 calculates a p-value: the chance of seeing a change this big if the gene really hadn't changed. But we test around 20,000 genes. At a cutoff of 0.05, about 1,000 genes would pass by luck alone.
So we use the adjusted p-value (Benjamini-Hochberg). Among genes with an adjusted p-value below 0.05, about 5% are expected to be false alarms, however many genes were tested. Our worked examples call a gene "changed" when its adjusted p-value is below 0.05 and it at least doubled or halved.
9. Shrink unreliable fold changes
A gene seen 2 times in one group and 16 times in the other has an eightfold change on paper, but it rests on very few fragments. If we plot it as is, such genes crowd the edges of the volcano plot and look more exciting than they are.
We apply fold-change shrinkage (the apeglm method): fold changes backed by little evidence are pulled towards zero, while well-supported ones barely move. Shrinkage changes the size of the fold change only, not the p-values. Our tables include the shrunken value, used for the plots, and the original next to it.
10. Record everything
A result is only trustworthy if someone else can repeat it. For every example we publish:
- the full results table for every tested gene, not just the significant ones;
- the quality plots, the sample list and the list of any excluded samples with reasons;
- the exact software versions and a fixed copy of the software environment;
- checksums of the downloaded files, so you can confirm you start from the same data.
What this kind of analysis can't tell you
- "Normal" tissue next to a tumor isn't fully healthy. It may already carry early changes, which can make some differences look smaller than they are.
- A tumor sample is a mix of cells. Tumor cells, immune cells and supporting tissue are all in there. A gene can look "up in tumors" because more immune cells were present, not because cancer cells switched it on.
- Change isn't cause. A gene that is more active in tumors may drive the cancer, respond to it, or just come along for the ride.
- These are teaching examples, not medical advice. Nothing here should guide anyone's diagnosis or treatment.
What comes next
A results table is the start, not the end. The usual next steps are a volcano plot to see the overall picture, then pathway enrichment to find what the changed genes have in common.
See it on real data. Each worked example opens its full results in the DE Results tool, so you can explore the volcano plot and pathways yourself.
See the worked examples