LSMA

LONDON SCHOOL OF MULTIOMICS & AI

LSMA

LONDON SCHOOL OF MULTIOMICS & AI

Free course

Free course

0 of 79 lessons

Calling germline variants: from BAM to VCF

Calling germline variants: from BAM to VCF

Calling germline variants: from BAM to VCF

Variant calling reads the stack of aligned reads at each position and decides the genotype. Align DNA reads, mark duplicates, call and filter variants with bcftools, and learn how pipelines are checked against benchmark samples.

In Finishing and sharing a genome you completed and released a genome of your own. This module now turns from building genomes to reading variation against one: given a good reference, how does one individual's DNA differ from it?

From reads to a list of differences

A variant is a position where a sample's DNA differs from the reference genome. The commonest kind is a single-nucleotide variant (SNV), one base swapped for another. Next come short insertions and deletions (indels) of a few bases. Larger changes, such as deletions of thousands of bases or rearranged chromosome segments, are called structural variants and need different methods; this lesson deals with SNVs and short indels, together called small variants.

Germline variants are inherited and present in every cell of the body, as you saw in Beyond RNA-seq: other assays and pipelines. Humans are diploid: each chromosome comes in two copies, one from each parent. So at any position a person can carry the reference base on both copies (homozygous reference), the variant on one copy (heterozygous), or the variant on both (homozygous alternate). Deciding which of the three applies, at every position, is called genotyping, and it is the heart of variant calling.

A typical human genome differs from the reference at roughly four to five million positions, nearly all of them common, harmless variants shared with many other people. Variant calling therefore produces a long list, and most later work is about filtering and interpreting it, as in Variants: what a change in sequence does, and how it is annotated.

The path has four steps. Reads are aligned to the reference with a DNA aligner, duplicate reads are marked, a caller looks at the stack of reads over each position and decides the genotype, and the calls are filtered and checked. The output is a VCF (Variant Call Format) file, the format you met in File formats you will meet: FASTA, GenBank, GFF, VCF, PDB.

Calling germline variants: from BAM to VCF · LSMA free course Reads stacked under a reference. At the first marked position about half the reads show a different base, which is called as a heterozygous variant. At the second, a single read differs, which is treated as a sequencing error. READS STACKED OVER THE REFERENCE reference 3 of 6 reads differ: heterozygous1 of 5 differs: likely error
Navy bars are reads aligned under the grey reference. Vermilion marks a base that differs from the reference in about half the reads, the pattern of a heterozygous variant; peach marks a lone difference, more likely a sequencing error. Schematic, not to scale.

Align, mark duplicates, call

The tools below are standard and free. The commands use placeholder names, ref.fa for the reference and sample_R1.fastq.gz and sample_R2.fastq.gz for trimmed paired reads; on real data, start small, for example with reads from one chromosome region.

Terminal · once
conda create -n variants -c conda-forge -c bioconda bwa samtools bcftools
conda activate variants
bwa index ref.fa
samtools faidx ref.fa
Terminal
bwa mem -t 4 -R '@RG\tID:run1\tSM:sample1' ref.fa \
        sample_R1.fastq.gz sample_R2.fastq.gz \
  | samtools fixmate -m - - \
  | samtools sort -o sample.sorted.bam
samtools markdup sample.sorted.bam sample.md.bam
samtools index sample.md.bam

bcftools mpileup -f ref.fa -a AD,DP sample.md.bam \
  | bcftools call -m -v -Oz -o sample.vcf.gz
bcftools index sample.vcf.gz

What this does

  • bwa index and samtools faidx build two indexes of the reference, once: one for the aligner and one that lets other tools fetch any stretch of sequence quickly.
  • bwa mem is a DNA aligner. Unlike HISAT2 in Aligning reads to a genome, it does not expect introns, because DNA reads match one continuous stretch of genome. -R adds a read group, a header line naming the run and the sample (SM); callers use the sample name in the VCF, and some refuse to run without it.
  • samtools fixmate -m adds information about each read's mate, which duplicate marking needs. It works here because bwa mem writes the two reads of a pair next to each other.
  • samtools markdup flags reads that are duplicates, as described in Beyond RNA-seq: other assays and pipelines. For variant calling this matters: one fragment copied ten times by PCR must not look like ten independent reads supporting a variant.
  • bcftools mpileup walks along the genome and, at each position, summarises the bases and qualities of all reads covering it. -a AD,DP asks it to keep the depth per allele and the total depth for each sample.
  • bcftools call -m -v turns that summary into genotypes with its multiallelic model (-m) and writes only the variant positions (-v). -Oz writes compressed VCF, which bcftools index then indexes.

