Skip to content

Visualization

A results section of a variant calling study carries a small set of standard figures, and each one doubles as a quality check. This page draws four of them for the four callers sarek ran on HG002: the transition to transversion ratio, the allele balance of heterozygous SNVs, the density of calls along the region and the indel lengths. Each tab prints the numbers behind its figure before drawing it in ggplot2 or matplotlib, so your text can quote them.

Four callers write four different VCFs, so read the headers before writing any code that assumes a sample name or a FORMAT field.

The HG002 inputs come from NIST and the Genome in a Bottle consortium. The preparation on October 29, 2026 selects the chromosome 20 interval, subsets the GIAB v4.2.1 benchmark, and produces fresh analysis outputs. The source and terms notice identifies the original sequencing and benchmark publications, the exact source files, and the changes. It also records the grants for the Broad reference bundle and Ensembl release 99 annotation.

Terminal window
cd /opt/data/variant_calling
for vcf in haplotypecaller/HG002.haplotypecaller.filtered.vcf.gz \
deepvariant/HG002.deepvariant.vcf.gz \
freebayes/HG002.freebayes.filtered.vcf.gz \
bcftools/HG002.bcftools.vcf.gz; do
sample=$(bcftools query -l "$vcf")
fields=$(bcftools view -h "$vcf" \
| grep -o '^##FORMAT=<ID=[^,]*' \
| cut -d '=' -f 3 \
| paste -sd ' ')
ad=$(bcftools view -h "$vcf" \
| grep '^##FORMAT=<ID=AD,' \
| sed 's/.*Description="//; s/">$//')
no_alt=$(bcftools view -H -i 'ALT="."' "$vcf" 2> /dev/null | wc -l)
echo "${vcf%%/*} sample=$sample records with ALT '.': $no_alt"
echo " FORMAT: $fields"
echo " AD: $ad"
done
haplotypecaller sample=HG002_HG002 records with ALT '.': 0
FORMAT: AD DP GQ GT PL
AD: Allelic depths for the ref and alt alleles in the order listed
deepvariant sample=HG002 records with ALT '.': 0
FORMAT: GT GQ DP MIN_DP AD VAF PL PS MF MD MT MI MED_DP MID
AD: Read depth for each allele
freebayes sample=HG002_HG002 records with ALT '.': 0
FORMAT: GT GQ GL DP AD RO QR AO QA MIN_DP
AD: Number of observation for each allele
bcftools sample=HG002 records with ALT '.': 124
FORMAT: PL AD GT
AD: Allelic depths (high-quality bases)

Three differences matter for the code. HaplotypeCaller and FreeBayes name the sample HG002_HG002, the <patient>_<sample> read group that sarek builds, while DeepVariant and bcftools name it HG002, so the code reads the one sample by position. All four write AD and describe it differently, and FreeBayes writes the same counts again as RO and AO. And bcftools writes 124 records with ALT . and genotype ./., sites with no called variant, which the tabs remove explicitly and count.

Each call set is the file a sarek user would pick up, with the filter that caller ships.

Caller File Records kept
HaplotypeCaller HG002.haplotypecaller.filtered.vcf.gz FILTER PASS
DeepVariant HG002.deepvariant.vcf.gz FILTER PASS, which drops RefCall and NoCall
FreeBayes HG002.freebayes.filtered.vcf.gz every record, after the sarek --freebayes_filter QUAL cut
bcftools HG002.bcftools.vcf.gz every record with a called genotype

The tabs turn each VCF into one row per ALT allele. They drop the spanning deletion allele *, which stands for a deletion called upstream, and they reduce an allele pair of equal length to the bases that differ. FreeBayes and multiallelic records write some SNVs with shared bases around the change, such as TA to CA, which is the SNV T>C. A pair that still differs at more than one base is an MNP, and a pair of unequal length is an indel.

