gl.report.replicates.KING: Identifies duplicate samples by KING-robust kinship

View source: R/gl.report.replicates.KING.r

gl.report.replicates.KINGR Documentation

Identifies duplicate samples by KING-robust kinship

Description

Scans a genlight object for duplicate samples (two libraries of one animal) by KING-robust kinship and the heterozygote share, computed from genotype likelihoods, read counts or called genotypes, and suggests which sample of each group of duplicates to remove. Unlike the identity screen of gl.report.replicates, it also finds duplicates in which one sample is poor: missed heterozygotes in a poor sample lower the share of identical genotypes, but much less so the kinship estimated from likelihoods or the heterozygote share.

Usage

gl.report.replicates.KING(
  x,
  input = c("auto", "likelihoods", "counts", "calls"),
  error_rate = 0.001,
  maf = 0.05,
  loc_threshold = 100,
  king_threshold = 0.354,
  het_threshold = 0.8,
  plot.out = TRUE,
  plot_theme = theme_dartR(),
  plot_colors = c("#2171B5", "#6BAED6"),
  bins = 100,
  verbose = NULL
)

Arguments

x

Name of the genlight object containing the SNP data [required].

input

Data the kinship is computed from: "likelihoods" (the genotype likelihoods kept by gl.read.vcf(likelihoods = TRUE)), "counts" (the read counts kept by gl.read.vcf(read.counts = TRUE)), "calls" (the called genotypes) or "auto", the first of these the object holds [default "auto"].

error_rate

Sequencing error rate of the binomial likelihoods built from read counts; used only with read counts [default 0.001].

maf

Minimum minor allele frequency of the loci used [default 0.05].

loc_threshold

Minimum number of loci two samples must share for their pair to be assessed [default 100].

king_threshold

KING-robust kinship above which a pair is a duplicate [default 0.354].

het_threshold

Heterozygote share above which a pair is a duplicate; used only with called genotypes (see details) [default 0.80].

plot.out

If TRUE, the plot is produced and returned; it is also printed unless verbose is 0 [default TRUE].

plot_theme

User specified theme [default theme_dartR()].

plot_colors

Vector with two colour names: flagged pairs and other pairs in the scatter plot, borders and fill of the histogram [default c("#2171B5", "#6BAED6")].

bins

Number of bins of the histogram [default 100].

verbose

Verbosity: 0, silent or fatal errors; 1, begin and end; 2, progress log; 3, progress and results summary; 5, full report [default 2, unless specified using gl.set.verbosity].

Details

Pair statistics

At each locus the genotypes of two samples (0, 1 or 2 copies of the ALT allele) fall into nine combinations, A to I (Waples et al. 2019; rows are the first sample, columns the second):

0 1 2
0 A D G
1 B E H
2 C F I

From their counts over the loci the two samples share, the function reports KING-robust kinship, (E - 2(C + G)) / (B + D + H + F + 2E) (Manichaikul et al. 2010); R0 = (C + G) / E and R1 = E / (B + C + D + F + G + H) (Waples et al. 2019); and the heterozygote share, E / min(B + E + H, D + E + F): among the loci where the sample with fewer heterozygous calls is heterozygous, the share where the other is heterozygous too. None of them needs allele frequencies.

With called genotypes the counts are tallied directly. With genotype likelihoods or read counts they are the expected counts of the two-dimensional site frequency spectrum of the pair, estimated by EM from the likelihoods as in NgsRelate (Hanghøj et al. 2019), so that a heterozygote missed at low depth counts as uncertain rather than as a homozygote. Likelihoods are 10^(-PL/10); from read counts R (REF) and A (ALT) they are (1 - e)^R e^A, 0.5^(R + A) and e^R (1 - e)^A for 0/0, 0/1 and 1/1, with e = error_rate. The EM runs in C++ (Rcpp and RcppParallel), compiled the first time the function is called in a session, which takes a little while.

Only loci with a minor allele frequency of at least maf are used: from genotype likelihoods the frequency is estimated by EM, as in NgsRelate; otherwise it is taken from the called genotypes. Pairs that share fewer than loc_threshold of these loci get NA and are never flagged.

Duplicates

A pair is flagged as a duplicate when its KING-robust kinship exceeds king_threshold. From called genotypes it is also flagged when its heterozygote share exceeds het_threshold. The heterozygote share guards against heterozygote dropout, which turns heterozygotes into homozygotes and rarely the reverse: conditioning on the heterozygous calls of the poorer sample cancels its dropout. In an outbred population it is expected to be about 1 for duplicates, 0.5 for parent and offspring, at most 0.625 for full siblings and 2pq for unrelated pairs; inbreeding and population structure can raise these values. From called genotypes, KING-robust kinship underestimates duplicates in which a sample has heterozygote dropout; the heterozygote share corrects for dropout in the poorer sample of a pair, but not when both samples are poor, so use genotype likelihoods where possible. With genotype likelihoods or read counts the heterozygote share is reported but does not flag pairs, as the EM already accounts for missed heterozygotes. In a ddRAD study of collared peccaries (102 duplicate pairs by KING from likelihoods), the heterozygote share raised the duplicates found from called genotypes from 88 to 94, added none from likelihoods, and from read counts added a pair of relatives at 0.802.

