Skip to main content

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 via augur filter. The output feeds directly into M03 alignment.

Input Requirements

Configuration Parameters


Processing Stages

Stage 1 — Pre-filter (qc_prefilter)

Script: scripts/qc_prefilter.py
Rule: qc_prefilter
Environment: envs/nextstrain.yaml
Performs three sequential filters on the raw FASTA:
  1. N-content filter: Sequences exceeding max_n_pct (default 5%) ambiguous bases are discarded. Calculated as count('N') / len(sequence).
  2. MD5 deduplication: Exact-duplicate sequences (identical nucleotide strings) are collapsed to one representative record. Metadata record with the earliest collection date is retained.
  3. Subtype underrepresentation filter: Subtypes with fewer than min_subtype_count total records after N-filtering are removed entirely. This prevents low-sample-count subtypes from introducing spurious long branches in tree inference.
Outputs:
  • results/{BUILD}/m02/prefiltered_sequences.fasta — Filtered FASTA
  • results/{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_filter
Environment: 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.
Mode B — Focal + Contextual subsampling: Used when 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.
The wrapper script detects which mode is active from the config and constructs the appropriate 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

Key packages: augur, pandas, biopython

Known Limitations & Edge Cases

  • Date-stratified subsampling requires complete dates: augur filter with group_by: "country year month" silently drops sequences where date is missing or only partially known (e.g., 2024). Check qc_report.json and 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_count may remove subtypes that are present only in the focal region. Lower min_subtype_count or disable it for single-country analyses.
  • Global max_sequences cap: The max_sequences limit is applied globally after stratified sampling. If the number of sequences after stratification is already below max_sequences, no additional downsampling occurs.
  • Temporal bias: Heavy bias toward recent sequences is common in GISAID. To counteract, include year in group_by and set sequences_per_group to cap per-year density.