Repository navigation
09 Differential Expression
Correcting counts and then running a standard test is one way to deal with
ambient RNA in differential expression. Decant offers a second way:
ambient_de() keeps the raw counts and models each sample's soup inside the
test.
Suppose disease samples carry more ambient RNA than control samples, and that ambient RNA is rich in the disease genes of an abundant cell type, A. A pseudobulk test on a rare cell type, R, sees those genes rise in R's disease samples and reports them as differentially expressed in R. They are not. Their rise is entirely due to the soup.
For each gene g and sample s, ambient_de() fits
counts[g, s] ~ NegativeBinomial( native expression[g, s] + rho[s] × total[s] × soup[g, s] )
- The native expression term depends on the design (for example control versus disease) and is what is tested.
- The ambient term is measured:
soupfrom the sample's own empty droplets andrhoestimated from the data. It is added to the mean, not subtracted from the counts, and its uncertainty is carried into the test. - The test is a quasi-likelihood F-test, as in edgeR.
library(Decant)
st <- simulate_ambient_study(seed = 3, G = 600, n_cells = 500)
table(st$cond)
#>
#> ctrl dis
#> 6 6-
simulate_ambient_study()creates 6 control and 6 disease samples. Cell type A is abundant and has 80 disease genes; cell type R is rare and has 40 of its own. Disease samples carry more ambient RNA than controls.
is_R <- st$label == "R"
samples <- sort(unique(st$sample))
Y <- vapply(samples, function(s)
rowSums(st$X[, is_R & st$sample == s, drop = FALSE]), numeric(nrow(st$X)))
rownames(Y) <- rownames(st$X)
dim(Y)
#> [1] 600 12-
is_Rselects the cells of the rare type. -
vapply()sums those cells' counts within each sample, giving one column per sample: the pseudobulk matrixY, genes × samples.
design <- model.matrix(~ cond, data = data.frame(cond = st$cond))
res <- ambient_de(Y, st$empties, design)
head(res[, c("gene", "logFC", "FDR", "ambient_frac", "naive_FDR", "ambient_driven")], 3)
#> gene logFC FDR ambient_frac naive_FDR ambient_driven
#> 117 g218 1.461912 1.129595e-07 0.02752255 3.990660e-07 FALSE
#> 173 g309 1.226158 2.978136e-07 0.01134339 1.797587e-06 FALSE
#> 189 g338 1.183623 4.248957e-06 0.01707194 9.899770e-06 FALSE-
designis a standard model matrix with one row per sample. The last column (conddis, disease versus control) is tested by default. -
st$emptiesis a list of empty-droplet matrices, one per sample, in the same order as the columns ofY. - Results are ordered by p-value. The key columns are:
| Column | Meaning |
|---|---|
logFC |
log2 fold change of native expression |
PValue, FDR
|
Contamination-aware p-value and false discovery rate |
ambient_frac |
Average share of the gene's counts that are ambient |
naive_FDR |
FDR of a standard edgeR test on the same pseudobulk |
ambient_driven |
TRUE if the standard test calls the gene and the contamination-aware test does not |
sum(res$ambient_driven)
#> [1] 12- Twelve genes would be reported by a standard pipeline but are explained
by differences in the soup between conditions. These are the calls
ambient_de()protects you from.
head(attr(res, "samples"), 3)
#> sample ambient_frac ambient_frac_imputed soup_umis norm_factor
#> 1 1 0.05692409 FALSE 49848 0.9663427
#> 2 2 0.05808700 FALSE 49966 1.0214589
#> 3 3 0.04450122 FALSE 50234 0.9746253-
ambient_fracis the estimated ambient fraction of the cell type in each sample, andsoup_umisthe number of UMIs the sample's soup rests on. -
ambient_frac_imputedisTRUEfor a sample whose own estimate was implausible (abovemax_rho) and was replaced by the median of the others (see 9.6).
# Requires your own data
res <- DecantDE(obj, cell_type = "Microglia", sample_col = "donor",
formula = ~ diagnosis, raw = raw_paths_by_donor)
subset(res, ambient_driven)-
DecantDE()builds the pseudobulk, reads each sample's empty droplets and callsambient_de(). -
cell_typeis the identity to test (Idents(obj)by default, or a column given incelltype_col). -
sample_colnames the sample of each cell;formulais the sample-level design. Every variable informulamust be constant within a sample. -
rawis a named list with one raw matrix or Cell Ranger path per sample.
| Argument | Default | Purpose |
|---|---|---|
coef |
last column | Design column to test |
robust |
TRUE |
Down-weight outlier samples gene by gene; important in large cohorts |
lfc |
0 |
Test against a minimum fold change, for example log2(1.1)
|
max_ambient_frac |
0.75 |
Skip genes whose counts are mostly ambient; they are listed in attr(res, "ambient_dominated")
|
naive |
TRUE |
Also run the standard test, to fill naive_FDR and ambient_driven
|
joint_rho |
TRUE |
Refine each sample's ambient fraction on genes absent from all samples pooled. Leave it on: without it, the ambient fraction of a single cell type can be wildly wrong |
max_rho |
0.5 |
A sample whose ambient fraction comes out above this takes the median of the other samples, with a warning |
dispersion |
"trended" |
NB dispersion in the fit. "tagwise" was the earlier default and is not calibrated on real data (9.6) |
-
ambient_de()is experimental. With condition labels shuffled between donors, so that there is nothing to find, on three real datasets (two brain, one pancreas; 168 tests) it reported a gene in 20 tests, never more than 9 genes; naive edgeR in 8. Earlier versions did far worse (up to 2,300 genes) and analyses made with them should be rerun. That it removes ambient-driven hits a standard test reports is shown only in simulation; a pre-registered real-data test was null, because the standard test found none. Report its hits together with a standard pseudobulk test, and check your own data the same way: shuffle the condition labels between samples and count the hits. - If
ambient_de()warns that a sample's ambient fraction is implausible, that sample's pseudobulk looks too much like the soup to measure its contamination (often a cell type close to the dominant one, or mislabelled cells). Its value is replaced by the median of the others. If most samples are flagged, the results for that cell type are unreliable. - With very few empty droplets per sample (a few hundred), the soup is uncertain and some leakage returns.
- With three samples per group, power is lower than with six.
- Correcting counts with a good tool and then testing performs
similarly on the same simulations;
ambient_de()has the advantage when the design includes covariates such as batch.
Previous: Chapter 8, Multi-Sample Experiments | Next: Chapter 10, Splice-Aware and Genotype Modules
Decant user guide · Repository · Report an issue · MIT License
Decant User Guide
- Preface
- 1. Installation
- 2. Key Concepts
- 3. Quick Start
- 4. Preparing Your Data
- 5. Running Decant
- 6. Seurat Integration
- 7. Estimation and Correction
- 8. Multi-Sample Experiments
- 9. Differential Expression
- 10. Splice-Aware and Genotype Modules
- 11. Diagnostics and Troubleshooting
- 12. Validation and Benchmarks
- 13. Function Reference
- 14. Cell-Cell Communication