Skip to content

Coverage & QC

A variant caller can only weigh the reads it is given, so check the alignments before you call anything. This page asks how deep the HG002 alignments are and how even, how many reads are duplicates, and whether the pairs and the bases look like a healthy library. The CRAM files are not in the image, so every number comes from the reports that sarek’s QC steps wrote.

Sarek runs mosdepth and samtools stats twice, on the CRAM that MarkDuplicates wrote, md, and on the recalibrated CRAM that every caller reads, recal.

File under /opt/data/qc/ Tool What it holds
mosdepth/HG002.md.mosdepth.summary.txt mosdepth the bases counted and the mean depth of chr20
mosdepth/HG002.md.mosdepth.global.dist.txt mosdepth the share of chr20 at each depth or more
mosdepth/HG002.md.regions.bed.gz mosdepth the mean depth of each 500 bp window of chr20
markduplicates/HG002.md.cram.metrics GATK MarkDuplicates the duplicate counts of the library
samtools/HG002.md.cram.stats samtools stats read counts, pairing, insert sizes and mismatches

Each md file in the table has a recal twin. The task script of the run shows that sarek started mosdepth with -n --fast-mode --by 500, which skips the per base output and writes the mean depth of each 500 bp window.

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
mosdepth=/opt/data/qc/mosdepth
# The summary that mosdepth wrote for the md CRAM.
awk '{printf "%-13s %9s %9s %5s %4s %4s\n", $1, $2, $3, $4, $5, $6}' \
"$mosdepth/HG002.md.mosdepth.summary.txt"
# The mean is the bases counted divided by the length of the contig.
awk '$1 == "chr20" {printf "mean: %d / %d = %.4f\n", $3, $2, $3 / $2}' \
"$mosdepth/HG002.md.mosdepth.summary.txt"
# The cumulative distribution at 20x and 30x, as mosdepth rounds it.
awk '$1 == "total" && ($2 == 20 || $2 == 30) {
print "share of chr20 at " $2 "x or more:", $3
}' "$mosdepth/HG002.md.mosdepth.global.dist.txt"
chrom length bases mean min max
chr20 64444167 58545277 0.91 0 116
chr20_region 64444167 58545277 0.91 0 116
total 64444167 58545277 0.91 0 116
total_region 64444167 58545277 0.91 0 116
mean: 58545277 / 64444167 = 0.9085
share of chr20 at 30x or more: 0.02
share of chr20 at 20x or more: 0.02

The summary gives chr20 a mean depth of 0.91, which is correct arithmetic for the wrong question. mosdepth divided the 58,545,277 bases it counted by all 64,444,167 bases of chr20, and almost all of chr20 outside the region has no reads. The distribution file adds rounding to the same blind spot. Rounded to two decimals of all of chr20, the share for a 1 Mb region can only be 0.00, 0.01 or 0.02, so the 0.02 at 20x and at 30x says almost nothing. Restrict any report computed over the whole reference to the bases you targeted, which here means the windows.

Both tabs sort every window of the md and recal files into three zones. A region window lies inside chr20:10,000,001-11,000,000, an edge window touches one end of the region from outside, and the rest of chr20 is elsewhere. The tabs then split the region’s windows by whether they touch a gap in the GIAB benchmark regions.