suppressPackageStartupMessages({
library(VariantAnnotation)
library(dplyr)
library(tidyr)
library(ggplot2)
})
dir.create("outputs", showWarnings = FALSE, recursive = TRUE)
call_dir <- "/opt/data/variant_calling"
call_files <- c(
HaplotypeCaller = "haplotypecaller/HG002.haplotypecaller.filtered.vcf.gz",
DeepVariant = "deepvariant/HG002.deepvariant.vcf.gz",
FreeBayes = "freebayes/HG002.freebayes.filtered.vcf.gz",
bcftools = "bcftools/HG002.bcftools.vcf.gz"
)
caller_levels <- names(call_files)
# One fixed colour per caller, the same in every figure on the page.
caller_colours <- c(
HaplotypeCaller = "#2a78d6", DeepVariant = "#eb6834",
FreeBayes = "#1baf7a", bcftools = "#eda100"
)
#' Describe an equal length REF and ALT pair by the bases that differ.
#'
#' FreeBayes and multiallelic records can write a one base change with
#' shared bases around it, such as TA>CA, which is the SNV T>C.
#'
#' @param ref The REF allele.
#' @param alt One ALT allele.
#' @return "T>C" style text for the differing bases, or NA when the two
#' alleles differ in length.
SubstitutionOf <- function(ref, alt) {
if (nchar(ref) != nchar(alt)) {
return(NA_character_)
}
ref_bases <- strsplit(ref, "", fixed = TRUE)[[1]]
alt_bases <- strsplit(alt, "", fixed = TRUE)[[1]]
differ <- ref_bases != alt_bases
paste0(
paste(ref_bases[differ], collapse = ""), ">",
paste(alt_bases[differ], collapse = "")
)
}
#' Read one call set as one row per ALT allele.
#'
#' Keeps the records whose FILTER is PASS or missing, with every ALT
#' allele. VariantAnnotation stores the spanning deletion allele `*` and
#' the ALT `.` of a site with no alternate allele as empty strings.
#'
#' @param path Path to a bgzipped VCF file.
#' @param caller Caller name for the caller column.
#' @return A data frame with one row per ALT allele.
ReadCallSet <- function(path, caller) {
param <- ScanVcfParam(info = NA, geno = c("GT", "AD"))
vcf <- readVcf(path, "hg38", param = param)
vcf <- vcf[filt(vcf) %in% c("PASS", ".")]
n_alt <- lengths(alt(vcf))
record <- rep(seq_along(n_alt), n_alt)
allele <- sequence(n_alt)
depths <- geno(vcf)$AD[record, 1]
alleles <- data.frame(
caller = caller,
sample = samples(header(vcf)),
record = record,
pos = start(vcf)[record],
ref = as.character(ref(vcf))[record],
alt = as.character(unlist(alt(vcf))),
n_alt = n_alt[record],
gt = sub("|", "/", geno(vcf)$GT[record, 1], fixed = TRUE),
ad_ref = as.integer(mapply("[", depths, 1)),
ad_alt = as.integer(mapply("[", depths, allele + 1))
)
alleles$change <- unname(
mapply(SubstitutionOf, alleles$ref, alleles$alt)
)
alleles$kind <- ifelse(
is.na(alleles$change), "indel",
ifelse(nchar(alleles$change) == 3, "SNV", "MNP")
)
alleles$indel_length <- ifelse(
alleles$kind == "indel", nchar(alleles$alt) - nchar(alleles$ref), NA
)
alleles
}
all_alleles <- bind_rows(
Map(ReadCallSet, file.path(call_dir, call_files), caller_levels)
)
all_alleles$caller <- factor(all_alleles$caller, caller_levels)
# A record with GT ./. holds no called variant. Count and remove them.
no_call <- all_alleles |>
filter(gt == "./.") |>
distinct(caller, record) |>
count(caller, name = "no_call_records", .drop = FALSE)
print(as.data.frame(no_call), row.names = FALSE)
cat("\n")
# The spanning deletion allele * stands for a deletion called upstream.
call_sets <- filter(all_alleles, gt != "./.", nchar(alt) > 0)
overview <- call_sets |>
group_by(caller, sample) |>
summarise(
records = n_distinct(record),
snv = sum(kind == "SNV"),
indel = sum(kind == "indel"),
mnp = sum(kind == "MNP"),
.groups = "drop"
)
print(as.data.frame(overview), row.names = FALSE)
# FreeBayes writes the depths twice, as AD and as RO plus AO.
freebayes_vcf <- readVcf(
file.path(call_dir, call_files[["FreeBayes"]]), "hg38",
param = ScanVcfParam(info = NA, geno = c("AD", "RO", "AO"))
)
freebayes_ad <- geno(freebayes_vcf)$AD[, 1]
freebayes_ro_ao <- Map(
c, geno(freebayes_vcf)$RO[, 1], geno(freebayes_vcf)$AO[, 1]
)
cat("\nFreeBayes records where AD differs from RO,AO:",
sum(!mapply(identical, freebayes_ad, freebayes_ro_ao)), "\n")
caller no_call_records
HaplotypeCaller 0
DeepVariant 0
FreeBayes 0
bcftools 124
caller sample records snv indel mnp
HaplotypeCaller HG002_HG002 1795 1452 382 0
DeepVariant HG002 1788 1444 384 0
FreeBayes HG002_HG002 1713 1378 363 29
bcftools HG002 1809 1479 361 0
FreeBayes records where AD differs from RO,AO: 0

