View source: R/gl.report.contamination.r
| gl.report.contamination | R Documentation |
Flags individuals whose genotypes carry DNA from another sample, using two
tiers of evidence that need only the genotypes, the population labels and,
when available, the plate wells stored by gl.read.dart(). When the
genlight also holds the reads of each allele (from
gl.read.vcf(read.counts = TRUE)), a further tier tests the read
balance of each sample's heterozygous calls and names the two animals
whose DNA a mixed sample holds.
gl.report.contamination(
x,
rare.freq = 0.02,
min.n = 5,
z.flag = 3,
min.excess = 0.02,
rare.min.excess = 0.005,
min.share = 20,
share.tol = 0.05,
depth.ratio = 1.5,
depth.flat = 1.25,
min.reads = 20,
balance.cut = 0.25,
min.calls = 1000,
plate = NULL,
plot.display = TRUE,
plot.theme = theme_dartR(),
plot.colors = NULL,
plot.colors.pop = gl.colors("dis", verbose = 0),
plot.dir = NULL,
plot.file = NULL,
verbose = NULL,
...
)
x |
Name of the genlight object containing the SNP data [required]. |
rare.freq |
Allele frequency in the rest of the population below which an allele counts as rare; must lie in (0, 0.5) [default 0.02]. |
min.n |
Minimum number of other individuals in the population called at a locus for that locus to enter the rare-allele burden; at least 2 [default 5]. |
z.flag |
Robust z-score above which a statistic is an outlier [default 3]. |
min.excess |
Absolute amount by which heterozygosity must also exceed the population median to be flagged; a robust z-score alone over-flags populations whose members are nearly identical [default 0.02]. |
rare.min.excess |
The same absolute margin for the rare-allele burden, which is an order of magnitude smaller than heterozygosity [default 0.005]. |
min.share |
Minimum number of rare-allele loci an individual needs before its source is chosen by allele sharing rather than by residual kinship alone [default 20]. |
share.tol |
Sharing scores within this distance of the best are treated as ties and separated by residual kinship [default 0.05]. |
depth.ratio |
Foreign-allele rate in the deepest quartile of loci over the shallowest at or above which, with trend p below 0.01, the pattern is "dose" [default 1.5]. |
depth.flat |
The same ratio below which the pattern is "flat" [default 1.25]. |
min.reads |
Minimum number of reads (REF plus ALT) for a genotype to enter the read-balance test [default 20]. |
balance.cut |
Share of the reads below which the minority allele of a heterozygous call marks it as skewed; must lie in (0, 0.5] [default 0.25]. |
min.calls |
Minimum number of genotypes with at least
|
plate |
Data frame with columns id, plate and well (for example
"C4", in either case) giving plate positions; overrides positions found in the individual
metadata. Without it, positions come from |
plot.display |
If TRUE, resultant plots are displayed in the plot window [default TRUE]. |
plot.theme |
A ggplot2 theme for the plot, for example
|
plot.colors |
List of two color names, the first for suspect individuals and the second for the rest [default c("#2171B5","#6BAED6")]. |
plot.colors.pop |
A color palette for the plate map, or a vector with as many colors as there are populations [default gl.colors("dis")]. |
plot.dir |
Directory to save the plot RDS files [default as specified by the global working directory or tempdir()]. |
plot.file |
Name for the RDS binary file to save (base name only, exclude extension); the plate map is saved beside it with "_plate" appended [default NULL]. |
verbose |
Verbosity: 0, silent or fatal errors; 1, begin and end; 2, progress log; 3, progress and results summary; 5, full report [default NULL, adopting the global verbosity set by gl.set.verbosity(), or 2 if no global is set]. |
... |
Parameters passed to function ggsave, such as width and height, when the ggplot is to be saved. |
Tier 1 scores each individual against the other members of its own
population. Heterozygosity is the proportion of called loci scored
heterozygous. The rare-allele burden is the proportion of called loci at
which the individual carries an allele whose frequency among the other
members of its population is below rare.freq; loci with fewer than
min.n other individuals called are skipped. Both statistics are
reported as a robust z-score (median and MAD within the population) and as
a fold over the population median.
Tier 2 names the most likely source of the foreign DNA. For an individual
with at least min.share rare-allele loci, every other individual is
scored by the proportion of those rare alleles it carries (sharing). The
candidates within share.tol of the best score, which in practice are
the members of one population, are then separated by residual kinship: a
VanRaden genomic relationship matrix halved to kinship, with each pair
expressed as a residual over the median kinship of its population pair so
that within- and between-population pairs are on the same scale. For an
individual with too few rare alleles (contamination from its own
population, or a clean sample) the partner is simply the largest residual.
The partner's sharing score and its residual kinship z-score against that
individual's other residuals are reported. If plate positions are known,
the partner is tested for plate adjacency (same plate, wells sharing an
edge). Positions are taken from
plate if supplied, otherwise from the plate_location column
of @other$ind.metrics written by gl.read.dart() (for
example "1-C2"; the well is the part after the last "-"), otherwise from plate and well columns.
Flags. An individual is a "suspect" when its heterozygosity has z-score
above z.flag and exceeds the population median by more than
min.excess.
Contamination always raises heterozygosity, so this is the required
signal. A suspect whose top kinship partner sits in an adjacent well is
upgraded to "adjacent". An individual whose rare-allele burden is elevated
by the same criteria but whose heterozygosity is normal is reported as
"rare-only" (z-score above z.flag and excess above
rare.min.excess): this is the signature of population structure
inside the assigned population, or of a mislabelled individual, not of
contamination. An individual whose read balance marks it as a mixture
(tier 4) is "mixed", which replaces "suspect", "rare-only" or no flag but
not "adjacent", where the plate position already explains the cause.
Tier 3 asks whether a flagged individual's foreign alleles behave like a
minority of its reads or like half of them. A contaminant contributes a
small fraction of the DNA, so its alleles are called mainly at loci with
enough depth to catch a minority allele; a hybrid's alleles sit at 50
percent and are called at any depth. The test uses the loci fixed for one
allele in the individual's population (frequency below rare.freq
among its unflagged members) and for the other allele in its partner's
population (frequency at least 1 - rare.freq among its unflagged
members), so that every locus could show the foreign allele. Restricting
to such loci matters because deep loci are the conserved ones and would
otherwise dilute the rate; building the references from unflagged
animals matters because a second contaminated animal in the host
population would otherwise remove every locus at which it carries the
donor allele. foreign.rate is the proportion of these loci at
which the individual carries the foreign allele, the plain measure of
how much of the other population it holds.
These loci are split into quartiles of rdepth, the per-locus
average read depth that gl.read.dart() stores in
@other$loc.metrics, and the proportion of them at which the
individual carries the foreign allele is compared across quartiles.
depth.ratio is that proportion in the deepest quartile over the
shallowest (with a half count added to each), depth.p a
chi-squared test for trend across the four quartiles, and pattern
is "saturated" when the foreign allele is already called at more than
half of the shallowest quartile (a heavy mixture or an F1 hybrid, which
depth cannot separate), "dose" when the ratio is at least
depth.ratio with p below 0.01 (a contaminant), "flat" when the
ratio is below depth.flat (a true heterozygote: hybrid, admixed
or mislabelled animal) and "unclear" between. The pattern is computed
for flagged individuals whose partner is in another population, with at
least 80 such loci and min.share foreign alleles among them, and
is NA otherwise or when the genlight has no rdepth; contamination
from the individual's own population, or from a population absent from
the dataset, cannot be tested this way. Read the pattern only when host
and partner are close enough for a hybrid to be plausible: across
species the plate-average depth is a poor proxy for the host's own depth,
and a "flat" call does not clear an animal whose foreign alleles are
fixed-absent in its species.
Locus average depth is a proxy for the individual's own read counts, so
the pattern does not change the flag; the decisive test remains allele
balance from per-individual read counts (tier 4).
Tier 4 uses the reads of each allele at each genotype, which
gl.read.vcf(read.counts = TRUE) stores in
@other$geno.metrics; without them its columns are NA. In a clean
sample the reads of a heterozygote split near 50:50. DNA from a second
animal adds heterozygous calls whose minority allele is carried by few
reads, and it does so even when both animals come from the same
population, where tiers 1 to 3 have little power. For each individual, the
genotypes called with at least min.reads reads are counted
(read.calls); skew.rate is the number of heterozygous calls
among them whose minority allele has less than balance.cut of the
reads, per 1,000 such genotypes. The rate is used rather than the share of
heterozygous calls that are skewed, because the share is inflated in
samples with few heterozygous calls, where genotyping errors make up much
of them. skew.z is a robust z-score across all individuals with at
least min.calls such genotypes, not within populations, because
read balance does not depend on population; individuals with fewer are not
screened, so a contaminated sample of low depth can be missed. The z-score
is relative to the cohort: when many samples are mixed (for example a
whole plate), the median and MAD rise and sensitivity falls. An individual
with skew.z above z.flag is "mixed".
For a mixed individual the function then looks for the two sources of its
DNA. main.source is the individual, other than mixed ones, with the
largest residual kinship to it. main.kin gives their kinship: a
duplicate is near 0.5, a mixed sample's extra heterozygous calls lower it
(0.39 for a sample with about 16 percent foreign DNA), and a first-degree
relative is near 0.25. Mixed individuals are excluded
so that a second library of the same DNA is not named. The extra sites are
those at which the individual is heterozygous and main.source
homozygous, both with at least min.reads reads; n.extra
counts them, and extra.share is the median share of the
individual's reads carried there by the allele main.source lacks.
The source columns below need min.share extra sites, and they are
left NA when extra.share is 0.35 or more: main.source is
then not the major genome of the sample (for example a relative, when that
genome is not in the dataset), and the extra sites hold the sample's own
heterozygotes. second.source is the individual, other than the
sample, main.source and mixed individuals, that carries the extra
allele at the largest share of the extra sites (second.share);
second.next is the best runner-up that is not a replicate of
second.source (identical genotypes at 90 percent or more of the
loci called in both), and second.gap the difference between their
shares. mix.fraction, the share of the sample's DNA that came from
second.source, is the median read share of the extra allele at the
extra sites where second.source is homozygous for it (at least 20
sites). It reads a little high for small fractions, because only reads
that produced a heterozygous call are counted.
Limits. The screen is a candidate list, not a verdict. Contamination from the same population as the host raises only heterozygosity and kinship, so a low rare-allele burden does not clear a suspect, and a population whose members differ widely in heterozygosity (inbreeding, admixture, relatives) can yield suspects that are not contaminated. Power falls as host and contaminant become genetically closer: a mixture between two populations of one species at a typical heterozygosity of 0.3 shifts heterozygosity by less than the natural spread of many populations. Tier 2 can only name a source that is in the dataset.
A file-backed (FBM) object is read from its backing file in blocks of
loci, and by individual for the suspects examined in tiers 3 and 4; the
genotype matrix is never decoded as a whole, and the results are
identical to those of the same data held in memory. The kinship matrix
(8 bytes per pair of individuals) is held in memory, as are read counts
in other$geno.metrics.
The plot shows heterozygosity against rare-allele burden with suspects
labelled. When plate positions are known, a second plot maps each plate
that holds a suspect: wells are filled by population, and a suspect's well
is ringed in the colour of its partner's population, solid with an arrow
from the partner when the partner sits in an adjacent well and dashed
otherwise, and labelled with its foreign.rate as a percentage and
its pattern, so that a hybrid next to its partner is not read as a
contaminant.
A list with three elements: ind, a data frame with one row
per individual holding the tier 1 and tier 2 statistics (including
n.foreign, the number of rare-allele loci, and share, the
partner's sharing score), the tier 3 columns foreign.rate,
depth.ratio,
depth.p and pattern, the tier 4 columns read.calls,
skew.rate, skew.z, main.source, main.kin,
n.extra, extra.share, second.source,
second.share, second.next, second.gap and
mix.fraction, and the flag;
pairs, a data frame of plate-adjacent pairs with their kinship and
residual kinship, or NULL when no plate positions are known; and
kinship, the matrix of residual kinship.
Author(s): Luis Mijangos. Custodian: Luis Mijangos – Post to https://groups.google.com/d/forum/dartr
gl.filter.contamination,
gl.report.heterozygosity,
gl.filter.heterozygosity
Other matched report:
gl.report.allna(),
gl.report.callrate(),
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.replicates.KING(),
gl.report.reproducibility(),
gl.report.secondaries(),
gl.report.taglength()
if (isTRUE(getOption("dartR_fbm"))) testset.gl <- gl.gen2fbm(testset.gl)
out <- gl.report.contamination(testset.gl)
head(out$ind)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.