suppressPackageStartupMessages({
library(dplyr)
library(readr)
library(GenomicRanges)
})
mosdepth_dir <- "/opt/data/qc/mosdepth"
bed_path <- paste0(
"/opt/data/truth/", "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))
}
#' Read a mosdepth window file and label each window by its zone.
#'
#' @param path Path to a mosdepth regions.bed.gz file.
#' @param from The 0-based start of the region, as in its BED file.
#' @param to The exclusive end of the region, as in its BED file.
#' @return A tibble with one row per window and a zone column: "region"
#' inside the region, "edge" for the two windows that touch it, and
#' "elsewhere" for the rest of chr20.
ReadWindows <- function(path, from, to) {
read_tsv(
path,
col_names = c("chrom", "start", "end", "depth"),
show_col_types = FALSE
) |>
mutate(zone = case_when(
start >= from & end <= to ~ "region",
end == from | start == to ~ "edge",
.default = "elsewhere"
))
}
region <- ReadBed("/opt/data/region/chr20_region.bed")
from <- start(region) - 1
to <- end(region)
windows <- bind_rows(
md = ReadWindows(
file.path(mosdepth_dir, "HG002.md.regions.bed.gz"), from, to
),
recal = ReadWindows(
file.path(mosdepth_dir, "HG002.recal.regions.bed.gz"), from, to
),
.id = "file"
)
zone_summary <- windows |>
group_by(file, zone) |>
summarise(
windows = n(),
with_reads = sum(depth > 0),
mean_depth = round(mean(depth), 3),
min_depth = min(depth),
max_depth = max(depth),
.groups = "drop"
)
print(as.data.frame(zone_summary))
# The region's windows, split by whether they touch a benchmark gap.
gaps <- GenomicRanges::setdiff(region, ReadBed(bed_path))
in_region <- filter(windows, file == "md", zone == "region")
window_ranges <- GRanges(
in_region$chrom, IRanges(in_region$start + 1, in_region$end)
)
in_region$benchmark <- if_else(
overlapsAny(window_ranges, gaps), "touches a gap", "fully inside"
)
gap_summary <- in_region |>
group_by(benchmark) |>
summarise(
windows = n(),
mean_depth = round(mean(depth), 3),
below_30x = sum(depth < 30),
below_20x = sum(depth < 20)
)
print(as.data.frame(gap_summary))
# The windows on both sides of each end of the region.
ends <- windows |>
filter(file == "md", zone == "edge" | start == from | end == to) |>
dplyr::select(start, end, zone, depth)
print(as.data.frame(ends))
recal_region <- filter(windows, file == "recal", zone == "region")
largest_difference <- max(abs(in_region$depth - recal_region$depth))
cat(sprintf("largest md to recal difference in the region: %.2f\n",
largest_difference))
# The gate compares these values with the Python tab.
parity <- list(
region_mean = mean(in_region$depth),
below_30x = sum(in_region$depth < 30),
gap_windows = sum(in_region$benchmark == "touches a gap"),
md_elsewhere_with_reads = sum(
windows$depth > 0 & windows$zone == "elsewhere" & windows$file == "md"
),
recal_elsewhere_with_reads = sum(
windows$depth > 0 & windows$zone == "elsewhere" & windows$file == "recal"
)
)
dir.create("outputs", showWarnings = FALSE)
jsonlite::write_json(
parity, "outputs/coverage_qc_r.json", auto_unbox = TRUE, digits = NA
)
file zone windows with_reads mean_depth min_depth max_depth
1 md edge 2 1 1.755 0.00 3.51
2 md elsewhere 126887 113 0.000 0.00 2.75
3 md region 2000 2000 58.536 22.16 87.11
4 recal edge 2 1 1.755 0.00 3.51
5 recal elsewhere 126887 0 0.000 0.00 0.00
6 recal region 2000 2000 58.536 22.16 87.11
benchmark windows mean_depth below_30x below_20x
1 fully inside 1840 59.204 0 0
2 touches a gap 160 50.852 4 0
start end zone depth
1 9999500 10000000 edge 0.00
2 10000000 10000500 region 35.59
3 10999500 11000000 region 39.36
4 11000000 11000500 edge 3.51
largest md to recal difference in the region: 0.00

The two tabs print the same values, and the gate compares the region mean and the window counts between them. The 2,000 windows of the region average 58.536, close to the 60x of the source file. None falls below 20x, four fall below 30x, and the lowest averages 22.16.

Table 3 of Marshall et al. 2020, the quality metrics of the Medical Genome Initiative for clinical WGS, makes a mean depth of at least 30x a pass or fail criterion and monitors the share of bases at 20x or more against 90 percent. The region clears the mean easily. The 20x metric is per base, and a window at 22.16 can still hide single bases below 20x, so the windows only show that no 500 bp stretch averages below it.

The thin windows gather at the gaps in the benchmark regions. The 160 windows that touch a gap average 50.852, against 59.204 for the 1,840 that sit fully inside, and all four windows below 30x touch a gap. Depth and the benchmark flag the same stretches of chr20.