R and Python print the same tables here and in every section below. The 124 no-call records all come from bcftools, which keeps 1,809 records once they are gone. FreeBayes alone writes MNP alleles, 29 of them, because it merges changes a few bases apart into one haplotype allele. Its AD agrees with RO and AO on every record, so AD serves all four callers.

A transition swaps a purine for a purine or a pyrimidine for a pyrimidine, A and G or C and T. Every other substitution is a transversion, and there are twice as many possible transversions as transitions, so random errors give a ratio near 0.5. Real human variation is rich in transitions, and the GATK guide to evaluating a germline call set expects about 2.0 to 2.1 for a whole genome and more for an exome. A ratio well below that range points to false positives.

transition_changes <- c("A>G", "G>A", "C>T", "T>C")
titv <- call_sets |>
filter(kind == "SNV") |>
mutate(transition = change %in% transition_changes) |>
group_by(caller) |>
summarise(
transitions = sum(transition),
transversions = sum(!transition),
.groups = "drop"
) |>
mutate(ti_tv = transitions / transversions)
print(
mutate(as.data.frame(titv), ti_tv = sprintf("%.3f", ti_tv)),
row.names = FALSE
)
bcftools_row <- titv[titv$caller == "bcftools", ]
haplotypecaller_row <- titv[titv$caller == "HaplotypeCaller", ]
cat(
"\nbcftools minus HaplotypeCaller: transitions",
bcftools_row$transitions - haplotypecaller_row$transitions,
"transversions",
bcftools_row$transversions - haplotypecaller_row$transversions, "\n"
)
titv_plot <- ggplot(titv, aes(x = ti_tv, y = caller, colour = caller)) +
annotate(
"rect", xmin = 2.0, xmax = 2.1, ymin = -Inf, ymax = Inf,
fill = "grey90"
) +
annotate(
"text", x = 2.05, y = 4.45, label = "whole genome range",
size = 3, colour = "grey35"
) +
geom_point(size = 4, show.legend = FALSE) +
geom_text(
aes(label = sprintf("%.3f", ti_tv)), nudge_y = 0.25,
size = 3.2, colour = "grey20"
) +
scale_colour_manual(values = caller_colours) +
scale_y_discrete(limits = rev(caller_levels)) +
coord_cartesian(xlim = c(1.9, 2.3)) +
labs(x = "Transitions / transversions, SNV alleles", y = NULL) +
theme_minimal(base_size = 11) +
theme(panel.grid.minor = element_blank())
ggsave(
"outputs/visualization_titv_r.png", titv_plot,
width = 6.5, height = 3.2, dpi = 150, bg = "white"
)
caller transitions transversions ti_tv
HaplotypeCaller 998 454 2.198
DeepVariant 991 453 2.188
FreeBayes 948 430 2.205
bcftools 1007 472 2.133
bcftools minus HaplotypeCaller: transitions 9 transversions 18

Ti/Tv of the SNV alleles for each caller, drawn in ggplot2 as one point per caller against a grey band from 2.0 to 2.1. HaplotypeCaller, DeepVariant and FreeBayes sit between 2.188 and 2.205, and bcftools sits lowest at 2.133.

