A simulation study of negative controls, DNA quantification and cross-contamination
Author
Joan Gordó Guardia
Published
November 18, 2026
Show code
library(ggplot2)library(dplyr)library(tidyr)library(knitr)root <-normalizePath("..") # Quarto runs chunks from analysis/for (f inlist.files(file.path(root, "R"), full.names =TRUE)) source(f)theme_set(theme_minimal(base_size =12))sim_file <-file.path(root, "analysis", "results", "simulation_results.rds")if (!file.exists(sim_file)) {stop("Run `Rscript analysis/run_simulation.R` from the project root first.")}sim <-readRDS(sim_file)res <- sim$results |>mutate(label =ifelse(is.na(threshold), method, paste0(method, " (t = ", threshold, ")")),quant =factor(ifelse(conc_noise ==0.1, "Precise quantification","Imprecise quantification"),levels =c("Precise quantification", "Imprecise quantification")),biomass =factor(paste0("Biomass ratio ", biomass_ratio),levels =paste0("Biomass ratio ", c(100, 10, 1))),leakage =factor(ifelse(leak ==0, "Clean blanks (no leakage)","Realistic blanks (0.5% leakage)"),levels =c("Clean blanks (no leakage)","Realistic blanks (0.5% leakage)")) )# Mean and 95% interval over simulated studiessumm <-function(df, ...) { df |>group_by(...) |>summarise(across(c(contam_reads_removed, true_reads_lost, true_taxa_lost, sensitivity),list(mean = mean,lo =~mean(.x) -1.96*sd(.x) /sqrt(n()),hi =~mean(.x) +1.96*sd(.x) /sqrt(n()))),n =n(), .groups ="drop")}# Blank composition in the real data, used to calibrate leakagereal <-load_dataset(file.path(root, "data"))blank_mock_pct <-100*sum(real$counts["Blank", real$taxonomy$expected]) /sum(real$counts["Blank", ])
Questions the mock community could not answer
Part 1 scored decontam against a mock community with known composition. That dataset has three limitations that matter for study design:
One negative control. The prevalence method could not be judged.
Nine abundant genuine taxa, present in every sample. Real clinical samples have many rare taxa that vary between patients, which is exactly where false removals happen.
One quantification method. The frequency method depends on how well DNA concentration is measured, and that cannot be varied in a fixed dataset.
Simulation lets us control all three and ask: for a given design, which method and threshold remove the most contamination without removing real biology?
Simulation design
Each simulated study has 40 true samples plus negative controls. The generative model (R/simulate.R) follows the mechanism decontam is built on:
Genuine community. 150 taxa with skewed abundances. Each patient carries each taxon with a taxon-specific probability (30–100%), and abundances vary between patients.
Reagent contamination. 100 contaminant taxa added in roughly the same absolute amount to every tube, each reaching a given tube only sometimes.
Biomass. Sample DNA varies log-normally across samples; its median, as a multiple of the contaminant DNA, sets how contaminated the study is.
DNA quantification. Measured concentration = true total DNA × log-normal error (SD on the log scale 0.1 = precise, 0.5 = imprecise).
Cross-contamination. Each blank receives a fraction of its reads from two neighbouring samples. In the real blank of Part 1, 1.2% of reads were mock-community reads, so a 0.5% leakage is, if anything, conservative.
Sequencing. About 30,000 reads per sample, half that for blanks.
That gives 48 scenarios × 20 simulated studies. Every study is scored with decontam’s frequency, prevalence, combined and “either” methods at thresholds 0.1, 0.25 and 0.5, plus the two simple filters from Part 1. Performance is measured on taxa seen in at least one true sample, as in Part 1:
Contamination removed: share of contaminant reads in true samples that are removed.
Real signal lost: share of genuine reads removed, and number of genuine taxa removed (out of 150).
Figure 1: Sanity check: in one simulated study per biomass level, the contaminant share of each sample falls as its measured DNA concentration rises, the same pattern seen in the real dilution series.
Result 1. The frequency method is only as good as the DNA measurement
The frequency method does not use the negative controls at all, so what drives it is the quality of the concentration it is given.
Figure 2: Frequency method, realistic blanks, all numbers of controls pooled. Points are means over simulated studies with 95% intervals.
At the default threshold and in the most contaminated studies, the method removes 75% of the contamination when DNA is measured precisely, but only 7% when the measurement is noisy. The samples that need cleaning most are the ones with the least DNA, which is also where imprecise instruments are at their worst. Better quantification is worth more than any choice of method or threshold.
Result 2. The threshold is a trade-off that the mock community hid
Figure 3: Operating characteristics under realistic blanks and precise quantification, averaged over all biomass levels and numbers of controls. Each point is a method-threshold pair; up and to the left is better.
In Part 1, raising the frequency threshold to 0.5 cost nothing, because every genuine taxon was abundant and present in every sample. With realistic communities it costs about 25 genuine taxa per study (3.0% of genuine reads): rare taxa seen in a few samples can show a negative relationship with DNA concentration by chance. A threshold of 0.25 is a good compromise here: 91% of the contamination removed for 2.6 genuine taxa lost, against 84% and 0.6 at the default 0.1.
Result 3. Prevalence needs many clean controls, and controls are rarely clean
Figure 4: Prevalence and combined methods (t = 0.25) by number of negative controls, precise quantification, all biomass levels pooled.
With clean blanks, adding controls steadily improves the prevalence method and costs nothing. With realistic blanks the picture reverses: abundant genuine taxa leak into the controls, look “more prevalent in blanks than in patients” when they are not carried by every patient, and get removed. With 8 controls and leakage, prevalence at t = 0.25 removed 32% of genuine reads, against 0.0% with clean blanks. More controls do not fix this, because each extra control is another chance to catch leaked DNA.
The practical consequence is that negative controls should be placed away from high-biomass samples on the plate, and that prevalence-based results should be checked for abundant taxa being removed.
Result 4. The simple filters
Show code
sf <- res |>filter(leak >0, conc_noise ==0.1, method %in%c("in negative control", "abundance >1%")) |>summ(method)sf |>transmute(Method = method,`Contamination removed (%)`= contam_reads_removed_mean,`Genuine reads lost (%)`= true_reads_lost_mean,`Genuine taxa lost (of 150)`= true_taxa_lost_mean) |>kable(digits =1)
Method
Contamination removed (%)
Genuine reads lost (%)
Genuine taxa lost (of 150)
abundance >1%
37.8
1.4
51.7
in negative control
91.8
79.8
39.4
Removing everything seen in a blank looks thorough but throws away most of the real signal once blanks contain any leaked DNA, which confirms the Part 1 result on a much larger scale. The abundance filter keeps the dominant genuine taxa but discards dozens of rare ones, and leaves most contamination in the very-low-biomass studies, where contaminants are themselves abundant.
It encodes decontam’s own assumptions (constant contaminant DNA per tube), so it is a best case for the frequency method. Contamination that scales with sample handling would weaken it.
No taxon is both genuine and a contaminant. In practice some genera (e.g. skin or environmental bacteria) can be both.
One batch. decontam can score batches separately; batch effects in contamination were not simulated.
Leakage structure is an assumption. Two neighbours per blank and a fixed rate; the qualitative conclusion (leakage harms prevalence) is robust, the exact numbers are not.
Only decontam and simple filters are compared. Methods that model contamination sources and well-to-well leakage explicitly, such as SCRuB (Austin et al., 2023, Nature Biotechnology 41: 1820–1828, https://doi.org/10.1038/s41587-023-01696-w), are designed for exactly the leaky-control scenarios where prevalence fails here, and are the natural next comparison.