Five thousand cells from eight people are eight replicates, not five thousand. This lesson sums each cell type's counts per donor, tests interferon-stimulated against control monocytes with DESeq2, and shows what a per-cell test gets wrong.
Many cells, few people
Markers and cell types named the clusters in one person's blood. Most experiments ask a different question: does a treatment, or a disease, change gene expression within a cell type? That needs samples from several people in each condition, and a test that respects how many people there really are.
The data here are from Kang et al. 2018. PBMCs from eight people with lupus were split in two: one half was stimulated with interferon-beta (IFN-β), a signalling protein the body releases against viruses, and the other half was left as a control. Cells from all donors were pooled and sequenced together, then assigned back to their donor from their genetic variants. The Bioconductor package muscData provides the counts, with the published cell-type labels.
library(muscData) library(SingleCellExperiment) library(scuttle) library(DESeq2) sce <- Kang18_8vs8() sce table(sce$multiplets) table(sce$ind, sce$stim)
What this does
Kang18_8vs8()downloads the data through ExperimentHub, Bioconductor's store of large datasets on first use, then reads it from a local cache.- The object is a SingleCellExperiment, Bioconductor's container for single-cell data. It is to single cells what the
ddsobject was to bulk samples:counts(sce)gives the matrix andcolData(sce)the table of cell information, sosce$indis one column of it. - The columns that matter:
indis the donor,stimthe condition (ctrl or stim),cellthe published cell type andmultipletsthe doublet call from the genetic variants.
The donor-by-condition table is the design. Every donor appears in both conditions, as every donor in airway gave both a treated and an untreated sample. The number of cells per donor ranges from about 1,300 to over 5,800.
sce <- sce[, sce$multiplets == "singlet" & !is.na(sce$cell)] sce <- sce[rowSums(counts(sce) > 0) >= 10, ] dim(sce) sce$donor <- factor(sce$ind) sce$condition <- relevel(factor(sce$stim), ref = "ctrl") table(sce$cell, sce$condition)
The first line keeps cells called singlets that have a cell-type label: it removes 3,169 doublets, 1,217 ambiguous cells and the few unlabelled ones. The second keeps genes detected in at least 10 cells. The donor becomes a factor, since its codes are numbers but not quantities, and the control is set as the reference level, as untrt was in RNA-seq counts and exploration.
The tempting test, and what is wrong with it
ISG15 is a classic interferon-stimulated gene. A Wilcoxon test of its normalised expression in CD14 monocytes, stimulated against control, is one line:
mono <- sce[, sce$cell == "CD14+ Monocytes"] mono <- logNormCounts(mono) wilcox.test(logcounts(mono)["ISG15", ] ~ mono$condition)$p.value table(mono$condition)
The p-value is so small that R stores it as 0. Here the answer happens to be right, because IFN-β induces ISG15 enormously. The method is still wrong. The test treats 5,385 cells as 5,385 independent replicates, but they came from only eight people. Cells from the same person share that person's genes, age, health and sample handling, so they resemble each other more than cells from different people. Counting them as independent is pseudoreplication: it is like measuring one patient's blood pressure 300 times and calling it a trial of 300 patients. The p-value describes how sure you can be about these particular cells, not about people in general.
Pseudobulk: one sample per donor and cell type
The fix is to return to the level at which the experiment was replicated. For each combination of cell type, donor and condition, add up the raw counts of all its cells. Each sum is a pseudobulk sample: what a bulk RNA-seq experiment on just that cell type from that person would have measured. The tools of Module 4 then apply unchanged.
pb <- aggregateAcrossCells(sce, ids = colData(sce)[, c("cell", "donor", "condition")])
pb
head(colData(pb)[, c("cell", "donor", "condition", "ncells")], 4)
summary(pb$ncells)What this does
aggregateAcrossCells()from scuttle sums the counts of every cell sharing the same values of the three columns given. Eight cell types × eight donors × two conditions gives 128 pseudobulk samples.ncellsrecords how many cells went into each sum. The smallest has 4 cells, the largest 1,484. Sums of very few cells are noisy, a point to remember when a cell type is rare.- In Seurat,
AggregateExpression()does the same job, as the project at the end of this module shows.
Worked example · one pseudobulk value by hand
Take ISG15 in the CD14 monocytes of donor 1015:
stimulated: 671 cells, ISG15 UMIs summed = 86,750 (129.3 per cell)
per-cell ratio = 129.3 ÷ 1.4 ≈ 93, log2 ≈ 6.5
aggregateAcrossCells() gives 779 cells and 1,087 for the control sum
What the answer means. The pseudobulk value is just a sum, which you can check against the cells directly, and the two numbers agree. For this one donor, ISG15 is about 90 times higher after stimulation. The per-cell ratio here is only a rough guide: DESeq2 normalises each pseudobulk sample by its own size factor, which accounts for the different numbers of cells.
Always sum raw counts. Summing log-normalised values, or averaging them, breaks the count model DESeq2 relies on.
pb_mono <- pb[, pb$cell == "CD14+ Monocytes"]
coldata <- as.data.frame(colData(pb_mono)[, c("donor", "condition", "ncells")])
coldata$donor <- droplevels(coldata$donor)
rownames(coldata) <- colnames(pb_mono) <- paste(coldata$donor, coldata$condition, sep = "_")
cts <- counts(pb_mono)
cts <- cts[rowSums(cts >= 10) >= 8, ]
dim(cts)
dds <- DESeqDataSetFromMatrix(cts, coldata, design = ~ donor + condition)
dds <- DESeq(dds)
res <- results(dds, contrast = c("condition", "stim", "ctrl"), alpha = 0.05)
summary(res)
head(res[order(res$padj), ], 4)What this does
- The first block selects the 16 monocyte samples, builds the sample table and gives each sample a readable name such as 1015_ctrl.
droplevels()removes unused factor levels. - The filter keeps genes with at least 10 counts in at least 8 of the 16 samples, the size of one group, the rule used in RNA-seq counts and exploration. 3,707 genes remain.
- The design
~ donor + conditionis the paired design of Differential expression with DESeq2 and Batch effects and design formulas: each donor's stimulated cells are compared with their own control cells, and the condition is last.
The output reads exactly like the airway results. 2,334 genes change at padj < 0.05, almost two-thirds of those tested: IFN-β is a very strong stimulus for monocytes. The top genes include CCL8 and ISG20, well-known interferon-induced genes, with fold changes in the hundreds (log2 of 9.8 is about 900-fold). ISG15 itself has a log2 fold change of 7.7 and padj of 3.9 × 10−84, still overwhelming, but now resting on eight people rather than five thousand cells.
Does it matter? A test with no true effect
With an effect this strong, both methods find it. The difference shows when there is nothing to find. The code below takes only the control monocytes and splits the eight donors into two arbitrary groups of four. No treatment separates the groups, so an honest test should find almost nothing.
grp_a <- c("101", "1015", "1039", "1256")
ctrl_mono <- mono[rownames(cts), mono$condition == "ctrl"]
ctrl_mono$fake <- factor(ifelse(ctrl_mono$donor %in% grp_a, "A", "B"))
table(ctrl_mono$fake)
p_cell <- apply(as.matrix(logcounts(ctrl_mono)), 1, function(x)
wilcox.test(x ~ ctrl_mono$fake)$p.value)
sum(p.adjust(p_cell, "BH") < 0.05)
cd_null <- coldata[coldata$condition == "ctrl", ]
cd_null$fake <- factor(ifelse(cd_null$donor %in% grp_a, "A", "B"))
dds_null <- DESeqDataSetFromMatrix(cts[, rownames(cd_null)], cd_null, design = ~ fake)
dds_null <- DESeq(dds_null, quiet = TRUE)
sum(results(dds_null, alpha = 0.05)$padj < 0.05, na.rm = TRUE)Reading the output
Testing cells, 323 genes "differ" between two groups of people chosen by hand, at a false discovery rate that is supposed to be 5%. They are real differences between these particular donors, in genetics or in health, but they say nothing about any treatment. Testing pseudobulk samples, with four people per group, finds none. That is the cost of pseudoreplication: false discoveries whenever donors differ, which is always. A comparison of patients with healthy controls tested cell by cell would mix disease effects with these person-to-person differences and could not tell them apart.
Two more checks need only small changes to the code above. Dropping the donor from the design, ~ condition, gave 2,315 genes instead of 2,334: here the stimulation is so strong that pairing adds little, though in milder experiments it can matter a great deal. And looping the same pseudobulk analysis over all eight cell types found the most changed genes in the monocytes (2,334 of 3,707 tested) and the fewest in the megakaryocytes, 15 of 211, which had only 260 cells across 16 samples. Rare cell types give small, noisy pseudobulk samples and little power.
Go deeper: mixed models and other options
Pseudobulk throws away the variation between cells of the same person. An alternative keeps every cell and adds the donor as a random effect in a mixed model, which estimates how much cells of one person resemble each other. Comparisons published by Squair et al. 2021 and Crowell et al. 2020 found that pseudobulk methods controlled false discoveries well and performed as well as, or better than, more complex methods, while being fast and simple.
The muscat package, by the authors of muscData, wraps the steps of this lesson, running pseudobulk analysis for every cell type at once with DESeq2 or edgeR. Writing them out by hand first, as here, makes clear what such a package does.
Common mistakes
- Using cells as replicates. The replicate is the person, or the animal, or the culture. Count them before planning any test.
- Summing normalised values. Pseudobulk sums the raw counts; DESeq2 normalises afterwards.
- Ignoring the cell counts. A pseudobulk sample of 4 cells is far noisier than one of 1,000. Consider dropping samples below a minimum, and report
ncells. - Comparing conditions with only one sample each. One stimulated and one control sample, however many cells, cannot separate the treatment from the sample.
The data are from Kang et al. 2018, "Multiplexed droplet single-cell RNA-sequencing using natural genetic variation" (Nature Biotechnology). Squair et al. 2021, "Confronting false discoveries in single-cell differential expression" (Nature Communications), showed that tests treating cells as replicates produce many false discoveries, and Crowell et al. 2020 (Nature Communications) introduced muscat and compared pseudobulk with other approaches. Report the number of donors per group, the minimum cells per pseudobulk sample and the design formula.
Key point
To compare conditions, sum each cell type's raw counts per donor and condition, then analyse the pseudobulk samples with DESeq2 and the design you would use for bulk data. The number of people sets your power, not the number of cells.
Further reading · Module 6Squair et al. 2021: why single-cell tests between conditions need biological replicates. · All reading for this course
Check your understanding
1. An experiment has 3 treated and 3 control mice, with 4,000 cells sequenced from each. How many biological replicates per group are there for a test between conditions?
2. What goes into a pseudobulk sample?
3. Control monocytes from eight donors were split into two arbitrary groups of four. A per-cell Wilcoxon test found 323 genes at FDR 5%; pseudobulk DESeq2 found none. What explains the 323?