Three callers land between 2.188 and 2.205, and bcftools sits apart at 2.133. It also reports the most SNV alleles, 1,479 against 1,452 for HaplotypeCaller, and the surplus is 9 transitions and 18 transversions. A surplus with a ratio of 0.5 is what random errors look like. All four values sit above the whole genome range. That range describes a whole genome, and one 1 Mb stretch of chr20 with 1,378 to 1,479 SNVs per caller can sit off it, so compare the callers with each other here rather than with the band.

bcftools stats is the usual command line route to the same number.

Terminal window
cd /opt/data/variant_calling
for vcf in haplotypecaller/HG002.haplotypecaller.filtered.vcf.gz \
deepvariant/HG002.deepvariant.vcf.gz \
freebayes/HG002.freebayes.filtered.vcf.gz \
bcftools/HG002.bcftools.vcf.gz; do
bcftools stats -f .,PASS "$vcf" 2> /dev/null \
| awk -v caller="${vcf%%/*}" \
'$1 == "TSTV" {printf "%-16s ts=%s tv=%s ts/tv=%s\n", caller, $3, $4, $5}'
done
haplotypecaller ts=998 tv=454 ts/tv=2.20
deepvariant ts=991 tv=453 ts/tv=2.19
freebayes ts=941 tv=428 ts/tv=2.20
bcftools ts=1007 tv=472 ts/tv=2.13

Its counts match the tabs exactly for HaplotypeCaller, DeepVariant and bcftools. For FreeBayes it counts 941 and 428 where the tabs count 948 and 430. Every single-base allele counts the same way in both, so the difference sits in FreeBayes’ multi-base alleles, which the two methods split into SNVs differently, and both ratios round to 2.20.

For a heterozygous SNV, about half the reads should carry each allele. The allele balance is the ALT read count over the REF plus ALT count from the AD field, and the tabs compute it for every biallelic SNV with genotype 0/1. They also count the calls below 0.3 and above 0.7 and check how many of the low ones sit at a position that the GIAB truth VCF lists.

truth_path <- "/opt/data/truth/hg002_giab_v4_2_1_chr20_region.vcf.gz"
truth_param <- ScanVcfParam(fixed = NA, info = NA, geno = NA)
truth_positions <- start(readVcf(truth_path, "hg38", param = truth_param))
het_snvs <- call_sets |>
filter(kind == "SNV", n_alt == 1, gt == "0/1") |>
mutate(allele_balance = ad_alt / (ad_ref + ad_alt)) |>
filter(!is.na(allele_balance))
balance_summary <- het_snvs |>
group_by(caller) |>
summarise(
het_snvs = n(),
median = sprintf("%.3f", median(allele_balance)),
below_0.3 = sum(allele_balance < 0.3),
of_which_in_truth = sum(
allele_balance < 0.3 & pos %in% truth_positions
),
above_0.7 = sum(allele_balance > 0.7),
.groups = "drop"
)
print(as.data.frame(balance_summary), row.names = FALSE)
balance_plot <- ggplot(het_snvs, aes(x = allele_balance, fill = caller)) +
geom_histogram(
binwidth = 0.025, boundary = 0, colour = "white", linewidth = 0.2,
show.legend = FALSE
) +
geom_vline(xintercept = 0.5, colour = "grey30", linewidth = 0.4) +
facet_wrap(~caller, ncol = 2) +
scale_fill_manual(values = caller_colours) +
scale_x_continuous(limits = c(0, 1), breaks = seq(0, 1, 0.25)) +
labs(x = "ALT reads / (REF + ALT reads)", y = "Heterozygous SNVs") +
theme_minimal(base_size = 11) +
theme(panel.grid.minor = element_blank())
ggsave(
"outputs/visualization_allele_balance_r.png", balance_plot,
width = 7, height = 4.5, dpi = 150, bg = "white"
)
caller het_snvs median below_0.3 of_which_in_truth above_0.7
HaplotypeCaller 898 0.500 25 6 1
DeepVariant 887 0.500 3 3 4
FreeBayes 852 0.500 8 4 3
bcftools 920 0.493 31 8 6

Histograms of the allele balance of heterozygous SNVs, one ggplot2 panel per caller, with a line at 0.5. Each caller peaks at 0.5. HaplotypeCaller and bcftools show a longer tail below 0.3 than DeepVariant and FreeBayes.

