Part III · Population Genomics · Step 04

SNP calling

Perform joint variant discovery across samples mapped to the same shared UCE pseudoreference, retain the read-level evidence needed for later genotype filtering, and validate the resulting raw VCF before any population-genomic filtering is applied.

Objective

The mapping stage placed reads from every individual into a common coordinate system. SNP calling now asks a different question: at each homologous position in that shared UCE pseudoreference, what alleles are supported by the aligned reads, and what genotype is most likely for each sample?

This module uses bcftools mpileup to summarize read evidence and calculate genotype likelihoods, followed by bcftools call to infer variant alleles and genotypes jointly across the selected samples.

shared UCE pseudoreference
        +
final marked-duplicate BAMs
        ↓
bcftools mpileup
        ↓
read evidence + genotype likelihoods
        ↓
bcftools call
        ↓
raw joint VCF
        ↓
extract raw SNP records
        ↓
index + validate + summarize
        ↓
variant filtering
Calling is not filtering

The output of this module is intentionally permissive. Low-depth genotypes, sites with substantial missing data, multiallelic SNPs and rare alleles may still be present. They are evaluated in the next module rather than silently discarded during discovery.

1. Why joint SNP calling?

Calling each individual independently and later merging VCF files can produce inconsistent site representation and make genotype comparison unnecessarily difficult. Joint calling evaluates the same candidate variant position across all selected samples at once.

Shared coordinates

Every genotype refers to the same UCE locus and pseudoreference position.

Comparable genotypes

Evidence from all individuals is considered within the same variant record.

Consistent ALT alleles

Alternate alleles are represented consistently across the complete sample set.

One population VCF

Downstream missingness, MAF, PCA and structure workflows begin from one coordinated dataset.

For UCE capture data, this logic is especially important because the reference is not a complete genome. It is a shared collection of homologous UCE sequences, and the population-genomic analysis should therefore use the same pseudoreference for every individual.

2. Inputs

This module assumes that the previous steps produced a shared pseudoreference and one final duplicate-marked BAM per sample.

01_pseudoreference/
└── shared_uce_pseudoref.fasta

02_mapping/
├── sample_A/
│   ├── sample_A.markdup.bam
│   └── sample_A.markdup.bam.bai
├── sample_B/
│   ├── sample_B.markdup.bam
│   └── sample_B.markdup.bam.bai
└── ...

04_snp_calling/
└── samples.txt

samples.txt should contain one sample identifier per line. The sample set used here should reflect the biological analysis being performed. A strongly divergent outgroup, for example, may be useful for phylogenetic analyses but inappropriate for fine-scale PCA, DAPC, ADMIXTURE or STRUCTURE analyses.

3. Activate the existing environment

The population-genomics environment was created previously. Do not recreate it for every module.

conda activate uce-popgen

Confirm that the required programs are available:

bcftools --version
samtools --version
Version awareness

BCFtools evolves actively. Record the version used for each project and consult the documentation for that version when a short option changes meaning or becomes deprecated.

4. Define portable paths

Use project-relative variables rather than hard-coding institutional paths into the workflow.

PROJECT="/path/to/project"
POPGEN="$PROJECT/population_genomics"
PSEUDOREF="$POPGEN/01_pseudoreference/shared_uce_pseudoref.fasta"
MAPPING="$POPGEN/02_mapping"
SNP_CALLING="$POPGEN/04_snp_calling"
SAMPLES="$SNP_CALLING/samples.txt"
BAM_LIST="$SNP_CALLING/bams.list"

mkdir -p "$SNP_CALLING"

5. Build the BAM list

bcftools mpileup can read a file containing one BAM path per line. Building this list explicitly makes the set of individuals used in calling reproducible.

while read -r SAMPLE; do
    echo "$MAPPING/$SAMPLE/${SAMPLE}.markdup.bam"
done < "$SAMPLES" > "$BAM_LIST"

Check the number of entries:

