Skip to content

Check archived calls in their population context

A complete archived callset can have no missing genotypes and still retain errors from sequencing, alignment, or variant discovery. The input archive does not contain those original measurements. Its call rate establishes whether a genotype value is present in each inspected record.

The primary workflow validates the complete PGEN and checks every eligible autosomal biallelic SNP before frequency thresholds. Unexpected missing calls stop source acceptance. The declared sample and variant missingness threshold is 0.02, but the examples do not manufacture failed calls to illustrate it.

The main panel requires minor allele frequency of at least 0.05 after the combined relatedness exclusions. Frequencies before and after those exclusions use their actual sample sets. The primary calls explicitly include nonfounders in the allele denominator.

The code below checks every sparse-panel ALT dosage against the final allele counts. It also reproduces each person’s observed heterozygote count and the population-specific expected count used by PLINK. The plotted observed fraction uses the same complete sparse marker denominator for every person.

The equilibrium comparison uses 64 evenly spaced indices from the frozen sparse marker list. It calculates the probability-ordered exact test in each source population and in the pooled retained cohort. This diagnostic panel is not a complete equilibrium screen of every source variant.

Conditional on the observed allele count, a possible heterozygote count has weight proportional to 2^h / (h! a! b!), where a and b count the two homozygotes. The shared helper code normalizes these weights and sums outcomes with probability no greater than the observed outcome. Each language performs that calculation independently and checks PLINK’s exact test without a mid-p correction.

A pooled result can reflect population mixture. The workflow does not exclude markers because the combined cohort departs from an equilibrium assumption that its collection design does not satisfy.

The genotype data come from Byrska-Bishop and colleagues and NYGC. The collection acknowledgment credits Coriell samples and NHGRI grants 3UM1HG008901-03S1 and 3UM1HG008901-04S2. This lesson calculates its own teaching summaries from the declared source selection.

