omics.co.in logo omics.co.in

Chapter 5: Step 3 — Post-Alignment Processing: Deduplication & GATK BQSR

Tested Stacks: GATK 4.6.1 Samtools 1.21 Nextflow 24.10 Seurat v5.1 Python 3.12
Prerequisites: Basic Linux CLI & Sequencing Formats
📚 Chapter 5 of 10 0% Course Completed

Chapter 5: Step 3 — Post-Alignment Processing: Deduplication & GATK BQSR

Raw BAM files generated directly by aligners cannot be immediately subjected to variant calling. Library amplification introduces duplicate copies of identical DNA molecules, while sequencers exhibit systematic cycle-dependent quality estimation errors. In this chapter, we master coordinate sorting, PCR and optical duplicate marking, and GATK Base Quality Score Recalibration (BQSR).

Step 3 Technical Specifications
  • Input File: Raw unsorted or coordinate-sorted BAM file.
  • Tools Used: Samtools (sorting and indexing), Picard / GATK MarkDuplicates (optical & PCR duplicate detection), GATK BQSR (BaseRecalibrator & ApplyBQSR).
  • Output File: Sorted, Recalibrated BAM/CRAM file + Index file (.bam.bai / .cram.crai).
  • Clinical Utility: Flags PCR duplicates so that multiple copies of a single initial DNA fragment are not counted as independent evidence. Recalibrates Phred scores against known polymorphic sites to remove sequencer hardware drift.

1. Duplicate Marking: Optical vs PCR Duplicates

During library preparation, PCR amplification cycles can produce thousands of identical copies of the same original genomic fragment. If a mutation arose during PCR Cycle 1, it could be present across 50 duplicate reads, creating a devastating false-positive call.

  • PCR Duplicates: Reads that have the exact same 5' alignment coordinates and orientation for both forward and reverse reads. Picard retains the single read pair with the highest sum of base quality scores and sets the 0x400 bitwise SAM flag on all duplicate copies.
  • Optical Duplicates: Clusters on the flow cell that physically originate from a single cluster that spread into adjacent nanowells. Picard uses pixel distance thresholds to distinguish optical from library duplicates.

2. Base Quality Score Recalibration (BQSR)

Illumina instruments assign Phred quality scores based on physical optical properties. However, real-world accuracy drifts systematically based on:

  • Cycle Bias: Phred scores typically decline toward the 3' end of the read due to phasing/pre-phasing decay.
  • Dinucleotide Context Bias: Errors occur disproportionately after specific motifs (e.g. after GG or CC homopolymers).

GATK BQSR analyzes all aligned bases that do not overlap known polymorphic sites (masking known SNPs in dbSNP and 1000 Genomes), builds a multidimensional empirical error covariate table, and recalculates accurate Phred values.

# Step 3a: Mark Duplicates with GATK MarkDuplicatesSpark (multithreaded)
gatk MarkDuplicatesSpark     -I patient_sorted.bam     -O patient_dedup.bam     -M dedup_metrics.txt     --conf 'spark.executor.cores=8'

# Step 3b: Generate BQSR Recalibration Covariate Table
gatk BaseRecalibrator     -I patient_dedup.bam     -R GRCh38.primary_assembly.fa     --known-sites dbsnp_146.hg38.vcf.gz     --known-sites Mills_and_1000G_gold_standard.indels.hg38.vcf.gz     -O recal_data.table

# Step 3c: Apply Recalibration to Generate Final Analysis-Ready BAM
gatk ApplyBQSR     -I patient_dedup.bam     -R GRCh38.primary_assembly.fa     --bqsr-recal-file recal_data.table     -O patient_recalibrated.bam

# Index the final recalibrated BAM
samtools index patient_recalibrated.bam
⚠️

Common 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 chr1 or 1; divergent naming causes silent alignment drops.
Was this guide helpful to your research?
Help us maintain 100% accurate, peer-reviewed bioinformatics standards.
📝 Propose Edit on GitHub ↗