wc -l "$SAMPLES"
wc -l "$BAM_LIST"

The two numbers should match.

Verify that every BAM exists

while read -r BAM; do
    [[ -f "$BAM" ]] || echo "MISSING: $BAM"
done < "$BAM_LIST"

If nothing is printed, all expected BAM paths were found.

Verify BAM integrity

while read -r BAM; do
    samtools quickcheck -v "$BAM"
done < "$BAM_LIST"

No output indicates that samtools quickcheck did not detect structural problems in the BAM files.

6. What bcftools mpileup does

mpileup does not yet decide which positions are final SNPs. It reads the aligned bases covering each reference position and summarizes the evidence required for genotype-likelihood calculations.

EvidenceWhy it matters
Read alignmentDetermines which reads support a pseudoreference position.
Mapping qualityMeasures confidence that a read was placed at the correct locus.
Base qualityMeasures confidence in the nucleotide observed in the read.
Allelic depthCounts read support for REF and ALT alleles within each sample.
Genotype likelihoodQuantifies how compatible the observed reads are with alternative genotypes.
Important distinction

Read depth is evidence, not certainty. A genotype supported by one or two reads may still receive a genotype call in a raw VCF. Minimum depth is therefore handled explicitly during genotype filtering.

7. Joint variant calling command

The following command is a practical starting point for diploid Illumina UCE population datasets. Thresholds should still be reviewed for the sequencing design and taxonomic divergence of each study.

RAW_VCF="$SNP_CALLING/raw_variants.vcf.gz"

bcftools mpileup \
    -f "$PSEUDOREF" \
    -b "$BAM_LIST" \
    -q 20 \
    -Q 20 \
    -D \
    -d 1000 \
    -a FORMAT/DP,FORMAT/AD \
    -Ou \
| bcftools call \
    -m \
    -v \
    -G - \
    -a GQ \
    -Oz \
    -o "$RAW_VCF"
BCFtools version note

Recent BCFtools development versions use bcftools call -a GQ to request genotype-quality output. Older releases may expose this through -f GQ / --format-fields GQ. Check bcftools call --help on the installed version rather than copying a deprecated short option blindly.

8. Understanding every parameter

-f "$PSEUDOREF"
Uses the shared UCE pseudoreference FASTA as the reference coordinate system. The FASTA must be indexed.
-b "$BAM_LIST"
Reads BAM file paths from a text file, enabling multi-sample calling from the selected individuals.
-q 20
Requires alignment mapping quality ≥20 before a read contributes evidence. Low-confidence alignments are ignored.
-Q 20
Requires base quality ≥20 before a base contributes evidence. This is stricter than the BCFtools default and reduces support from uncertain base calls.
-D
Runs full BAQ on all reads. Current BCFtools documentation specifically recommends full BAQ for multi-sample calling and low-frequency variants because the default heuristic was primarily validated on simpler single-sample settings.
-d 1000
Allows up to 1000 reads per BAM at a position. BCFtools defaults to 250. UCE capture can produce high local depth, so a larger cap avoids unnecessary truncation while still controlling pathological pileups.
-a FORMAT/DP,FORMAT/AD
Outputs per-sample depth (DP) and allele-specific depth (AD). These fields are essential for later genotype-level QC.
-Ou
Streams uncompressed BCF directly into the next BCFtools command. This avoids unnecessary text conversion and intermediate compression.
call -m
Uses the multiallelic calling model, which BCFtools recommends for most variant-calling tasks.
-v
Outputs variant sites only. Positions called entirely as reference are not written to the raw variant VCF.
-G -
Disables the assumption that all samples form one Hardy–Weinberg population and performs single-sample genotype calling within the joint record set. This is useful when population structure is unknown, but BCFtools warns that false positives can increase in low-coverage data.
-a GQ
Requests genotype quality (GQ), a Phred-scaled measure of confidence in each called genotype conditioned on the site being variant.
-Oz
Writes a BGZF-compressed VCF (.vcf.gz) suitable for indexing and downstream BCFtools operations.