The centers agree, with a median of 0.500 for three callers and 0.493 for bcftools. The tails do not. HaplotypeCaller has 25 heterozygous SNVs below 0.3 and bcftools has 31, against 3 for DeepVariant and 8 for FreeBayes. Only 6 of the HaplotypeCaller calls and 8 of the bcftools calls sit at a position in the truth VCF, while all 3 of the DeepVariant calls do.

A heterozygous call that one read in five supports deserves suspicion. Reads that belong elsewhere in the genome can produce this pattern, and this section’s chr20-only reference gives such reads nowhere else to go. Absence from the truth VCF is not proof of an error, because the truth set is complete only inside its benchmark regions, and the Benchmarking page scores the calls inside them properly.

Counting the records in 10 kb windows shows where along the region the calls fall. The tabs count records rather than alleles, give every window of the 1 Mb region a count even when it is zero, and correlate each caller’s 100 counts with those of HaplotypeCaller.

region_start <- 10000000
region_end <- 11000000
bin_width <- 10000
bin_starts <- seq(region_start, region_end - bin_width, by = bin_width)
density <- call_sets |>
distinct(caller, record, pos) |>
mutate(
bin_start = region_start +
(pos - 1 - region_start) %/% bin_width * bin_width
) |>
count(caller, bin_start) |>
complete(caller, bin_start = bin_starts, fill = list(n = 0))
density_summary <- density |>
group_by(caller) |>
summarise(
bins = n(),
mean = sprintf("%.2f", mean(n)),
min = min(n),
max = max(n),
max_bin_start = bin_start[which.max(n)],
empty_bins = sum(n == 0),
.groups = "drop"
)
print(as.data.frame(density_summary), row.names = FALSE)
density_wide <- pivot_wider(density, names_from = caller, values_from = n)
bin_correlation <- cor(density_wide[caller_levels])[, "HaplotypeCaller"]
cat("\nPearson correlation of the bin counts with HaplotypeCaller\n")
cat(sprintf("%-16s %.3f\n", caller_levels, bin_correlation), sep = "")
density_plot <- ggplot(
density, aes(x = (bin_start + bin_width / 2) / 1e6, y = n, fill = caller)
) +
geom_col(width = bin_width / 1e6 * 0.85, show.legend = FALSE) +
facet_wrap(~caller, ncol = 1) +
scale_fill_manual(values = caller_colours) +
labs(x = "Position on chr20 (Mb)", y = "Records per 10 kb") +
theme_minimal(base_size = 11) +
theme(panel.grid.minor = element_blank())
ggsave(
"outputs/visualization_density_r.png", density_plot,
width = 7, height = 5.5, dpi = 150, bg = "white"
)
caller bins mean min max max_bin_start empty_bins
HaplotypeCaller 100 17.95 0 67 10020000 1
DeepVariant 100 17.88 0 68 10020000 1
FreeBayes 100 17.13 0 64 10110000 1
bcftools 100 18.09 1 70 10020000 0
Pearson correlation of the bin counts with HaplotypeCaller
HaplotypeCaller 1.000
DeepVariant 0.992
FreeBayes 0.982
bcftools 0.994

Records per 10 kb window along chr20 from 10.0 to 11.0 Mb, one ggplot2 panel per caller. The four panels rise and fall together, with the tallest windows near 10.02 Mb and 10.11 Mb and the same low stretches in every panel.

The four callers trace the same profile. The mean runs from 17.13 records per window for FreeBayes to 18.09 for bcftools, and the correlation with HaplotypeCaller is 0.992 for DeepVariant, 0.994 for bcftools and 0.982 for FreeBayes. Three callers put their densest window at 10,020,000, with 67 to 70 records, and FreeBayes puts its densest at 10,110,000, with 64.

The useful contrast is between what all four show and what one shows alone. A peak or a dip in every panel belongs to the genome or to the coverage, and the Coverage & QC page has the depth to tell the two apart. A peak in one panel alone belongs to that caller and is worth opening in a genome browser.

The last figure counts the indel alleles by length, positive for an insertion and negative for a deletion. The plots show lengths up to 20 bases in either direction, and the tables count what lies beyond.

