Chapter 3: Step 1 — Quality Control (QC) & Preprocessing
Chapter 3: Step 1 — Quality Control (QC) & Preprocessing
Every clinical diagnostic assay starts with raw binary reads emitted by sequencing platforms. In this chapter, we master the mathematics of Phred quality scores, implement automated quality reporting using FastQC, and deploy high-performance trimming algorithms using FastP and Trimmomatic to eliminate technical artifacts.
- Input File: Raw FASTQ (
.fastq.gz) containing nucleotide strings and ASCII-encoded Phred quality scores. - Tools Used: FastQC (statistical quality reporting), FastP • Trimmomatic (adapter trimming & sliding-window base filtering).
- Output File: Cleaned, quality-filtered FASTQ (
.fastq.gz) ready for aligner ingestion. - Clinical Utility: Evaluates per-base quality decay, base composition, GC biases, and adapter contamination. Trimming eliminates synthetic adapter artifacts and erroneous low-quality base calls ($Q < 20$), preventing downstream false-positive variant calls.
The 4-Line Anatomy of a FASTQ Record
Each sequencing read occupies exactly four lines in a standard FASTQ file:
@A00123:456:H5TY2DSX7:1:1101:1024:1000 1:N:0:GATCGT <- Line 1: Header (Instrument, Run, Flowcell, Tile, X:Y coordinates, Index)
ATGCGATCGATCGTAGCTAGCTAGGCTAGCTAACTAGCTAGCTA <- Line 2: Nucleotide Sequence Call (A, C, G, T, N)
+ <- Line 3: Separator (optional repeat of header)
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF <- Line 4: ASCII Phred Quality Characters (ASCII 33 offset)Phred Quality Score Mathematics
The Phred score ($Q$) is a logarithmic transformation of the estimated base-calling error probability ($P_e$):
| Phred Score ($Q$) | Error Probability ($P_e$) | Base Call Accuracy | ASCII-33 Character | Clinical Interpretation |
|---|---|---|---|---|
| Q10 | 1 in 10 (0.10) | 90.0% | + | Unacceptable. High probability of false-positive call. |
| Q20 | 1 in 100 (0.01) | 99.0% | 5 | Minimum acceptable diagnostic threshold for clinical filtration. |
| Q30 | 1 in 1,000 (0.001) | 99.9% | ? | Benchmark standard for Illumina SBS and PacBio HiFi. |
| Q40 | 1 in 10,000 (0.0001) | 99.99% | I | Ultra-high accuracy (NovaSeq X, Element AVITI, BGI DNBseq). |
Production Preprocessing Pipelines: FastP vs Trimmomatic
In modern high-throughput labs, FastP has largely replaced legacy Java-based tools due to its multithreaded C++ architecture, automatic adapter detection, and built-in poly-G tail removal (crucial for two-color Illumina chemistry where no-signal corresponds to G):
# Modern High-Performance Trimming with FastP
fastp --in1 sample_R1.fastq.gz --in2 sample_R2.fastq.gz --out1 clean_R1.fastq.gz --out2 clean_R2.fastq.gz --detect_adapter_for_pe --trim_poly_g --cut_front --cut_tail --cut_window_size 4 --cut_mean_quality 20 --length_required 50 --thread 16 --html qc_report.html --json qc_metrics.json
# Legacy Trimmomatic Pipeline Execution
trimmomatic PE -threads 16 sample_R1.fastq.gz sample_R2.fastq.gz clean_paired_R1.fq.gz clean_unpaired_R1.fq.gz clean_paired_R2.fq.gz clean_unpaired_R2.fq.gz ILLUMINACLIP:adapters/TruSeq3-PE.fa:2:30:10:2:keepBothReads LEADING:3 TRAILING:3 SLIDINGWINDOW:4:20 MINLEN:50Common Pitfalls & Troubleshooting Checklist
- Java Heap Exhaustion (GATK / Picard): If processes terminate with
java.lang.OutOfMemoryError, set your environment variable explicitly:export _JAVA_OPTIONS="-Xmx16g -Djava.io.tmpdir=/tmp". - Index Timestamp Mismatch: If tools complain that a BAM index is missing or out of date, regenerate with
samtools index -@ 4 sample.bam. - Conda Channel Conflicts: Avoid ABI incompatibilities between bioconda and conda-forge by setting strict priority:
conda config --set channel_priority strict. - Chromosome Naming Contamination: Always verify whether reference FASTA headers use
chr1or1; divergent naming causes silent alignment drops.