Module M02: Quality Control & Subsampling
M02 operates on the raw FASTA and enriched metadata from M01 and produces a filtered, balanced sequence set. It executes two serial stages: (1) hard pre-filtering via a custom script, and (2) adaptive spatio-temporal subsampling viaaugur filter. The output feeds directly into M03 alignment.
Input Requirements
Configuration Parameters
Processing Stages
Stage 1 — Pre-filter (qc_prefilter)
Script: scripts/qc_prefilter.pyRule:
qc_prefilterEnvironment:
envs/nextstrain.yaml
Performs three sequential filters on the raw FASTA:
- N-content filter: Sequences exceeding
max_n_pct(default 5%) ambiguous bases are discarded. Calculated ascount('N') / len(sequence). - MD5 deduplication: Exact-duplicate sequences (identical nucleotide strings) are collapsed to one representative record. Metadata record with the earliest collection date is retained.
- Subtype underrepresentation filter: Subtypes with fewer than
min_subtype_counttotal records after N-filtering are removed entirely. This prevents low-sample-count subtypes from introducing spurious long branches in tree inference.
results/{BUILD}/m02/prefiltered_sequences.fasta— Filtered FASTAresults/{BUILD}/m02/qc_report.json— Retention statistics (total input, removed per filter, output count)
Stage 2 — Adaptive Subsampling (augur_filter)
Script: scripts/m02_filter_wrapper.py (Snakemake script: directive — runs as Python)Rule:
augur_filterEnvironment:
envs/nextstrain.yaml
This rule wraps augur filter with adaptive logic that supports two sampling schemes:
Mode A — Global uniform subsampling:
Used when subsampling block contains only group_by and max_sequences. Draws a balanced sample globally across all defined strata.
subsampling.focal and subsampling.contextual blocks are defined. Ensures that the target country/region is fully represented, with a smaller contextual sample from other regions for phylogenetic placement.
augur filter command. If neither focal nor contextual keys are present, it falls back to global mode.
Output:
results/{BUILD}/m02/filtered_sequences.fasta
Outputs
Reading the QC Report
Conda Environment
augur, pandas, biopython
Known Limitations & Edge Cases
- Date-stratified subsampling requires complete dates:
augur filterwithgroup_by: "country year month"silently drops sequences wheredateis missing or only partially known (e.g.,2024). Checkqc_report.jsonand the filter log for the count of sequences excluded due to missing date fields. - Subtype filter vs. focal sampling: When using focal+contextual mode with a narrow focal region, the pre-filter’s
min_subtype_countmay remove subtypes that are present only in the focal region. Lowermin_subtype_countor disable it for single-country analyses. - Global
max_sequencescap: Themax_sequenceslimit is applied globally after stratified sampling. If the number of sequences after stratification is already belowmax_sequences, no additional downsampling occurs. - Temporal bias: Heavy bias toward recent sequences is common in GISAID. To counteract, include
yearingroup_byand setsequences_per_groupto cap per-year density.
