gl2eigenstrat: Converts a genlight object into eigenstrat format

View source: R/gl2eigenstrat.r

gl2eigenstratR Documentation

Converts a genlight object into eigenstrat format

Description

The output of this function are three files:

  • genotype file: contains genotype data for each individual at each SNP with an extension 'eigenstratgeno.'

  • snp file: contains information about each SNP with an extension 'snp.'

  • indiv file: contains information about each individual with an extension 'ind.'

Usage

gl2eigenstrat(
  x,
  outfile = "gl_eigenstrat",
  outpath = NULL,
  snp.pos = 1,
  snp.chr = 1,
  pos.cM = 0,
  sex.code = "unknown",
  phen.value = "Case",
  verbose = NULL
)

Arguments

x

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

outfile

File name of the output file [default 'gl_eigenstrat'].

outpath

Path where to save the output file [default global working directory or if not specified, tempdir()].

snp.pos

Field name from the slot loc.metrics where the SNP position is stored; when left at the numeric sentinel 1, a constant position of 1 is written for every SNP [default 1].

snp.chr

Field name from the slot loc.metrics where the chromosome of each SNP is stored; when left at the numeric sentinel 1, a constant chromosome of 1 is written for every SNP [default 1].

pos.cM

A vector, with as many elements as there are loci, containing the SNP position in morgans or centimorgans; the default writes 0 (unknown) for every SNP [default 0].

sex.code

A vector, with as many elements as there are individuals, containing the sex code ('male', 'female', 'unknown') [default 'unknown'].

phen.value

A vector, with as many elements as there are individuals, containing the phenotype value ('Case', 'Control') [default 'Case'].

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].

Details

Each value in the genotype file is the number of copies of the reference allele – the first allele of loc.all, written in the fifth column of the snp file: 2 homozygous reference, 1 heterozygous, 0 homozygous alternate, 9 missing.

Eigenstrat only accepts chromosomes coded as numeric values, as follows: X chromosome is encoded as 23, Y is encoded as 24, mtDNA is encoded as 90, and XY is encoded as 91. Chromosome labels 'X', 'Y', 'MT'/'mtDNA' and 'XY' in the nominated field are mapped to this encoding; SNPs with illegal chromosome values (any other non-numeric label, or a value less than 1, such as 0) are removed, with a warning stating how many. If no locus has an encodable chromosome value, the function stops.

Value

returns no value (i.e. NULL)

Author(s)

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

References

  • Patterson, N., Price, A. L., & Reich, D. (2006). Population structure and eigenanalysis. PLoS genetics, 2(12), e190.

  • Price, A. L., Patterson, N. J., Plenge, R. M., Weinblatt, M. E., Shadick, N. A., & Reich, D. (2006). Principal components analysis corrects for stratification in genome-wide association studies. Nature genetics, 38(8), 904-909.

See Also

Other linker: gi2gl(), gl2bayesAss(), gl2bayescan(), gl2bpp(), gl2demerelate(), gl2faststructure(), gl2gapit(), gl2gds(), gl2genalex(), gl2genepop(), gl2geno(), gl2gi(), gl2hapmap(), gl2hiphop(), gl2related(), gl2snapper(), gl2structure(), gl2treemix(), gl2vcf()

Examples


require("dartR.data")
if (isTRUE(getOption("dartR_fbm"))) platypus.gl <- gl.gen2fbm(platypus.gl)
# The platypus chromosome labels (e.g. 'NC_041731.1_chromosome_4') cannot
# be encoded for Eigenstrat, so the chromosome field is left at its
# constant default
gl2eigenstrat(platypus.gl,snp.pos='ChromPos_Platypus_Chrom_NCBIv1',
outpath=tempdir())



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