9. Why use full BAQ?

BAQ—Base Alignment Quality—reduces the influence of bases whose alignment position is uncertain, particularly around local alignment problems. Without this correction, mismatches created by alignment ambiguity can resemble real nucleotide variation.

BCFtools currently applies BAQ heuristically by default, but its documentation notes that the heuristic has been tested primarily on single-sample data with even allele frequencies. For multi-sample or low-frequency variant discovery, full BAQ remains the recommended safer choice.

BAQ is not base-quality filtering

-Q 20 filters on sequencing base quality. BAQ modifies the effective confidence of bases according to local alignment uncertainty. They address different sources of error.

10. Why -G - requires care

By default, bcftools call assumes that all samples belong to one population and can use Hardy–Weinberg equilibrium information. That assumption may be undesirable when the purpose of the analysis is precisely to discover population structure.

Using -G - removes that population-level HWE assumption. Genotypes are then called independently for each sample while remaining represented together in the same multi-sample VCF.

StrategyAdvantageCaution
Default single populationCan use cross-sample allele-frequency information.Assumes one HWE population, potentially inappropriate for structured datasets.
-G -Avoids forcing all individuals into one HWE population.BCFtools warns that low-coverage samples can show more false positives.
-G groups.tsvApplies HWE within defined populations but not across groups.Requires biologically justified population assignments before calling.
Why DP and AD are retained

The -G strategy needs per-sample quantitative evidence, and later filtering must be able to distinguish a genotype supported by one read from one supported by many independent reads. FORMAT/DP and FORMAT/AD preserve that information.

11. Diploidy and ploidy assumptions

If no ploidy definition is supplied, BCFtools normally treats unlisted regions as diploid. That is appropriate for standard autosomal-like nuclear UCE loci in diploid organisms.

If the study organism or targeted regions include haploid, sex-linked, polyploid or mixed-ploidy loci, this assumption must be changed explicitly. Do not use the default diploid model merely because it is convenient.

12. Index the raw VCF

bcftools index "$RAW_VCF"

For compressed VCF output, BCFtools normally creates a CSI index. Indexed files support rapid region queries and many downstream operations.

13. Extract SNP records

The initial caller can discover both SNPs and short indels. Population-genomic workflows often begin by separating the SNP records while preserving the complete raw variant VCF for provenance.

RAW_SNPS="$SNP_CALLING/raw_snps.vcf.gz"

bcftools view \
    -v snps \
    -Oz \
    -o "$RAW_SNPS" \
    "$RAW_VCF"

bcftools index "$RAW_SNPS"
Do not delete the complete raw VCF

raw_variants.vcf.gz remains the record of the complete discovery step. raw_snps.vcf.gz is a convenient derivative for SNP-focused filtering.

14. Generate summary statistics

Before filtering, document what the caller produced.

bcftools stats "$RAW_VCF" \
    > "$SNP_CALLING/raw_variants.stats.txt"

bcftools stats "$RAW_SNPS" \
    > "$SNP_CALLING/raw_snps.stats.txt"

The summary-number lines can be inspected with:

grep '^SN' "$SNP_CALLING/raw_variants.stats.txt"
grep '^SN' "$SNP_CALLING/raw_snps.stats.txt"

Useful quantities include number of samples, total records, SNPs, indels and multiallelic sites.

15. Per-sample genotype statistics

Mapping QC should now be cross-checked against genotype completeness. Ask bcftools stats to calculate per-sample statistics:

bcftools stats \
    -s - \
    "$RAW_SNPS" \
    > "$SNP_CALLING/raw_snps.per_sample.stats.txt"

Inspect the PSC records:

grep '^PSC' \
    "$SNP_CALLING/raw_snps.per_sample.stats.txt" \
    | head

These records include sample-level genotype counts, average depth and missing genotypes. They are particularly useful for testing whether samples already flagged during mapping QC also show poor genotype completeness.