Run gl.report.contamination (and remove contaminated samples with gl.filter.contamination) before this function. The rule below keeps the sample with the fewest missing genotypes, which favours a contaminated sample, as mixed DNA gives more calls: in the peccary study the pair CP47-CP57 keeps CP57, a mixture of about 4/5 CP47 and 1/5 CP46.

Flagged pairs are linked into groups (connected components). In each group the sample with the lowest proportion of missing genotypes is kept (ties keep the name that sorts first) and the others are suggested for removal. A group can also link two different animals through a sample that is a mixture of them (contamination, see gl.report.contamination); the function warns and lists the pairs in a group that are not flagged themselves, which should be checked before samples are removed.

Kinship classes

Each pair gets a class from the KING bins of Manichaikul et al. (2010): first degree above 0.177, second degree above 0.0884, third degree above 0.0442 and unrelated otherwise; flagged pairs are "duplicate", including those flagged only by the heterozygote share. KING-robust kinship assumes a single population: between divergent lineages it is strongly negative (values down to -3 are expected), which still means unrelated.

Plot

The top panel plots every pair by KING-robust kinship and heterozygote share, with dashed lines at king_threshold, at 0.177 and, when it is used, at het_threshold; flagged pairs are labelled when there are 30 or fewer and package ggrepel is installed. The kinship axis is cut at -1, and a caption gives the number of pairs below it. Duplicates sit to the right (from likelihoods) or at the top (from calls with dropout). The bottom panel is a histogram of the statistic that separates duplicates: the kinship of the pairs above 0, with the bounds of the classes, or, from called genotypes, the heterozygote share of the pairs above 0.4, with lines at 0.5 (parent and offspring), 0.625 (the largest expected for full siblings in an outbred population) and het_threshold. A gap between the relatives and the duplicates means the duplicate calls are clear-cut.

A file-backed (FBM) object (called genotypes) is read from its backing file in blocks of loci: missing data, allele frequencies and the counts of the nine genotype combinations are added block by block, so the genotype matrix is never decoded as a whole, and the results are identical to those of the same data held in memory.

Value

A list, returned invisibly, with:

  • table.rep: the flagged pairs, with their statistics, class, group, the proportion of missing genotypes of each sample (ind1_miss, ind2_miss) and ind_to_drop, the sample of the pair with more missing genotypes (ties: the name that sorts last). In a group where every pair is flagged, ind_to_drop lists exactly ind.list.drop.

  • ind.list.drop: the samples suggested for removal.

  • ind.list.rep: for each sample in a flagged pair, its duplicates.

  • table.all: every pair (ind1 before ind2 in the object), with nloc (shared loci), KING, R0, R1, het_share, class and flagged.

  • ind.miss: the proportion of missing genotypes of each sample.

  • input: the data used, "likelihoods", "counts" or "calls".

  • parameters: the thresholds; het_threshold_used, TRUE when het_threshold flagged pairs (called genotypes only); and n.sites, the number of loci that passed maf.

  • plot: the plot (a patchwork of two ggplots), or NULL when plot.out = FALSE.

Author(s)

Author(s): Luis Mijangos. Custodian: Luis Mijangos – Post to https://groups.google.com/d/forum/dartr

References

  • Hanghøj K, Moltke I, Andersen PA, Manica A, Korneliussen TS (2019) Fast and accurate relatedness estimation from high-throughput sequencing data in the presence of inbreeding. GigaScience 8: giz034.

  • Manichaikul A, Mychaleckyj JC, Rich SS, Daly K, Sale M, Chen WM (2010) Robust relationship inference in genome-wide association studies. Bioinformatics 26: 2867-2873.

  • Waples RK, Albrechtsen A, Moltke I (2019) Allele frequency-free inference of close familial relationships from genotypes or low-depth sequencing data. Molecular Ecology 28: 35-48.

See Also

gl.filter.replicates.KING, gl.report.replicates, gl.read.vcf

Other matched report: gl.report.allna(), gl.report.callrate(), gl.report.contamination(), gl.report.excess.het(), gl.report.factorloadings(), gl.report.fstat(), gl.report.hamming(), gl.report.heterozygosity(), gl.report.hwe(), gl.report.ld(), gl.report.ld.map(), gl.report.locmetric(), gl.report.maf(), gl.report.overshoot(), gl.report.pa(), gl.report.rdepth(), gl.report.replicates(), gl.report.reproducibility(), gl.report.secondaries(), gl.report.taglength()

Examples


if (isTRUE(getOption("dartR_fbm"))) platypus.gl <- gl.gen2fbm(platypus.gl)
res <- gl.report.replicates.KING(platypus.gl)
head(res$table.all)



dartR.base documentation built on Nov. 18, 2026, 9:06 a.m.