Inside the region the md and recal files agree in every window. The one edge window with reads starts at 11,000,000 and holds the ends of reads that run past the region. Away from the region the md file has reads in 113 windows and the recal file has none, for a reason the last section explains.

The figure draws the recal windows, the depth every caller works from, with 5 kb around each end of the region in the lower panels.

library(ggplot2)
library(patchwork)
profile <- filter(windows, file == "recal")
region_mean <- mean(profile$depth[profile$zone == "region"])
#' Draw the windows within 5 kb of one end of the region as bars.
#'
#' @param profile Windows with start, end and depth columns.
#' @param boundary The position of the region end, in bases.
#' @param region_mean The mean depth of the region, drawn as a line.
#' @param label The name of the end, written beside the boundary.
#' @param hjust 1 to write the name left of the boundary, 0 for right.
#' @return A ggplot object.
EdgeView <- function(profile, boundary, region_mean, label, hjust) {
near <- filter(profile, start >= boundary - 5000, end <= boundary + 5000)
ggplot(near) +
geom_rect(
aes(xmin = start / 1e6, xmax = end / 1e6, ymin = 0, ymax = depth),
fill = "#2a78d6", colour = "white", linewidth = 0.4
) +
geom_hline(
yintercept = region_mean, linetype = "dashed", colour = "#52514e"
) +
geom_vline(
xintercept = boundary / 1e6, linetype = "dotted", colour = "#52514e"
) +
annotate(
"text", x = boundary / 1e6, y = 85, label = paste0(" ", label, " "),
hjust = hjust, size = 3, colour = "#52514e"
) +
scale_x_continuous(
breaks = seq(boundary - 4000, boundary + 4000, by = 2000) / 1e6,
labels = scales::label_number(accuracy = 0.001)
) +
scale_y_continuous(limits = c(0, 90)) +
labs(
title = paste("5 kb on each side of the", label),
x = "Position on chr20 (Mb)", y = "Mean depth"
) +
theme_minimal(base_size = 10)
}
full_view <- ggplot(
filter(profile, zone == "region"), aes((start + end) / 2e6, depth)
) +
geom_line(linewidth = 0.3, colour = "#2a78d6") +
geom_hline(
yintercept = region_mean, linetype = "dashed", colour = "#52514e"
) +
scale_y_continuous(limits = c(0, 90)) +
labs(
title = sprintf(
"The whole region in 500 bp windows, dashed line at the mean of %.1f",
region_mean
),
x = "Position on chr20 (Mb)", y = "Mean depth"
) +
theme_minimal(base_size = 10)
start_view <- EdgeView(profile, from, region_mean, "region start", 1)
end_view <- EdgeView(profile, to, region_mean, "region end", 0)
figure <- full_view / (start_view | end_view) +
plot_annotation(
title = "HG002 depth in chr20:10,000,001-11,000,000, recalibrated CRAM"
)
ggsave(
"outputs/coverage-qc_depth_profile_r.png", figure,
width = 9, height = 6.5, dpi = 110, bg = "white"
)

Mean depth of HG002 in 500 bp windows across chr20,000,001-11,000,000, drawn with ggplot2. The top panel shows the 2,000 windows of the region varying around the dashed region mean of about 58. The two lower panels show 5 kb on each side of the region start and the region end. Outside the region the bars are empty, and the first and last windows inside it are lower than their neighbors.

The depth stays level across the region, between the 22.16 and 87.11 of the extreme windows, except at the ends. The first window averages 35.59 and the last 39.36.

The fetch script made that drop, not the library. It kept a pair only when both mates start inside the region, so near the start the reverse reads whose mates start before 10,000,001 are missing, and near the end the forward reads whose mates start after 11,000,000 are missing. With inserts of about 550 bases, the outer few hundred bases at each end keep mostly one strand of reads, and a caller has less evidence there than anywhere else in the region. A whole genome run has no such edge.