source("/shared/population_utils.R")
accepted <- ReadAnalysis()
samples <- ReadSamples()
missing <- ReadTable("complete_sample_missingness.tsv")
variants <- ReadTable("variant_universe.tsv.gz")
dosage <- ReadTable("sparse_dosages.tsv.gz")
markers <- MarkerIds("sparse_markers.txt")
sentinels <- MarkerIds("hwe_sentinel_markers.txt")
stopifnot(all(missing$MISSING_CT == 0), all(missing$F_MISS == 0))
stopifnot(identical(dosage$IID, MarkerIds("unrelated.keep")))
genotypes <- as.matrix(dosage[markers])
stopifnot(all(genotypes %in% 0:2))
metadata <- samples[match(dosage$IID, samples$IID), ]
variant_index <- match(markers, variants$ID)
stopifnot(all(colSums(genotypes) == variants$ALT_CTS[variant_index]))
stopifnot(all(variants$OBS_CT == 2 * nrow(genotypes)))
maf <- pmin(variants$ALT_CTS, variants$OBS_CT - variants$ALT_CTS) /
variants$OBS_CT
stopifnot(all(abs(maf - variants$MAF) < 1e-12), all(maf >= 0.05))
heterozygosity <- data.frame(IID = dosage$IID, Population = metadata$Population,
heterozygotes = rowSums(genotypes == 1),
fraction = rowMeans(genotypes == 1))
hwe <- data.frame()
groups <- c("POOLED", sort(unique(metadata$Population)))
for (group in groups) {
selected <- seq_len(nrow(genotypes))
if (group != "POOLED") {
selected <- which(metadata$Population == group)
}
group_genotypes <- genotypes[selected, , drop = FALSE]
frequency <- colMeans(group_genotypes) / 2
expected_hets <- sum(2 * frequency * (1 - frequency))
het_report <- ReadTable(paste0("heterozygosity_", group, ".het"))
het_report <- het_report[match(dosage$IID[selected], het_report$IID), ]
observed <- rowSums(group_genotypes == 1)
stopifnot(all(het_report[["O(HET)"]] == observed))
stopifnot(all(het_report$OBS_CT == sum(frequency > 0 & frequency < 1)))
stopifnot(all(abs(het_report[["E(HET)"]] - expected_hets) <
5e-6 * expected_hets + 1e-8))
calculated_f <- 1 - observed / expected_hets
stopifnot(all(abs(calculated_f - het_report$F) < 1e-5))
selected_genotypes <- group_genotypes[, sentinels, drop = FALSE]
counts <- data.frame(Population = group, ID = sentinels,
hom_ref = colSums(selected_genotypes == 0),
heterozygous = colSums(selected_genotypes == 1),
hom_alt = colSums(selected_genotypes == 2))
counts$p_value <- numeric(nrow(counts))
for (index in seq_len(nrow(counts))) {
counts$p_value[index] <- HweExact(counts$hom_ref[index],
counts$heterozygous[index],
counts$hom_alt[index])
}
primary_counts <- ReadTable(paste0("hwe_", group, ".gcount"))
primary_counts <- primary_counts[match(sentinels, primary_counts$ID), ]
stopifnot(all(counts$hom_ref == primary_counts$HOM_REF_CT))
stopifnot(all(counts$heterozygous == primary_counts$HET_REF_ALT1_CT))
stopifnot(all(counts$hom_alt == primary_counts$HOM_ALT1_CT))
stopifnot(all(primary_counts$MISSING_CT == 0))
primary_hwe <- ReadTable(paste0("hwe_", group, ".hardy"))
primary_hwe <- primary_hwe[match(sentinels, primary_hwe$ID), ]
stopifnot(all(abs(counts$p_value - primary_hwe$P) <
5e-6 * counts$p_value + 1e-14))
hwe <- rbind(hwe, counts)
}
dir.create("outputs", showWarnings = FALSE)
write.table(heterozygosity, "outputs/heterozygosity_r.tsv", sep = "\t",
row.names = FALSE, quote = FALSE)
write.table(hwe, "outputs/hwe_r.tsv", sep = "\t", row.names = FALSE,
quote = FALSE)
png("outputs/frequency_r.png", width = 1050, height = 700, res = 130)
hist(maf, breaks = seq(0.05, 0.5, by = 0.025),
col = "#167c80", border = "white",
main = "The frozen common-variant association universe",
xlab = "Minor allele frequency in the retained people", ylab = "Markers")
invisible(dev.off())
png("outputs/heterozygosity_r.png", width = 1300, height = 720, res = 130)
par(mar = c(7, 4, 3, 1))
boxplot(fraction ~ Population, data = heterozygosity, las = 2,
col = "#78b3b5", ylab = "Observed heterozygous fraction",
main = "The same sparse marker denominator for every person",
outline = TRUE, outpch = 16, outcex = 0.35)
invisible(dev.off())
fractions <- numeric(length(groups))
for (index in seq_along(groups)) {
fractions[index] <- mean(hwe$p_value[hwe$Population == groups[index]] < 0.001)
}
png("outputs/equilibrium_r.png", width = 1300, height = 720, res = 130)
par(mar = c(7, 4, 3, 1))
barplot(100 * fractions, names.arg = groups, las = 2,
col = c("#9e4f22", rep("#167c80", length(groups) - 1)),
ylab = "Diagnostic markers with exact p < 0.001, percent",
main = "The fixed 64-marker equilibrium diagnostic")
invisible(dev.off())
metrics <- list(source_people = nrow(missing), missing_calls = 0,
retained_people = nrow(genotypes),
sparse_markers = ncol(genotypes),
universe_markers = nrow(variants), hwe_tests = nrow(hwe),
heterozygous_calls = sum(heterozygosity$heterozygotes))
WriteMetrics(metrics)
cat(sprintf("The source reports no missing eligible calls in %d people.\n",
nrow(missing)))
cat(sprintf("All ALT counts agree across %d sparse markers and %d people.\n",
ncol(genotypes), nrow(genotypes)))
cat(sprintf("The exact test checks %d stratum-marker pairs.\n",
nrow(hwe)))
cat("No equilibrium diagnostic defines an additional exclusion.\n")
The source reports no missing eligible calls in 3202 people.
All ALT counts agree across 27390 sparse markers and 2574 people.
The exact test checks 1728 stratum-marker pairs.
No equilibrium diagnostic defines an additional exclusion.

The R frequency figure shows the retained association universe.

The histogram starts at the declared common-variant threshold. It describes the selected association universe, which includes dense chromosome 22 coverage. It is not the complete source allele-frequency spectrum.

The R heterozygosity figure compares people within source population labels.

Every fraction uses the same sparse marker list. The distributions describe that ascertainment and sample selection; they do not rank population quality.

The R equilibrium figure compares pooled and stratified diagnostics.

Each column uses the same 64 diagnostic markers. The displayed threshold is a descriptive comparison, not a multiple-testing discovery rule or an exclusion.

  • PLINK basic statistics

    The manual documents exact equilibrium tests, optional mid-p adjustment, founder denominators, and genotype counts. These options distinguish the reported diagnostic from a different sample set or test.

  • PLINK source data notes

    The resource notes identify the selected callset and corrected pedigree fields. Those source choices determine which people and alleles enter the subsequent count checks.