What you will see

The run writes sample.vcf.gz. bcftools view -H sample.vcf.gz | head shows the first variant lines without the header, one variant per line. How many variants there are depends on the region and the sample; for a human sample, expect roughly one variant every thousand bases or so.

Reading a VCF and judging a call

A VCF line has eight fixed columns, followed by a FORMAT column and one column per sample. The fixed columns are the chromosome, the position, an ID (often .), the reference allele (REF), the alternate allele (ALT), QUAL, FILTER and INFO. The header lines starting with ## define every tag used, so a VCF documents itself.

FieldWhereWhat it means
QUALcolumn 6Phred-scaled confidence that the site is variable at all
FILTERcolumn 7PASS, or the name of each filter the call failed
GTsample columnGenotype: 0/0 reference, 0/1 heterozygous, 1/1 homozygous alternate
DPINFO or sampleRead depth at the position
ADsample columnReads supporting each allele, reference first
PLsample columnPhred-scaled likelihood of each genotype, the best set to 0
GQsample columnPhred-scaled confidence in the chosen genotype

How to read this table

The first two rows describe the site; the rest describe the sample's genotype at it. In the sample column, the values appear in the order listed in FORMAT, separated by colons, for example GT:PL:DP:AD followed by 0/1:120,0,160:20:11,9. Phred-scaled means the same scale as base qualities in From sample to reads: 20 is a 1 in 100 chance of being wrong, 30 a 1 in 1,000. QUAL and GQ answer different questions: a site can be clearly variable (high QUAL) while it is unclear whether the sample carries one copy or two (low GQ). bcftools reports PL by default and GQ only when asked; GATK and DeepVariant report both.

A slash in the genotype, 0/1, means the order of the two copies is unknown. A bar, 0|1, means the call is phased: it is known which parental copy carries the variant, which long reads or family data can provide.

Worked example · choosing a genotype from 20 reads

20 reads: 11 show the reference base, 9 the alternate · error rate 1%
likelihood if 0/0: 9 errors and 11 correct ≈ 1.5 × 10−13 · if 0/1: about 0.16 · if 1/1: ≈ 1.5 × 10−17
PL = 120, 0, 160 → genotype 0/1, GQ = 120

Step by step. Each genotype predicts a share of alternate reads. If the sample is 0/0, an alternate base can only be an error, 1% of the time, so 9 such errors out of 20 has probability C(20,9) × 0.019 × 0.9911; C(20,9), the number of ways to choose 9 reads of 20, is 167,960, and the product is about 1.5 × 10−13. If it is 0/1, each read comes from either copy with chance one half, so the probability is 167,960 × 0.520 = 167,960 ÷ 1,048,576 ≈ 0.16. If it is 1/1, the 11 reference reads must all be errors: 167,960 × 0.999 × 0.0111 ≈ 1.5 × 10−17.

What the answer means. Heterozygous explains the reads far better than either alternative. On the Phred scale, relative to the best genotype, 0/0 is −10 × log10(1.5 × 10−13 ÷ 0.16) ≈ 120 and 1/1 is about 160, which gives PL = 120,0,160. GQ is the gap to the second-best genotype, 120; many tools cap it at 99. Real callers also use each base's quality, the mapping quality and, in GATK and DeepVariant, a local re-assembly of the reads, but the logic is the same.

Filtering and normalising

Raw calls include false positives, usually in places where reads align poorly: repeats, regions with too few or far too many reads, and the ends of reads. A first filter marks low-confidence calls rather than deleting them, so the decision stays visible:

Terminal
bcftools filter -e 'QUAL<20 || INFO/DP<10' -s LowQual \
        -Oz -o sample.filt.vcf.gz sample.vcf.gz
bcftools norm -f ref.fa -m -any -Oz -o sample.norm.vcf.gz sample.filt.vcf.gz
bcftools stats sample.norm.vcf.gz > sample.stats.txt

What this does

  • bcftools filter -e picks out calls to exclude, here those with QUAL below 20 or a depth below 10, and -s LowQual writes that name in their FILTER column instead of removing them. Passing calls get PASS.
  • bcftools norm rewrites variants in a standard form. The same indel inside a repeat, such as one extra A in a run of As, can be written at several positions; normalisation shifts it to the leftmost one and trims shared bases, using the reference given with -f. -m -any splits sites with several alternate alleles into one line each. Without this step, two files can describe the same variant differently and fail to match.
  • bcftools stats writes summary counts, including the numbers of SNVs and indels and the transition/transversion ratio.

