Combine pedigrees with genotype relatedness
Ordinary association regression treats its residual observations as independent. A parent and child do not satisfy that assumption merely because their sample identifiers differ. The teaching analysis therefore selects a set that passes both the recorded pedigree rule and the declared genotype relatedness rule.
KING estimates come from one eligible SNP per 100-kb autosomal window. Within each window, the workflow chooses the lowest coordinate, then reference and alternate alleles in lexical order. This selection precedes phenotype creation and never uses an association result.
Preserve both sources of evidence
Section titled “Preserve both sources of evidence”The conflict graph contains each pair with KING kinship above 0.0884 and each
documented first-degree or second-degree relationship. The pedigree calculation
includes shared parent identifiers even when that parent has no genotype row.
An absent parent code of 0 does not connect two families.
Pedigree kinship uses the standard parental recursion with unrecorded founders treated as unrelated. The primary record preserves its assumptions and the relationships the available table establishes. Missing family metadata cannot prove that two people are unrelated.
PLINK’s KING documentation explains that the estimator does not use pedigree records and can underestimate kinship when parents come from different populations. A low KING value therefore does not cancel a documented close relationship. The workflow records discordant pairs and requires a source-bound review before it creates the simulated traits.
Apply the same deterministic exclusion
Section titled “Apply the same deterministic exclusion”Each step removes the person with the most remaining conflict edges. Ties use higher sample missingness, then the lexically larger sample identifier. The code below independently reproduces that rule from the complete accepted conflict table and compares every exclusion with the primary run.
The rule produces a reproducible conflict-free set. It does not claim the largest possible set, and it does not select people to improve a phenotype association.
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()conflicts <- ReadTable("relatedness_conflicts.tsv")missing <- ReadTable("complete_sample_missingness.tsv")expected <- ReadTable("excluded_samples.tsv")keep <- MarkerIds("unrelated.keep")stopifnot(identical(samples$IID, missing$IID))invisible(Sys.setlocale("LC_COLLATE", "C"))neighbors <- rep(list(integer()), nrow(samples))for (index in seq_len(nrow(conflicts))) { left <- match(conflicts$IID1[index], samples$IID) right <- match(conflicts$IID2[index], samples$IID) stopifnot(!is.na(left), !is.na(right)) neighbors[[left]] <- c(neighbors[[left]], right) neighbors[[right]] <- c(neighbors[[right]], left)}degree <- lengths(neighbors)retained <- rep(TRUE, nrow(samples))excluded <- data.frame(IID = character(), remaining_degree = integer(), missing_fraction = numeric(), remaining_neighbors = character())while (any(degree > 0)) { candidates <- which(retained & degree > 0) ranking <- order(degree[candidates], missing$F_MISS[candidates], samples$IID[candidates], decreasing = TRUE) removed <- candidates[ranking[1]] adjacent <- neighbors[[removed]][retained[neighbors[[removed]]]] record <- data.frame( IID = samples$IID[removed], remaining_degree = degree[removed], missing_fraction = missing$F_MISS[removed], remaining_neighbors = paste(sort(samples$IID[adjacent]), collapse = ",") ) excluded <- rbind(excluded, record) retained[removed] <- FALSE degree[adjacent] <- degree[adjacent] - 1L degree[removed] <- 0L}stopifnot(identical(samples$IID[retained], keep))stopifnot(identical(excluded$IID, expected$IID))stopifnot(identical(excluded$remaining_neighbors, expected$remaining_neighbors))stopifnot(all(excluded$remaining_degree == expected$remaining_degree))stopifnot(!any(conflicts$IID1 %in% keep & conflicts$IID2 %in% keep))dir.create("outputs", showWarnings = FALSE)write.table(excluded, "outputs/exclusions_r.tsv", sep = "\t", row.names = FALSE, quote = FALSE)known <- conflicts$pedigree_kinship > 0.0884png("outputs/relatedness_r.png", width = 1100, height = 760, res = 130)plot(conflicts$pedigree_kinship, conflicts$king_kinship, col = ifelse(known, "#167c80", "#969ca3"), pch = 16, cex = 0.65, xlab = "Kinship implied by the available pedigree", ylab = "KING estimate on the preliminary sparse panel", main = "Every accepted conflict pair before sample exclusions")abline(h = 0.0884, lty = 2, col = "#9e4f22")legend("right", c("Documented close relationship", "KING conflict only"), col = c("#167c80", "#969ca3"), pch = 16, bty = "n")invisible(dev.off())discordant <- sum(known & conflicts$king_kinship <= 0.0884)metrics <- list(input_samples = nrow(samples), retained_samples = sum(retained), excluded_samples = nrow(excluded), conflict_pairs = nrow(conflicts), discordant_pairs = discordant, retained_conflicts = 0)WriteMetrics(metrics)cat(sprintf("The rule retains %d of %d people.\n", sum(retained), nrow(samples)))cat(sprintf("It excludes %d people from %d conflict pairs.\n", nrow(excluded), nrow(conflicts)))cat(sprintf("The review records %d pedigree pairs below the KING cutoff.\n", discordant))cat("No retained pair violates either declared relatedness rule.\n")The rule retains 2574 of 3202 people.It excludes 628 people from 1267 conflict pairs.The review records 0 pedigree pairs below the KING cutoff.No retained pair violates either declared relatedness rule.
Zero on the pedigree axis means that the supplied family records do not establish a close relationship. It does not prove biological unrelatedness. Every plotted pair contributes a conflict before sample selection.
import sys
import matplotlib.pyplot as pltimport pandas as pd
sys.path.insert(0, "/shared")import population_utils as population
accepted = population.read_analysis()samples = population.read_samples()conflicts = population.read_table("relatedness_conflicts.tsv")missing = population.read_table("complete_sample_missingness.tsv")expected = population.read_table("excluded_samples.tsv")keep = population.marker_ids("unrelated.keep")assert samples["IID"].tolist() == missing["IID"].tolist()neighbors = {iid: set() for iid in samples["IID"]}for row in conflicts.itertuples(index=False): neighbors[row.IID1].add(row.IID2) neighbors[row.IID2].add(row.IID1)missing_fraction = missing.set_index("IID")["F_MISS"].to_dict()excluded = []while any(neighbors.values()): candidates = [(len(adjacent), missing_fraction[iid], iid) for iid, adjacent in neighbors.items() if adjacent] degree, fraction, removed = max(candidates) adjacent = sorted(neighbors[removed]) excluded.append((removed, degree, fraction, ",".join(adjacent))) for neighbor in adjacent: neighbors[neighbor].remove(removed) del neighbors[removed]excluded = pd.DataFrame(excluded, columns=expected.columns)retained = [iid for iid in samples["IID"] if iid in neighbors]assert retained == keepassert excluded["IID"].tolist() == expected["IID"].tolist()assert excluded["remaining_neighbors"].equals(expected["remaining_neighbors"])assert excluded["remaining_degree"].equals(expected["remaining_degree"])assert not (conflicts["IID1"].isin(keep) & conflicts["IID2"].isin(keep)).any()population.compare_table(excluded, "outputs/exclusions_r.tsv", ["IID", "remaining_neighbors"], ["remaining_degree", "missing_fraction"], 0)known = conflicts["pedigree_kinship"].gt(0.0884)fig, ax = plt.subplots(figsize=(9, 6))for selected, label, color in [(known, "Documented close relationship", "#167c80"), (~known, "KING conflict only", "#969ca3")]: ax.scatter(conflicts.loc[selected, "pedigree_kinship"], conflicts.loc[selected, "king_kinship"], s=13, color=color, label=label)ax.axhline(0.0884, linestyle="--", color="#9e4f22")ax.set(xlabel="Kinship implied by the available pedigree", ylabel="KING estimate on the preliminary sparse panel", title="Every accepted conflict pair before sample exclusions")ax.legend()fig.savefig("outputs/relatedness_python.png", dpi=160, bbox_inches="tight")plt.close(fig)discordant = int((known & conflicts["king_kinship"].le(0.0884)).sum())metrics = dict(input_samples=len(samples), retained_samples=len(retained), excluded_samples=len(excluded), conflict_pairs=len(conflicts), discordant_pairs=discordant, retained_conflicts=0)population.write_metrics(metrics)print(f"The rule retains {len(retained)} of {len(samples)} people.")print(f"It excludes {len(excluded)} people from " f"{len(conflicts)} conflict pairs.")print(f"The review records {discordant} pedigree pairs below the KING cutoff.")print("No retained pair violates either declared relatedness rule.")The rule retains 2574 of 3202 people.It excludes 628 people from 1267 conflict pairs.The review records 0 pedigree pairs below the KING cutoff.No retained pair violates either declared relatedness rule.
The dashed line marks the declared KING cutoff. A documented close pair remains in the conflict graph even when its estimate falls below that line.
Keep the exclusion boundary visible
Section titled “Keep the exclusion boundary visible”The primary workflow checks the retained genotypes again with PLINK’s KING cutoff calculation, which avoids relying only on rounded text estimates. It also checks every documented close pedigree pair against the retained list.
The final working PSAM clears parental fields only after these exclusions, so LD and PCA use all retained people. The original pedigree remains unchanged in the source fixture. Frequency reports explicitly include nonfounders before that working-file change.
Further reading
Section titled “Further reading”-
The manual defines kinship scaling and notes that pedigree records are ignored. Its warning about parents from different populations explains why a low estimate cannot cancel documented relatives.
-
Byrska-Bishop and colleagues, expanded 1000 Genomes cohort
The study explains the family structure in this high-coverage cohort. Those documented relationships remain relevant when a teaching analysis selects independent observations.