Terminal window
metrics=/opt/data/qc/markduplicates/HG002.md.cram.metrics
# The metrics row follows the header line after "## METRICS CLASS".
awk -F '\t' '
/^## METRICS CLASS/ {
getline
split($0, names)
getline
for (i = 1; i <= NF; i++) printf "%-30s %s\n", names[i], $i
exit
}' "$metrics"
# PERCENT_DUPLICATION counts reads: two for each duplicate pair plus the
# unpaired duplicates, over every read examined.
awk -F '\t' '
/^## METRICS CLASS/ {
getline
getline
printf "(2 x %d + %d) / (2 x %d + %d) = %.6f\n",
$7, $6, $3, $2, (2 * $7 + $6) / (2 * $3 + $2)
exit
}' "$metrics"
LIBRARY HG002
UNPAIRED_READS_EXAMINED 0
READ_PAIRS_EXAMINED 199845
SECONDARY_OR_SUPPLEMENTARY_RDS 220
UNMAPPED_READS 0
UNPAIRED_READ_DUPLICATES 0
READ_PAIR_DUPLICATES 1826
READ_PAIR_OPTICAL_DUPLICATES 38
PERCENT_DUPLICATION 0.009137
ESTIMATED_LIBRARY_SIZE 11097402
(2 x 1826 + 0) / (2 x 199845 + 0) = 0.009137

MarkDuplicates examined 199,845 pairs and marked 1,826 as copies of another pair, 38 of them optical duplicates. PERCENT_DUPLICATION counts reads, and the second line rebuilds its 0.009137 from the other columns. samtools stats agrees in the next section, with 3,652 reads flagged, twice 1,826. The MGI table monitors duplicates at below 10 percent of mapped sequence, and the PCR-free libraries of HG002 skip the amplification that makes most copies.

The rate depends on the read groups, because MarkDuplicates compares reads within one library, the LB tag. GIAB pooled 12 libraries for each reference sample, according to the library README, but this run’s samplesheet gives sarek one sample and one lane, so every read lands in one library. Pairs from different libraries that share both ends by chance are marked too, which makes 0.009137 an upper bound.

samtools stats writes a summary block of SN lines at the top of its report. The fence lines up the fields that matter here for the two CRAMs, then derives the share of reads that are not properly paired and the median insert size.

Terminal window
stats=/opt/data/qc/samtools
# The SN lines are the summary block of samtools stats.
grep '^SN' "$stats/HG002.md.cram.stats" | cut -f 2,3 > md_sn.tsv
grep '^SN' "$stats/HG002.recal.cram.stats" | cut -f 2,3 > recal_sn.tsv
# Both files list the same fields in the same order, so paste lines them up.
printf '%-32s %12s %12s\n' field md recal
paste md_sn.tsv recal_sn.tsv | awk -F '\t' '
BEGIN {
keep = "raw total sequences:,reads mapped:,reads properly paired:"
keep = keep ",reads duplicated:,reads MQ0:,supplementary alignments:"
keep = keep ",error rate:,average quality:,insert size average:"
keep = keep ",insert size standard deviation:"
keep = keep ",pairs on different chromosomes:"
n = split(keep, fields, ",")
for (i = 1; i <= n; i++) wanted[fields[i]] = 1
}
$1 in wanted {printf "%-32s %12s %12s\n", $1, $2, $4}'
# Reads that BWA did not flag as part of a proper pair.
for name in md recal; do
awk -F '\t' -v name="$name" '
$1 == "reads paired:" {paired = $2}
$1 == "reads properly paired:" {proper = $2}
END {
printf "%s: %d of %d reads not properly paired, %.3f%%\n",
name, paired - proper, paired, 100 * (paired - proper) / paired
}' "${name}_sn.tsv"
done
# The IS lines give each insert size and its number of pairs.
grep '^IS' "$stats/HG002.md.cram.stats" | cut -f 2,3 | awk '
{size[NR] = $1; pairs[NR] = $2; total += $2}
END {
for (i = 1; i <= NR; i++) {
seen += pairs[i]
if (seen >= total / 2) {print "median insert size, md:", size[i]; exit}
}
}'
field md recal
raw total sequences: 399690 399676
reads mapped: 399690 399676
reads properly paired: 399662 399662
reads duplicated: 3652 3652
reads MQ0: 10 6
supplementary alignments: 220 70
error rate: 2.846421e-03 2.845006e-03
average quality: 36.0 36.8
insert size average: 546.3 546.3
insert size standard deviation: 141.8 141.8
pairs on different chromosomes: 0 0
md: 28 of 399690 reads not properly paired, 0.007%
recal: 14 of 399676 reads not properly paired, 0.004%
median insert size, md: 551