The transition/transversion ratio (Ts/Tv) is a quick sanity check. Transitions swap a purine for a purine (A↔G) or a pyrimidine for a pyrimidine (C↔T); transversions swap between the two groups. Real human variants are biased towards transitions, giving a ratio of about 2.0 to 2.1 across the whole genome and higher in exons, whereas random errors give about 0.5. A ratio far below the expected value suggests many false calls.

The thresholds above are only a start. Fixed cut-offs like these, known as hard filters, are easy to explain but crude. Large projects use model-based filtering, or callers whose scores are already well calibrated.

Go deeper: GATK, DeepVariant and why callers re-assemble

bcftools judges each position from the pileup alone. That works well for SNVs, but indels are harder: the aligner places each read independently, so reads crossing the same deletion may be aligned slightly differently, scattering the evidence. GATK HaplotypeCaller handles this by re-assembling the reads in each active region into candidate haplotypes, the sequences of whole stretches of one chromosome copy, and scoring each read against each haplotype before choosing genotypes. This is the same assembly idea you met in Assembly graphs, applied to a few hundred bases at a time.

DeepVariant takes another route. It turns the reads around each candidate site into an image-like table of bases, qualities and strands, and a deep neural network trained on samples with known answers predicts the genotype. It performs very well in benchmarks and adapts to new sequencing technologies by retraining. Both tools write a VCF with the same fields as in the table above.

How good are the calls?

For one sample you cannot know the true variants. For a few reference samples you can. The Genome in a Bottle consortium (GIAB), led by the US National Institute of Standards and Technology, has sequenced a small set of people with many technologies, including HG001 (also known as NA12878) and the son–father–mother trio HG002, HG003 and HG004, and published benchmark sets: variant lists together with the regions where those lists are trusted. Sequencing one of these samples and comparing your calls with the benchmark measures your whole pipeline.

The comparison counts three kinds of result. A true positive is a benchmark variant you called correctly; a false positive is a call that is not in the benchmark; a false negative is a benchmark variant you missed. From these, precision is the share of your calls that are right, TP ÷ (TP + FP), and recall is the share of true variants you found, TP ÷ (TP + FN). Stricter filters raise precision and lower recall, so both are always reported.

Matching variants is less simple than comparing positions, because the same change can be written in different ways, as normalisation showed, and because a nearby pair of variants may be represented as one complex change. The tool hap.py, developed with the Global Alliance for Genomics and Health benchmarking team, compares a query VCF with a truth VCF at the level of haplotypes, restricted to the benchmark's confident regions, and reports precision and recall separately for SNVs and indels. A typical run takes the truth VCF, your VCF, the confident-region BED file with -f, the reference with -r and an output prefix with -o.

Two lessons come from such benchmarks. Modern pipelines call SNVs in the easy parts of the genome with very high precision and recall, but indels and difficult regions, such as segmental duplications and long repeats, remain much harder. And a pipeline's performance depends on the sequencing data it was tuned for, so a pipeline validated on one technology should be re-validated before it is used on another.

BWA-MEM is described by Li (2013, arXiv) and the current samtools and bcftools by Danecek et al. (2021, GigaScience). GATK was introduced by McKenna et al. (2010, Genome Research), and DeepVariant by Poplin et al. (2018, Nature Biotechnology). The Genome in a Bottle benchmarks are described by Zook et al. (2019, Nature Biotechnology) and the benchmarking methods behind hap.py by Krusche et al. (2019, Nature Biotechnology). Tan, Abecasis and Kang (2015, Bioinformatics) showed why variants must be normalised before they are compared. In methods, report the reference build, every tool version, the filters and, if you benchmarked, the benchmark version and regions.

Common mistakes

  • Skipping duplicate marking, so PCR copies count as independent support for a variant.
  • Leaving out the read group, so the sample name is missing or wrong in the VCF.
  • Comparing two VCFs without normalising them, so the same indel looks like two different variants.
  • Deleting filtered calls instead of marking them, which hides how the final list was made.
  • Quoting precision without recall, or measuring either outside the benchmark's confident regions.

Key point

A variant call is a judgement from the stack of reads, with a confidence attached. Mark duplicates, keep the read group, filter visibly, normalise, and check the pipeline against a benchmark sample before trusting it on your own.

Further reading · Module 5Genome in a Bottle: the reference samples and benchmark sets used to measure variant calling. · bcftools manual: every command and option used in this lesson. · All reading for this course

Check your understanding

1. Why are duplicate reads marked before variant calling?

2. What does the genotype 0/1 mean in a VCF?

3. A pipeline makes 1,000 calls in a benchmark region; 950 are true, and the benchmark has 1,000 variants. What are precision and recall?

Ask LSMA