Sample exclusion should use multiple lines of evidence

A sample that has restricted UCE breadth, weak usable depth and high genotype missingness is a much stronger technical outlier than a sample that is unusual in only one metric.

16. Validate the sample set

The VCF should contain exactly the samples that were intended for joint calling.

bcftools query -l "$RAW_SNPS"

Count them:

bcftools query -l "$RAW_SNPS" | wc -l

Compare this number with wc -l "$SAMPLES". A mismatch should be investigated before any downstream filtering.

17. Count raw variant records efficiently

Once the VCF is indexed, BCFtools can read the record count from the index:

bcftools index -n "$RAW_VCF"
bcftools index -n "$RAW_SNPS"

This is much faster than decompressing and counting every record manually.

18. Inspect the VCF structure

A raw VCF should be inspected before filtering rather than treated as a black box.

Inspect selected FORMAT definitions

bcftools view -h "$RAW_SNPS" \
    | grep -E '^##FORMAT=<ID=(GT|DP|AD|GQ)'

Inspect a few genotype records

bcftools query \
    -f '%CHROM\t%POS\t%REF\t%ALT\t%QUAL[\t%GT:%DP:%AD:%GQ]\n' \
    "$RAW_SNPS" \
    | head -3

A genotype may look like:

0/1:8:5,3:42
 │  │  │   └── GQ: genotype quality
 │  │  └────── AD: REF reads, ALT reads
 │  └───────── DP: total high-quality depth
 └──────────── GT: genotype

19. Understanding the key VCF genotype fields

GT
Genotype. For a diploid biallelic site, 0/0 is homozygous reference, 0/1 heterozygous, 1/1 homozygous alternate and ./. missing.
DP
Per-sample read depth at the position after the read/base-quality logic used by mpileup. It indicates how much sequence evidence contributed to that genotype.
AD
Allelic depth. For a biallelic site, values such as 5,3 mean five reads support REF and three support ALT.
GQ
Conditional genotype quality on a Phred scale. Higher values indicate greater confidence in the genotype relative to the alternatives, conditioned on the site being variant.
High GQ does not replace a depth threshold

A raw call can occasionally show high GQ even when supported by very few reads. GQ describes confidence under the caller's model; DP tells you how much sequence evidence exists. Robust genotype filtering considers both.

20. Site QUAL and genotype GQ are different

QUAL belongs to the variant record and expresses confidence in the assertion that a non-reference allele exists at that site. GQ belongs to an individual genotype and measures confidence in that sample's genotype call.

FieldLevelQuestion
QUALSiteHow strong is the evidence that this position is variant?
GQSample genotypeHow confident is the called genotype for this individual?
DPSample genotypeHow many usable reads support evaluation of this sample at this position?
ADSample genotypeHow is that read support distributed among REF and ALT alleles?

21. Why the output is still a raw SNP dataset

At this stage, a site can be present even if it is unsuitable for population-genomic inference. Examples include:

These properties are not all errors. They are reasons to define an analysis-specific filtering policy in a transparent subsequent step.

raw SNP discovery
        ↓
keep evidence-rich VCF
        ↓
filter low-quality genotypes
        ↓
filter sites by missingness / depth / allele count
        ↓
retain appropriate biallelic SNPs
        ↓
control linkage or select one SNP per UCE
        ↓
population-genomic analyses

22. Outgroups and alternative sample sets

Do not discard an outgroup merely because it is excluded from the primary population SNP VCF. Preserve its final BAM and sample metadata.

A useful strategy is to maintain separate, explicitly named sample lists:

population_samples.txt
    focal individuals for PCA / DAPC / ancestry analyses

all_samples.txt
    focal individuals + outgroup(s) for analyses where the
    broader taxonomic comparison is biologically appropriate

If a second joint VCF including the outgroup is needed, generate it as a separate dataset. This avoids letting a highly divergent taxon alter missingness, allele-frequency and structure analyses designed for the focal populations.

