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 filteringThe 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
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.
| Evidence | Why it matters |
|---|---|
| Read alignment | Determines which reads support a pseudoreference position. |
| Mapping quality | Measures confidence that a read was placed at the correct locus. |
| Base quality | Measures confidence in the nucleotide observed in the read. |
| Allelic depth | Counts read support for REF and ALT alleles within each sample. |
| Genotype likelihood | Quantifies how compatible the observed reads are with alternative genotypes. |
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"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"-b "$BAM_LIST"-q 20-Q 20-D-d 1000-a FORMAT/DP,FORMAT/AD-Oucall -m-v-G --a GQ-Oz.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.
-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.
| Strategy | Advantage | Caution |
|---|---|---|
| Default single population | Can 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.tsv | Applies HWE within defined populations but not across groups. | Requires biologically justified population assignments before calling. |
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"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" \
| headThese 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.
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 -3A 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
GT0/0 is homozygous reference, 0/1 heterozygous, 1/1 homozygous alternate and ./. missing.DPAD5,3 mean five reads support REF and three support ALT.GQA 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.
| Field | Level | Question |
|---|---|---|
QUAL | Site | How strong is the evidence that this position is variant? |
GQ | Sample genotype | How confident is the called genotype for this individual? |
DP | Sample genotype | How many usable reads support evaluation of this sample at this position? |
AD | Sample genotype | How 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:
- genotypes supported by very low depth;
- genotypes with low GQ;
- sites missing in many individuals;
- multiallelic SNPs;
- extremely high-depth sites associated with repetitive or ambiguous mapping;
- very rare alternate alleles;
- multiple linked SNPs from the same UCE locus.
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 analyses22. 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 appropriateIf 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.
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 pattern | Interpretation | Action |
|---|---|---|
| Sample count is lower than expected | BAM list, read-group sample labels or input list is inconsistent. | Stop and reconcile sample identities before filtering. |
Many ./. genotypes | Coverage is absent or insufficient for some samples/sites. | Compare per-sample missingness with mapping QC. |
| High GQ with very low DP | The 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=Float | Some 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 slow | Large 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 density | May 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
mpileup.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 datasetReferences 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.