Every read mapped, and 28 of the 399,690 reads in the md file are not properly paired. MGI monitors aligned reads at above 98 percent, but here these numbers say little about the library, because the fetch script took only primary reads that the source aligner had placed in the region as proper pairs.

The insert size averages 546.3 bases, with a median of 551. GIAB sheared the DNA for a target of 550 bases, and MGI monitors a median above 300 bp.

The error rate, 2.846421e-03, is the share of aligned bases that differ from the reference according to the NM tags. Every real variant of HG002 counts as well, so the rate overstates the sequencing error. BQSR leaves the bases alone and rewrites their qualities, so the error rate hardly moves in recal while the average quality rises from 36.0 to 36.8, as BWA & GATK preprocessing explains.

Ten reads in the md file have a mapping quality of 0, which means the aligner found another place that fits as well. HaplotypeCaller skips reads below 20 by default, as its engine source sets, and DeepVariant skips reads below 5 with its WGS model, according to its FAQ.

Between the md and recal files, the CRAM lost 14 primary reads, from 399,690 to 399,676, and 150 supplementary alignments, from 220 to 70. The reads that are not properly paired fell from 28 to 14 while the properly paired count held at 399,662, so the lost reads all come from those 28. They are mates. For 14 pairs, BWA aligned one read inside the region and the other elsewhere on chr20. The 150 supplementary alignments are parts of reads from the region that BWA aligned a second time elsewhere on chr20, the split read form that BWA & GATK preprocessing describes.

Before BWA realigned them, every one of these reads sat in a proper pair inside the region, because the fetch script took only proper pairs from a BAM that Novoalign had aligned to the whole GRCh38 analysis set with its decoy sequences. Against chr20 alone, BWA had no other chromosome to offer, so every second placement it found landed on chr20. The same limit silences a usual alarm. The pairs on different chromosomes line reads 0, as it must with one chromosome, so a chimeric pair shows up only as a pair that is not properly paired. Counting all 28 reads as chimeric gives 0.007 percent, far under the 1 percent that MGI monitors.

No caller sees these alignments. The task script shows that sarek passed the region BED to ApplyBQSR as --intervals, and ApplyBQSR writes only the reads that overlap its intervals, while every md report still counts them. When a run uses intervals, read the md and recal reports side by side.

The MGI thresholds are written for whole clinical genomes, so on a 1 Mb region they serve as reference points rather than a verdict.

Check Threshold Source This run
Mean depth 30x or more, pass or fail Marshall et al. 2020, Table 3 58.536 over the windows of the region
Bases at 20x or more 90 percent or more, monitored Marshall et al. 2020, Table 3 no window below 20x; per base depth is not in the fixtures
Duplicates below 10 percent of mapped sequence Marshall et al. 2020, Table 3 0.009137
Chimeric reads below 1 percent Marshall et al. 2020, Table 3 at most 28 reads, 0.007 percent
Median insert size above 300 bp Marshall et al. 2020, Table 3 551
Aligned reads above 98 percent Marshall et al. 2020, Table 3 399,690 of 399,690, by construction
Mapping quality 20 for HaplotypeCaller, 5 for DeepVariant GATK source, DeepVariant FAQ 10 reads at MAPQ 0 in the md file

The next page, Variant calling, reads the HaplotypeCaller VCF that sarek made from the recalibrated CRAM.

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

The mosdepth documentation explains window summaries and fast-mode behavior. It supports the distinction between whole-contig depth and depth inside the target interval.

The Picard duplication metric implementation defines examined and duplicate read counts. It explains the factors of two in the displayed duplicate-rate calculation.