23. Computational execution

Joint calling can be substantially more expensive than the validation commands shown later in this module. On a workstation, run it only when the BAM set fits the available memory and I/O capacity. On an HPC system, submit the calling pipeline through the site's scheduler.

The tutorial intentionally keeps scheduler syntax out of the core command so the biological workflow remains portable across SLURM, PBS, LSF, local workstations and cloud environments.

Do not parallelize samples independently and merge later merely for convenience

The important concept is joint evaluation of the chosen sample set. If the computation must be split, split by independent reference regions/loci with a carefully designed scatter/gather strategy—not by producing unrelated per-sample calls and treating them as equivalent to joint calling.

24. Common warnings and problems

Message or patternInterpretationAction
Sample count is lower than expectedBAM list, read-group sample labels or input list is inconsistent.Stop and reconcile sample identities before filtering.
Many ./. genotypesCoverage is absent or insufficient for some samples/sites.Compare per-sample missingness with mapping QC.
High GQ with very low DPThe genotype can be confident relative to the model despite minimal read evidence.Do not trust GQ alone; define genotype DP filters later.
MQ should be declared as Type=FloatSome BCFtools/VCF-version combinations can expose a header-type compatibility warning for the reserved INFO/MQ tag.Inspect the header and tool version. Do not silently edit biological values; keep the raw VCF and document any header-only correction if required for downstream compatibility.
Calling is extremely slowLarge BAM set, deep targets, storage I/O or BAQ computation may dominate runtime.Use the cluster scheduler and adequate memory/I/O; preserve the same calling model.
Very high raw SNP densityMay reflect real divergence, low-quality calls, reference bias or weakly covered samples.Treat the raw count as a diagnostic, not as the final number of usable SNPs.

25. Recommended output structure

04_snp_calling/
├── samples.txt
├── bams.list
├── raw_variants.vcf.gz
├── raw_variants.vcf.gz.csi
├── raw_variants.stats.txt
├── raw_snps.vcf.gz
├── raw_snps.vcf.gz.csi
├── raw_snps.stats.txt
└── raw_snps.per_sample.stats.txt

26. Validation checklist

✓ Every selected sample has a final duplicate-marked BAM and index.
✓ The BAM list contains exactly the intended individuals.
✓ All BAM files pass basic integrity checks.
✓ All samples were called against the same shared UCE pseudoreference.
✓ Mapping quality and base quality thresholds are documented.
✓ FORMAT/DP and FORMAT/AD were retained by mpileup.
✓ FORMAT/GQ was retained by the caller.
✓ The raw VCF and SNP-only VCF are BGZF-compressed and indexed.
✓ The VCF contains the expected number and names of samples.
✓ Raw variant counts and per-sample statistics were archived.
✓ Mapping-QC warning samples were compared with genotype missingness rather than removed automatically.
✓ No final MAF, missingness, biallelic or linkage filter has been applied yet.

27. What comes next?

The raw VCF now preserves the evidence needed to make explicit filtering decisions. The next module converts unreliable genotypes to missing, restricts the dataset to an appropriate SNP class, filters excessive site missingness, evaluates depth and genotype quality, and applies allele-frequency criteria.

Module 16 · SNP calling
raw multi-sample SNP VCF
        ↓
Module 17 · Variant filtering
        ↓
quality-controlled population SNP dataset

References and software documentation

BCFtools manual — official documentation
Current command syntax and definitions for mpileup, call, view, index and stats.

Variant Call Format specification v4.5
Definitions of VCF site fields and genotype fields including GT, DP, AD and GQ.

Danecek et al. (2021) — Twelve years of SAMtools and BCFtools
Overview of the SAMtools/BCFtools ecosystem and variant-processing framework.

Li (2011) — Improving SNP discovery by base alignment quality
Methodological basis for BAQ and its role in reducing false SNP signals caused by alignment uncertainty.

← Mapping quality control Next: Variant filtering →