The Workflow & the Dataset
A germline analysis turns one person’s reads into a list of the places where that genome differs from the reference, with a genotype at each one. This page lays out the path from FASTQ to an annotated VCF and marks which steps nf-core/sarek runs and which steps the pages of this section run. It then opens the answer key for the sample, the Genome in a Bottle truth set for HG002, and counts what is in it. Those counts are what a perfect call set for this region would contain.
The workflow
Section titled “The workflow”nf-core/sarek, run once on the host pages of this section─────────────────────────────────── ─────────────────────paired FASTQ │ FastQC, fastp ┐ nf-core/sarek and │ BWA-MEM, samtools sort │ BWA & GATK preprocessing │ GATK MarkDuplicates │ explain these steps, │ GATK BaseRecalibrator, ApplyBQSR ┘ reference only ▼recalibrated CRAM ├── mosdepth, samtools stats ────────────► Coverage & QC │ │ HaplotypeCaller, DeepVariant, │ FreeBayes, bcftools mpileup ▼one VCF per caller ────────────────────────► Variant calling │ Comparing callers │ Filtering │ Benchmarking, with the GIAB truth set │ Visualization │ SnpEff ▼annotated VCF ─────────────────────────────► AnnotationThe left column is pipeline work. Sarek ran it once, as a Nextflow run on the host with each process in its own Podman container, and the DNA-seq with nf-core/sarek guide records that run and every file it wrote. The nf-core/sarek and BWA & GATK preprocessing pages explain those steps without running them again, and each one says so in a note.
The right column reads what sarek wrote. The QC reports, the four VCFs, the SnpEff
output and the truth set were copied into the dnaseq image under /opt/data, and every
gated page reads them from there. No page realigns a read. Each page runs its own code in
that image, and its checks fail when a printed number or a figure on the page did not come
from that run.
The dataset
Section titled “The dataset”The sample is HG002, also catalogued as NA24385, the son in the Ashkenazi trio that
Genome in a Bottle characterizes. GIAB sequenced him to about 300x on a HiSeq 2500, with
2 x 148 bp reads from TruSeq PCR-free libraries and a target insert size of 550 bases, as
the GIAB data paper describes. The reads here
come from HG002.GRCh38.60x.1.bam, a 60x share of those reads that Novoalign aligned to
the GRCh38 analysis set with its decoy sequences, according to the
README of the BAM folder.
A fetch script cut one region, chr20:10,000,001-11,000,000, out of that file and wrote
the read pairs back out as FASTQ, so sarek starts from reads. The region was the first
1 Mb window from 10 Mb onward that holds at least 1,000 SNVs and 100 indels inside the
benchmark regions of the truth set. The reference is chr20 of the GATK GRCh38 FASTA,
which is why every coordinate on these pages starts with chr20.
The truth set is the GIAB v4.2.1 benchmark of Wagner et al. 2022. It has two parts. The VCF lists the variants GIAB trusts, and the BED file lists the benchmark regions, where that VCF is complete. Inside those regions, a call that is not in the truth VCF is a false positive, and a truth variant that no caller finds is a false negative. Outside them, nothing can be scored, which is why the GA4GH best practices compute precision and recall inside the benchmark regions only. Both files were cut to the region by the same fetch script.
The input files
Section titled “The input files”Every gated page reads its inputs from the files below and from the chr20 reference under
/opt/reference. The image checks each file against SHA256SUMS when it is built, and the
fence repeats the check.
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.
# Every file under /opt/data, with its size in bytes.find /opt/data -type f -printf '%10s %P\n' | LC_ALL=C sort -k 2
# The chr20 reference and its length.cut -f 1,2 /opt/reference/chr20.fasta.fai
# Check every file against the checksums written when the fixtures were made.cd /opt/datasha256sum --quiet -c SHA256SUMSecho "$(wc -l < SHA256SUMS) files match SHA256SUMS"cd - > /dev/null
# The sample name inside each VCF.for vcf in /opt/data/*/*/*.vcf.gz /opt/data/truth/*.vcf.gz; do printf '%-12s %s\n' "$(bcftools query -l "$vcf")" "${vcf#/opt/data/}"done 12940 PROVENANCE.md 4087 SHA256SUMS 117815 annotation/haplotypecaller/HG002.haplotypecaller.filtered_snpEff.ann.vcf.gz 689 annotation/haplotypecaller/HG002.haplotypecaller.filtered_snpEff.ann.vcf.gz.tbi 12042 annotation/haplotypecaller/HG002.haplotypecaller.filtered_snpEff.csv 2434 annotation/haplotypecaller/HG002.haplotypecaller.filtered_snpEff.genes.txt 1135019 qc/bqsr/HG002.recal.table 4219 qc/markduplicates/HG002.md.cram.metrics 2500 qc/mosdepth/HG002.md.mosdepth.global.dist.txt 2248 qc/mosdepth/HG002.md.mosdepth.region.dist.txt 186 qc/mosdepth/HG002.md.mosdepth.summary.txt 553876 qc/mosdepth/HG002.md.regions.bed.gz 217 qc/mosdepth/HG002.md.regions.bed.gz.csi 2500 qc/mosdepth/HG002.recal.mosdepth.global.dist.txt 2248 qc/mosdepth/HG002.recal.mosdepth.region.dist.txt 186 qc/mosdepth/HG002.recal.mosdepth.summary.txt 553331 qc/mosdepth/HG002.recal.regions.bed.gz 217 qc/mosdepth/HG002.recal.regions.bed.gz.csi 2777 qc/multiqc/multiqc_general_stats.txt 104556 qc/samtools/HG002.md.cram.stats 105716 qc/samtools/HG002.recal.cram.stats 24 region/chr20_region.bed 63622 truth/hg002_giab_v4_2_1_chr20_region.vcf.gz 705 truth/hg002_giab_v4_2_1_chr20_region.vcf.gz.tbi 3096 truth/hg002_giab_v4_2_1_chr20_region_noinconsistent.bed 69702 variant_calling/bcftools/HG002.bcftools.vcf.gz 641 variant_calling/bcftools/HG002.bcftools.vcf.gz.tbi 43974 variant_calling/deepvariant/HG002.deepvariant.vcf.gz 684 variant_calling/deepvariant/HG002.deepvariant.vcf.gz.tbi 163809 variant_calling/freebayes/HG002.freebayes.filtered.vcf.gz 685 variant_calling/freebayes/HG002.freebayes.filtered.vcf.gz.tbi 203468 variant_calling/freebayes/HG002.freebayes.vcf.gz 696 variant_calling/freebayes/HG002.freebayes.vcf.gz.tbi 101113 variant_calling/haplotypecaller/HG002.haplotypecaller.filtered.vcf.gz 661 variant_calling/haplotypecaller/HG002.haplotypecaller.filtered.vcf.gz.tbi 92187 variant_calling/haplotypecaller/HG002.haplotypecaller.vcf.gz 661 variant_calling/haplotypecaller/HG002.haplotypecaller.vcf.gz.tbichr20 6444416735 files match SHA256SUMSHG002_HG002 annotation/haplotypecaller/HG002.haplotypecaller.filtered_snpEff.ann.vcf.gzHG002 variant_calling/bcftools/HG002.bcftools.vcf.gzHG002 variant_calling/deepvariant/HG002.deepvariant.vcf.gzHG002_HG002 variant_calling/freebayes/HG002.freebayes.filtered.vcf.gzHG002_HG002 variant_calling/freebayes/HG002.freebayes.vcf.gzHG002_HG002 variant_calling/haplotypecaller/HG002.haplotypecaller.filtered.vcf.gzHG002_HG002 variant_calling/haplotypecaller/HG002.haplotypecaller.vcf.gzHG002 truth/hg002_giab_v4_2_1_chr20_region.vcf.gzTwo sample names appear. HaplotypeCaller and FreeBayes take the name from the SM tag of
the read group, which sarek builds as <patient>_<sample>, so they write HG002_HG002.
Sarek starts DeepVariant with --sample_name HG002, and the bcftools VCF and the truth set
also say HG002. A script that selects a sample by name breaks when it moves from one
caller’s VCF to the next, so read the first sample column by position when a VCF holds a
single sample.
The qc/ folder holds the reports that the
Coverage & QC page reads. Each report exists twice, once
for the CRAM written after duplicate marking, md, and once for the recalibrated CRAM,
recal. The alignment files themselves are not in the image.
The truth set in numbers
Section titled “The truth set in numbers”bcftools answers the first questions from the command line. The truth BED is in BED
coordinates, 0-based and half open, so the length of an interval is its end minus its
start. A record counts as inside the benchmark regions when its POS falls inside an
interval, which is what bcftools view -T tests by default.
truth=/opt/data/truthvcf="$truth/hg002_giab_v4_2_1_chr20_region.vcf.gz"bed="$truth/hg002_giab_v4_2_1_chr20_region_noinconsistent.bed"
# BED intervals are 0-based and half open: the length is end - start.awk '{n += $3 - $2} END {print "region length:", n}' \ /opt/data/region/chr20_region.bedawk '{n += $3 - $2} END {print "benchmark bases:", n, "in", NR, "intervals"}' \ "$bed"
echo "truth records in the region: $(bcftools view -H "$vcf" | wc -l)"
# -T keeps the records whose POS falls inside a BED interval.bcftools view -T "$bed" -Oz -o truth_in_bed.vcf.gz "$vcf"echo "records inside the BED: $(bcftools view -H truth_in_bed.vcf.gz | wc -l)"echo "records outside the BED: $(bcftools view -H -T ^"$bed" "$vcf" | wc -l)"
# An SNV has one base in REF and in every ALT. An indel record has at# least one ALT allele whose length differs from REF.snvs=$(bcftools view -H -i 'TYPE="snp"' truth_in_bed.vcf.gz | wc -l)indels=$(bcftools view -H -v indels truth_in_bed.vcf.gz | wc -l)echo "SNVs: $snvs"echo "indels: $indels"
# Split each genotype into its two allele indexes, 0 being REF.bcftools query -f '[%GT]\n' truth_in_bed.vcf.gz \ | awk -F '[/|]' ' $1 == $2 {hom++; next} $1 == 0 || $2 == 0 {het++; next} {multi++} END { print "het REF/ALT:", het print "hom ALT/ALT:", hom print "het ALT/ALT:", multi }'region length: 1000000benchmark bases: 977839 in 129 intervalstruth records in the region: 1625records inside the BED: 1588records outside the BED: 37SNVs: 1354indels: 234het REF/ALT: 974hom ALT/ALT: 595het ALT/ALT: 19The R tab reads the same two files with VariantAnnotation and GenomicRanges, and the Python tab reads them with cyvcf2 and pandas. Both also count one case that bcftools does not report, a record whose POS is inside an interval but whose REF allele runs past the interval’s end.
suppressPackageStartupMessages({ library(VariantAnnotation) library(GenomicRanges)})
truth_dir <- "/opt/data/truth"vcf_path <- file.path(truth_dir, "hg002_giab_v4_2_1_chr20_region.vcf.gz")bed_path <- file.path( truth_dir, "hg002_giab_v4_2_1_chr20_region_noinconsistent.bed")
#' Read a three column BED file as 1-based GRanges.#'#' @param path Path to the BED file.#' @return A GRanges object with one range per line of the file.ReadBed <- function(path) { bed <- read.delim( path, header = FALSE, col.names = c("chrom", "start", "end") ) # A BED start is 0-based and its end is exclusive, so add 1 to the start. GRanges(bed$chrom, IRanges(start = bed$start + 1, end = bed$end))}
region <- ReadBed("/opt/data/region/chr20_region.bed")benchmark <- ReadBed(bed_path)cat(sprintf("region length: %d\n", sum(width(region))))cat(sprintf( "benchmark bases: %d in %d intervals\n", sum(width(benchmark)), length(benchmark)))
# Read the fixed fields and the genotypes, and skip the INFO fields.param <- ScanVcfParam(info = NA, geno = "GT")truth <- readVcf(vcf_path, genome = "hg38", param = param)cat(sprintf("truth records in the region: %d\n", nrow(truth)))
# A record is inside when its POS, the first base of REF, is inside.first_base <- resize(rowRanges(truth), width = 1, fix = "start")inside <- truth[overlapsAny(first_base, benchmark)]
is_snv <- nchar(ref(inside)) == 1 & all(nchar(alt(inside)) == 1)
gt <- geno(inside)$GT[, 1]first_allele <- sub("[/|].*", "", gt)second_allele <- sub(".*[/|]", "", gt)is_hom <- first_allele == second_alleleis_het_ref <- !is_hom & (first_allele == "0" | second_allele == "0")
# rowRanges spans the whole REF allele, so "within" tests all of it.ref_inside <- overlapsAny(rowRanges(inside), benchmark, type = "within")
counts <- list( records = nrow(truth), in_bed = nrow(inside), snvs = sum(is_snv), indels = sum(!is_snv), het_ref_alt = sum(is_het_ref), hom_alt_alt = sum(is_hom), het_alt_alt = sum(!is_hom & !is_het_ref), ref_past_end = sum(!ref_inside))cat(sprintf("records inside the BED: %d\n", counts$in_bed))cat(sprintf("records outside the BED: %d\n", nrow(truth) - nrow(inside)))cat(sprintf("SNVs: %d\n", counts$snvs))cat(sprintf("indels: %d\n", counts$indels))cat(sprintf("het REF/ALT: %d\n", counts$het_ref_alt))cat(sprintf("hom ALT/ALT: %d\n", counts$hom_alt_alt))cat(sprintf("het ALT/ALT: %d\n", counts$het_alt_alt))cat(sprintf("REF runs past its interval: %d\n", counts$ref_past_end))for (i in which(!ref_inside)) { record <- rowRanges(inside)[i] holder <- benchmark[overlapsAny(benchmark, resize(record, 1))] cat(sprintf( " POS %d %s>%s, REF ends at %d, interval ends at %d\n", start(record), as.character(record$REF), paste(as.character(unlist(record$ALT)), collapse = ","), end(record), end(holder) ))}
# The gate compares these counts with the Python tab.dir.create("outputs", showWarnings = FALSE)jsonlite::write_json( counts, "outputs/overview_counts_r.json", auto_unbox = TRUE)region length: 1000000benchmark bases: 977839 in 129 intervalstruth records in the region: 1625records inside the BED: 1588records outside the BED: 37SNVs: 1354indels: 234het REF/ALT: 974hom ALT/ALT: 595het ALT/ALT: 19REF runs past its interval: 1 POS 10566231 GTTTTAGTTAAC>G, REF ends at 10566242, interval ends at 10566232import jsonimport pathlib
import cyvcf2import numpy as npimport pandas as pd
TRUTH_DIR = pathlib.Path("/opt/data/truth")VCF_PATH = TRUTH_DIR / "hg002_giab_v4_2_1_chr20_region.vcf.gz"BED_PATH = TRUTH_DIR / "hg002_giab_v4_2_1_chr20_region_noinconsistent.bed"
def read_bed(path): """Read a three column BED file.
Args: path: Path to the BED file.
Returns: A DataFrame with chrom, start and end columns. The coordinates stay 0-based and half open, as in the file. """ return pd.read_csv( path, sep="\t", header=None, names=["chrom", "start", "end"] )
def genotype_class(first, second): """Name the class of one diploid genotype.
Args: first: Index of the first allele, 0 for REF. second: Index of the second allele, 0 for REF.
Returns: "hom ALT/ALT", "het REF/ALT" or "het ALT/ALT". """ if first == second: return "hom ALT/ALT" if first == 0 or second == 0: return "het REF/ALT" return "het ALT/ALT"
def read_truth(path): """Read the fields this page needs from every record of a VCF.
Args: path: Path to a bgzipped single sample VCF.
Returns: A DataFrame with one row per record: POS, REF, ALT, the 0-based start and the exclusive end of the REF allele, whether the record is an SNV, and the genotype class. """ rows = [] reader = cyvcf2.VCF(str(path)) for variant in reader: first, second = variant.genotypes[0][:2] is_snv = len(variant.REF) == 1 and all( len(alt) == 1 for alt in variant.ALT ) rows.append({ "pos": variant.POS, "ref": variant.REF, "alt": ",".join(variant.ALT), "start": variant.start, "end": variant.end, "snv": is_snv, "genotype": genotype_class(first, second), }) reader.close() return pd.DataFrame(rows)
def holding_interval(positions, bed): """Find the BED interval that holds each 0-based position.
Args: positions: 0-based positions, as a NumPy array. bed: Sorted, non-overlapping intervals from read_bed.
Returns: For each position, the row number of the interval that holds it, or -1 when no interval does. """ starts = bed["start"].to_numpy() ends = bed["end"].to_numpy() index = np.searchsorted(starts, positions, side="right") - 1 held = (index >= 0) & (positions < ends[np.maximum(index, 0)]) return np.where(held, index, -1)
region = read_bed("/opt/data/region/chr20_region.bed")benchmark = read_bed(BED_PATH)region_length = int((region["end"] - region["start"]).sum())benchmark_bases = int((benchmark["end"] - benchmark["start"]).sum())print(f"region length: {region_length}")print(f"benchmark bases: {benchmark_bases} in {len(benchmark)} intervals")
truth = read_truth(VCF_PATH)print(f"truth records in the region: {len(truth)}")
# A record is inside when its POS, the first base of REF, is inside.interval = holding_interval(truth["start"].to_numpy(), benchmark)inside = truth[interval >= 0]interval_end = benchmark["end"].to_numpy()[interval[interval >= 0]]past_end = inside["end"].to_numpy() > interval_endgenotypes = inside["genotype"].value_counts()
counts = { "records": len(truth), "in_bed": len(inside), "snvs": int(inside["snv"].sum()), "indels": int((~inside["snv"]).sum()), "het_ref_alt": int(genotypes.get("het REF/ALT", 0)), "hom_alt_alt": int(genotypes.get("hom ALT/ALT", 0)), "het_alt_alt": int(genotypes.get("het ALT/ALT", 0)), "ref_past_end": int(past_end.sum()),}print(f"records inside the BED: {counts['in_bed']}")print(f"records outside the BED: {len(truth) - len(inside)}")print(f"SNVs: {counts['snvs']}")print(f"indels: {counts['indels']}")print(f"het REF/ALT: {counts['het_ref_alt']}")print(f"hom ALT/ALT: {counts['hom_alt_alt']}")print(f"het ALT/ALT: {counts['het_alt_alt']}")print(f"REF runs past its interval: {counts['ref_past_end']}")records = inside[past_end].itertuples()for record, end in zip(records, interval_end[past_end]): # A 0-based exclusive end is the same number as a 1-based last base. print( f" POS {record.pos} {record.ref}>{record.alt}, " f"REF ends at {record.end}, interval ends at {end}" )
# The gate compares these counts with the R tab.pathlib.Path("outputs").mkdir(exist_ok=True)pathlib.Path("outputs/overview_counts_python.json").write_text( json.dumps(counts, indent=2) + "\n")region length: 1000000benchmark bases: 977839 in 129 intervalstruth records in the region: 1625records inside the BED: 1588records outside the BED: 37SNVs: 1354indels: 234het REF/ALT: 974hom ALT/ALT: 595het ALT/ALT: 19REF runs past its interval: 1 POS 10566231 GTTTTAGTTAAC>G, REF ends at 10566242, interval ends at 10566232Reading the counts
Section titled “Reading the counts”The three fences agree on every count they share, and the gate compares the R and Python counts field by field. The benchmark regions cover 977,839 of the 1,000,000 bases in the region, split into 129 intervals. Of the 1,625 truth records with POS in the region, 1,588 fall inside an interval. The other 37 sit in the gaps between intervals, where the benchmark makes no claim, so no call there can be scored.
Inside the benchmark regions the truth holds 1,354 SNVs and 234 indel records, so a caller
that found everything would report 1,588 variants here and nothing else. Of those
records, 974 carry one REF and one ALT allele, and 595 carry the ALT allele on both
copies. The remaining 19 are multiallelic records, where the two copies carry two
different ALT alleles and the genotype reads 1/2. bcftools norm -m- splits each of
those into two records with one ALT each, so a count taken after normalization differs
from a count taken before it.
The one record that the R and Python tabs flag is an 11 base deletion at POS 10,566,231.
Its POS and the first deleted base lie inside an interval that ends at 10,566,232, and the
other ten deleted bases lie past that end. A rule that asks for the whole REF allele to
sit inside the BED leaves this deletion out, while the POS rule of bcftools view -T keeps
it. Neither rule is wrong. Pick one and apply it to the truth set and to the calls alike,
or the two counts stop lining up at the edges of the intervals.
Where this goes wrong
Section titled “Where this goes wrong”- BED and VCF coordinates differ by one. A BED start is 0-based and a VCF POS is 1-based,
so the R tab adds 1 to every BED start and the Python tab compares the BED with the
0-based
variant.startof cyvcf2. Skip that step and every interval shifts by one base, which drops an SNV on the first base of an interval and admits one just before it. - A call outside the benchmark BED cannot be scored. The truth there is unknown, so the call is neither a true nor a false positive.
- Sample names differ between the VCFs above. Code that picks the sample by name works on one caller’s file and fails on the next.
- Counts made before and after normalization do not compare. Splitting the 19 multiallelic records adds one record for each of them.
Next steps
Section titled “Next steps”The next page, nf-core/sarek, covers the pipeline that
wrote the QC reports and the VCFs in /opt/data.
Scientific references
Section titled “Scientific references”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.
Further reading
Section titled “Further reading”The Sarek 3.11.0 usage guide describes the pipeline inputs and stages that produced the local files. It connects the lesson sequence to the recorded run.
The VCF specification defines records, alternate alleles, genotypes, and reference blocks. These distinctions explain why record counts and benchmark bases answer different questions.