How AmpliTrim works
It computes what it can compute exactly, and measures what it cannot.
This page shows the design one step at a time. The pictures are schematic: they explain the idea and are not drawn from your data.
The idea
DADA2 does three things to your reads, in this order. AmpliTrim treats each one differently.
- Replicated exactly
Filter and trim
AmpliTrim applies the same rules as
filterAndTrim: cut each read at the chosen length, drop reads that have a base of quality 2 or below, or any N, in the part you keep, and drop reads over the expected-error limit (maxEE). A read's expected errors are the sum, over the bases you keep, of the chance that each base is wrong,10^(-Q/10)for a base of Phred quality Q (the formulas are in step 6). The share that passes is computed, not guessed. - Not modelled
Denoise
Denoising (
dada) is DADA2's most expensive step, and a quick test cannot reproduce it. This is why AmpliTrim's yield is an estimate, and an optimistic one. - Measured on raw reads
Merge pairs
DADA2's
mergePairsworks on denoised reads. AmpliTrim merges your trimmed reads with vsearch instead, at the minimum overlap (default 12, DADA2's own), so you see how many pairs really merge.
What the cut does
A forward and a reverse read each start at one end of the amplicon, the stretch of DNA that was amplified. truncLenF and truncLenR say where to cut each read. Together they have to be at least as long as the amplicon plus the minimum overlap (12 by default), so that the reads overlap, and no longer than the quality allows.
forward readreverse readoverlapnoisy end
Too short
Schematic, not your data. The reads stop before they meet. There is a gap, so they cannot merge.
Just enough
Schematic, not your data. The reads overlap by at least the minimum overlap (12 nt by default). They merge.
Too long
Schematic, not your data. They overlap, but the last bases of each read are noisy. More reads fail the quality filter, and you lose them.
AmpliTrim looks for the shortest cut that still lets your longest amplicons merge, and splits it between the two reads where the quality allows.
Step by step
AmpliTrim runs these steps on a sample of your reads.
Take a sample of your reads
AmpliTrim takes every Nth read pair across all your samples, up to 50,000 pairs, and uses the same pairs for everything below. The sample is the same every time you run it.
In the code:
build_subsampleSchematic, not your data. Measure your amplicons
It merges the full-length reads with vsearch. The lengths of the merged reads are your amplicon lengths, so you do not need to look them up.
Only pairs that overlap at full length can be seen. If fewer than 100 pairs do, the run stops with a message that says so.
In the code:
estimate_insert_sizesSchematic, not your data. Set the floor
AmpliTrim leaves out the longest 0.2% of the amplicons and adds the minimum overlap: 12 by default, DADA2's own, or the value of
--min-overlap(12 to 20). The result is the shortest total cut length that can merge the rest, and AmpliTrim never tests anything shorter.In the code:
coverage_floorSchematic, not your data. Try cuts above the floor
From the floor up to the full read length, in steps of 2 nt, AmpliTrim asks the quality table for the best split between the forward and reverse reads. That table holds the share of pairs that pass DADA2's filter at every cut.
It then filters the reads at that cut and merges them with vsearch. The share that passes times the share that merges is the yield. The search stops when a longer cut gains less than 1 point.
In the code:
_search,pass_table,run_vsearchSchematic, not your data. Pick the cut
Cuts whose yield is within 1 point of the best are treated as tied. Among them, AmpliTrim picks the one with the least overlap, which means the shortest reads and the fewest noisy bases. A cut that cannot merge your longest amplicons is never picked.
In the code:
select_recommendationSchematic, not your data. Set maxEE
At the chosen cut, for each read, AmpliTrim finds the limit that covers three quarters of the reads: the 75th percentile of their expected errors, plus 1. It is never below 2, DADA2's default. There is no upper limit: the report notes it when a limit goes above 5.
In symbols. The expected errors of a read cut at length L are the sum, over its first L bases, of the chance that each base is wrong:
EE = sum of 10^(-Q/10), where Q is the Phred quality of the base. For each read direction, over the reads that reach the cut:maxEE = max(2, int(P75 of EE) + 1), where P75 is the 75th percentile andintdrops the decimals. For example, a 75th percentile of 3.4 gives int(3.4) + 1 = 4, and one of 0.6 gives int(0.6) + 1 = 1, which is below 2, so the limit is 2.If the limit is not the default for both reads, the search and the pick are repeated with it.
In the code:
_rule_max_eeSchematic, not your data. Write the report
You get
REPORT.md(the settings, copy-paste snippets for DADA2 and QIIME 2, what to expect, and warnings),summary.json(the same result for scripts) andsummary.png(a figure).In the code:
write_outputsSchematic, not your data. With
--itsITS amplicons vary a lot in length, so DADA2's ITS workflow does not truncate. AmpliTrim evaluates exactly that: each read is cut at its first base of quality 2 or below, then kept if it is long enough, free of N and within
maxEE.The floor and the search are skipped. The
maxEErule is measured on each read after this cut, with the same percentile and rounding. When fewer than 100% of the pairs pass atmaxEE2,2, the report advises trimming the poor read ends first (amplitrim trim: window 4, mean quality 15) and predicts the effect, andmaxEEstays 2 for the trimmed reads. The report also shows where the pairs go.In the code:
_run_its,_run_its_rulesSchematic, not your data.
Why these choices
Every choice is listed with how well it held up in our tests. Some are design choices with no test behind them, and we say which.
| Choice | Why | How it held up |
|---|---|---|
| Replicate DADA2's quality filter | The share of pairs that pass is then computed, not guessed. | Held The predicted pass rate was within 0.8 points of DADA2's in every test dataset. |
| Measure merging with real merges, at the minimum overlap (default 12, DADA2's own) | Merging depends on the real overlaps and mismatches in your reads, which arithmetic cannot know. | Held With these cuts, DADA2 merged as many pairs as with the other tool's cuts: a tie. |
| Find the amplicon length from your reads | You do not have to look it up, and it is right for your data. | Design choice Only pairs that overlap at full length are seen, so the longest amplicons are under-represented. |
| Use a sample of at most 50,000 pairs | The run time and the memory use stay bounded, however large your dataset is. | Timed The bound is by design. The released version 0.2.0 ran in 29 to 141 seconds and used at most 352 MB on 12 datasets (register section 30). |
| Count merges with a tolerant setting for the yield | A strict count tracked DADA2 less well in our tests. | Optimistic The yield is an estimate made before DADA2 denoises the reads. Use it to compare settings, and run DADA2 once to confirm. On ITS it can be far too high: DADA2 merged 46.9% where 72.4% was estimated and 14.0% where 82.1% was estimated, and on two of four independent gut datasets it overshot by 6 to 20 points. |
| Break ties by the least overlap | Shorter reads mean fewer noisy bases. | Design choice Cuts within the tolerance of the best are equivalent on yield, so this is a matter of preference. |
Set maxEE to cover three quarters of the reads, never below 2 | Reads with noisy ends fail DADA2's default limit, and a looser limit can recover them. | Sensible default, independently tested in part It follows DADA2's author: keep maxEE 2 unless your reads need more, and relax it somewhat when they do. The 75th percentile is our own choice, made after seeing the validation data (the author gives no ceiling, so the rule has none; the report notes a limit above 5), and the rule did not reach the result we had decided in advance would make us adopt it. An independent test by a collaborator on two gut datasets where it relaxed was favourable (more pairs merged, community profiles unchanged). We keep it as a trade-off that we state openly. |
| Offer few options | Three required arguments, --its and --verbose leave little room to misuse it. | Design choice Everything else is chosen for you, including |
The full results, including what did not hold, are on the validation page. The user guide explains how maxEE is chosen.
What AmpliTrim does not do
- It does not denoise. The yield is measured before DADA2 denoises the reads, so DADA2 can keep fewer pairs.
- It checks quality and mergeability, not accuracy.
- It does not recommend settings for other denoisers, such as Deblur.
- It cannot help when your reads do not overlap. If your amplicons are longer than your two reads can span, no cut can merge them.
Where things are in the code
The package is nine modules. The last column shows which others each one uses.
| Module | What it does | Uses |
|---|---|---|
cli.py | The command line: reads the arguments, runs the pipeline, prints the summary and writes the report. | api, pipeline, report, trim |
api.py | The programmatic entry point, recommend(): runs the pipeline, writes the report and returns the summary. The command line calls it. | pipeline, report |
config.py | Defaults that mirror the DADA2 call you will run (minimum overlap, mismatches, maxEE), and how a maxEE value is read. | nothing else in the package |
subsample.py | Finds the read pairs and takes the shared, repeatable sample. | nothing else in the package |
trimmer.py | Holds the sample in memory and replicates DADA2's filter: the quality table, filtering at a cut, and the error counts. | config, subsample |
trim.py | amplitrim trim: cuts the poor ends of ITS reads before the first window of 4 bases whose mean quality is below 15, the cut tested in the validation. | nothing else in the package |
merge_wrapper.py | Runs vsearch to merge reads, and reads its log. | nothing else in the package |
ranking.py | Defines a candidate cut, the floor, and the rule that picks the recommendation. | config |
pipeline.py | The whole run: the steps in order, the maxEE rule, the ITS mode with its trim advice, and the warnings. | config, merge_wrapper, ranking, subsample, trim, trimmer |
report.py | Writes REPORT.md, summary.json and summary.png, and the summary for the terminal. | config, pipeline, ranking |
If you want to change something
| To change | Look in |
|---|---|
| A default, such as the minimum overlap or the share of long amplicons set aside | config.py, and the constants at the top of subsample.py and pipeline.py |
| How reads are filtered | trimmer.py |
| How the best cut is chosen | ranking.py (select_recommendation) |
How maxEE is set | pipeline.py (_rule_max_ee) |
| What the report says | report.py |
Contributions are welcome: see CONTRIBUTING.md.