indels <- filter(call_sets, kind == "indel")
indel_summary <- indels |>
group_by(caller) |>
summarise(
indels = n(),
insertions = sum(indel_length > 0),
deletions = sum(indel_length < 0),
one_base = sum(abs(indel_length) == 1),
over_20 = sum(abs(indel_length) > 20),
min = min(indel_length),
max = max(indel_length),
.groups = "drop"
)
print(as.data.frame(indel_summary), row.names = FALSE)
indel_plot <- indels |>
filter(abs(indel_length) <= 20) |>
count(caller, indel_length) |>
ggplot(aes(x = indel_length, y = n, fill = caller)) +
geom_col(width = 0.8, show.legend = FALSE) +
facet_wrap(~caller, ncol = 2) +
scale_fill_manual(values = caller_colours) +
scale_x_continuous(breaks = seq(-20, 20, 5)) +
labs(
x = "Indel length (bases; negative = deletion)",
y = "ALT alleles"
) +
theme_minimal(base_size = 11) +
theme(panel.grid.minor = element_blank())
ggsave(
"outputs/visualization_indel_length_r.png", indel_plot,
width = 7, height = 4.5, dpi = 150, bg = "white"
)
# The gate compares these numbers with the Python tab.
parity_metrics <- c(
setNames(overview$records, paste0(overview$caller, "_records")),
setNames(overview$snv, paste0(overview$caller, "_snv")),
setNames(titv$ti_tv, paste0(titv$caller, "_ti_tv")),
setNames(
balance_summary$below_0.3, paste0(balance_summary$caller, "_ab_low")
),
setNames(bin_correlation, paste0(caller_levels, "_bin_r")),
setNames(indel_summary$indels, paste0(indel_summary$caller, "_indels"))
)
jsonlite::write_json(
as.list(parity_metrics), "outputs/visualization_metrics_r.json",
auto_unbox = TRUE, digits = NA
)
caller indels insertions deletions one_base over_20 min max
HaplotypeCaller 382 198 184 165 16 -48 144
DeepVariant 384 193 191 171 11 -48 28
FreeBayes 363 176 187 157 8 -36 28
bcftools 361 182 179 153 10 -42 28

Bar charts of indel length from minus 20 to plus 20 bases, one ggplot2 panel per caller. Every caller peaks at one base deletions and one base insertions, with smaller peaks at four bases on both sides.

The four shapes match. One base indels are the largest group for every caller, from 153 of 361 for bcftools to 171 of 384 for DeepVariant, and insertions and deletions come close to even, 198 against 184 for HaplotypeCaller. The callers part at the long end. HaplotypeCaller reports 16 indels longer than 20 bases, including a 144 base insertion, while DeepVariant, FreeBayes and bcftools report 11, 8 and 10 and stop at 28 bases on the insertion side. A 144 base insertion is past the 50 base line that the What is DNA-seq page draws between an indel and a structural variant, so it needs a look in the alignments before it goes in a table.

  • AD is not one quantity. The headers above give four descriptions, from allelic depths for HaplotypeCaller to high-quality bases for bcftools, and each caller applies its own read and base quality rules before it counts. Compare the shapes of the allele balance histograms across callers rather than their exact tails.
  • Representation changes the counts. The same change can be one MNP allele in FreeBayes and two SNVs in another caller, and the same indel can sit at different positions in a repeat. Normalize with bcftools norm and the reference before any comparison that matches calls by position.
  • The filter decides the figure. Every number here describes the call set after the filter each caller ships with, and the Filtering page shows what a filter removes. Drawn before and after a filter, the allele balance tail and the Ti/Tv show whether it removed the right calls.

The code for this page is in guides/dnaseq/visualization/ of the companion repository. The Benchmarking page replaces the indirect checks on this page with a direct one, precision and recall against the GIAB truth set.

Danecek and colleagues, 2021 describe the development and the current features of SAMtools and BCFtools.

Obenchain and colleagues, 2014 describe VariantAnnotation, the Bioconductor package for the exploration and annotation of genetic variants.

The VCF specification defines the allele and genotype fields used by these summaries. A plot must preserve the distinction between records and alternate alleles.

The BCFtools query and normalization reference explains field extraction and variant representation. It helps interpret comparisons between the four caller outputs.