| gl.impute | R Documentation |
This function imputes genotypes on a population-by-population basis, where populations can be considered panmictic, or imputes the state for presence-absence data.
gl.impute(
x,
method = "neighbour",
fill.residual = TRUE,
parallel = FALSE,
beagle.bin.path = getwd(),
plink.bin.path = getwd(),
verbose = NULL
)
x |
Name of the genlight object containing the SNP or presence-absence data [required]. |
method |
Imputation method, either "frequency" or "HW" or "neighbour" or "random" or "beagle" [default "neighbour"]. |
fill.residual |
Should any residual missing values remaining after imputation be filled at random, drawing from the global allele profile at the particular locus (for presence-absence data, a Bernoulli draw with the global band frequency) [default TRUE]. |
parallel |
A logical indicating whether multiple cores -if available- should be used for the computations (TRUE), or not (FALSE); requires the package parallel to be installed [default FALSE]. |
beagle.bin.path |
Path of beagle.27Feb25.75f.jar file [default getwd()]. |
plink.bin.path |
Path of PLINK binary file [default getwd()]. |
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]. |
We recommend that imputation be performed on sampling locations, before any aggregation. Imputation is achieved by replacing missing values using either of five methods:
If "frequency", a genotype scored as missing at a locus in an individual is set deterministically from the allele frequencies at that locus in the population from which the individual was drawn. For SNP genotype data the imputed value is the expected genotype dosage 2q (q being the frequency of the alternate allele in that population) rounded to the nearest valid genotype (0, 1 or 2); exact ties (2q = 0.5 or 2q = 1.5) resolve to the heterozygote (1). For presence-absence data the imputed value is the more frequent band state (0 or 1) in the population; a tie (band frequency exactly 0.5) resolves to presence (1). This method involves no random draw – repeated runs give identical results (values filled by fill.residual remain random draws).
If "HW", a genotype scored as missing at a locus in an individual is drawn at random. For SNP genotype data the draw assumes Hardy-Weinberg equilibrium, using the genotype probabilities (p^2, 2pq, q^2) at that locus in the population. For presence-absence data the draw is Bernoulli with the band frequency at that locus in the population.
If "neighbour", substitute the missing values for the focal individual with the values taken from the nearest neighbour. Repeat with next nearest and so on until all missing values are replaced.
if "random", missing data are substituted by values drawn at random with equal probability from the valid genotypes (0, 1 or 2 for SNP genotype data; 0 or 1 for presence-absence data).
if "beagle", missing data is imputed using using BEAGLE (beagle.27Feb25.75f.jar), which infers missing genotypes by modelling shared haplotype patterns among individuals. Applies only to SNP genotype data. Beagle can be downloaded using the following link:
https://faculty.washington.edu/browning/beagle/beagle.html#download.
After downloading the Beagle binary move it to your working directory.
For method = "beagle" it is also required to download the binary file of PLINK 1.9 and move it to your working directory. The binary file can be downloaded from:
The spelling "neighbor" is accepted as an alias for "neighbour".
The nearest neighbour is the one at the smallest Euclidean distance from the focal individual.
The advantage of this approach is that it works regardless of how many individuals are in the population to which the focal individual belongs, and the displacement of the individual is haphazard as opposed to: (a) Drawing the individual toward the population centroid (HW and Frequency). (b) Drawing the individual toward the global centroid (glPCA).
Note that loci that are missing for all individuals in a population are not imputed with method 'frequency' or 'HW' and can give unpredictable results for particular individuals using 'neighbour'.
Consider using the function
gl.filter.allna with by.pop=TRUE to remove them first.
Loci scored NA across all individuals in the dataset cannot be imputed
from allele frequencies or neighbours: with methods 'frequency', 'HW' and
'neighbour' they remain NA in the returned object, regardless of
fill.residual (the global frequency at such loci is undefined). Method
'random' substitutes unconditioned random values at such loci. Use
gl.filter.allna (without by.pop) to remove them first.
File-backed objects (see gl.gen2fbm) are imputed in blocks
of loci, without decoding the whole genotype matrix; the block size
follows options(bigstatsr.block.sizeGB). The imputed genotypes are
written into a new backing file, and the input is left unchanged. The
result is identical to that for the same data held in memory, including
the random draws with the same seed (method 'HW' reads the file once per
population to keep that order). Method 'neighbour' holds the matrix of
distances between individuals in memory (8 bytes per pair, e.g. 32 Mb for
2,000 individuals). Method 'beagle' exports the data to a VCF file, which
decodes the genotypes.
A genlight object with the missing data imputed.
Author(s): Luis Mijangos. Custodian: Luis Mijangos – Post to https://groups.google.com/d/forum/dartr
Browning, B. L., & Browning, S. R. (2016). Genotype imputation with millions of reference samples. American Journal of Human Genetics, 98(1), 116-126. https://doi.org/10.1016/j.ajhg.2015.11.020
Other data manipulation:
gl.add.indmetrics(),
gl.define.pop(),
gl.drop.ind(),
gl.drop.loc(),
gl.drop.pop(),
gl.edit.recode.pop(),
gl.fbm.cleanup(),
gl.fbm2gen(),
gl.gen2fbm(),
gl.join(),
gl.keep.ind(),
gl.keep.loc(),
gl.keep.pop(),
gl.make.recode.ind(),
gl.make.recode.pop(),
gl.merge.pop(),
gl.reassign.ind(),
gl.reassign.pop(),
gl.recode.ind(),
gl.recode.pop(),
gl.rename.pop(),
gl.sample(),
gl.sim.genotypes(),
gl.sort(),
gl.subsample.ind(),
gl.subsample.loc(),
gl.subsample.loci()
require("dartR.data")
# SNP genotype data
if (isTRUE(getOption("dartR_fbm"))) platypus.gl <- gl.gen2fbm(platypus.gl)
gl <- gl.filter.callrate(platypus.gl,threshold=0.95)
gl <- gl.filter.allna(gl)
gl <- gl.impute(gl, method="frequency")
# Sequence Tag presence-absence data
gs <- gl.filter.callrate(testset.gs,threshold=0.95)
gs <- gl.filter.allna(gs)
gs <- gl.impute(gs, method="neighbour")
gl <- gl.impute(platypus.gl,method ="random")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.