gl2plink: Converts a genlight object into PLINK format

View source: R/gl2plink.r

gl2plinkR Documentation

Description

This function exports a genlight object into PLINK format and save it into a file. By default it produces two files: a .ped file (which embeds the six sample columns of the .fam format) and a .map file. With bed.files = TRUE and an external PLINK 1.9 binary, the binary .bed, .bim and .fam files are also produced.

Usage

gl2plink(
  x,
  plink.bin.path = getwd(),
  bed.files = FALSE,
  outfile = "gl_plink",
  outpath = NULL,
  chr.format = "character",
  pos.cM = "0",
  ID.dad = "0",
  ID.mum = "0",
  sex.code = "unknown",
  phen.value = "0",
  verbose = NULL
)

Arguments

x

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

plink.bin.path

Path of PLINK binary file [default getwd()].

bed.files

Whether create PLINK files .bed, .bim and .fam [default FALSE].

outfile

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

outpath

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

chr.format

Whether chromosome information is stored as 'numeric' or as 'character', see details [default 'character'].

pos.cM

A vector, with as many elements as there are loci, containing the SNP position in morgans or centimorgans [default '0'].

ID.dad

A vector, with as many elements as there are individuals, containing the ID of the father, '0' if father isn't in dataset [default '0'].

ID.mum

A vector, with as many elements as there are individuals, containing the ID of the mother, '0' if mother isn't in dataset [default '0'].

sex.code

A vector, with as many elements as there are individuals, containing the sex code ('male', 'female', 'unknown'). Sex information needs just to start with an "F" or "f" for females, with an "M" or "m" for males and with a "U", "u" or being empty if the sex is unknown [default 'unknown'].

phen.value

A vector, with as many elements as there are individuals, containing the phenotype value. '1' = control, '2' = case, '0' = unknown [default '0'].

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

To create PLINK files .bed, .bim and .fam (bed.files = TRUE), it is necessary to download the binary file of PLINK 1.9 and provide its path (plink.bin.path). The binary file can be downloaded from: https://www.cog-genomics.org/plink/

After downloading, unzip the file, access the unzipped folder and move the binary file ("plink") to your working directory.

If you are using a Mac, you might need to open the binary first to grant access to the binary.

The chromosome of each SNP can be a character or numeric. The chromosome information for unmapped SNPS is coded as 0.

If the accessors x$chromosome and x$position are unset (NULL), the loci are treated as unmapped: chromosome and base-pair position are written as 0, PLINK's own convention, and a warning is given. Note also that if x$position holds within-tag offsets (as when read directly from a DArT report, values typically < 70) rather than genomic coordinates, those offsets are written to the .map as base-pair positions; assign genomic coordinates before calling if downstream position-aware PLINK operations are intended.

Family ID is taken from x$pop.

Within-family ID (cannot be '0') is taken from indNames(x).

Variant identifier is taken from locNames(x).

SNP position is taken from the accessor x$position.

Chromosome name is taken from the accessor x$chromosome

Note that if names of populations or individuals contain spaces, they are replaced by an underscore "_".

If you like to use chromosome information when converting to plink format and your chromosome names are not from human, you need to change the chromosome names as 'contig1', 'contig2', etc. as described in the section "Nonstandard chromosome IDs" in the following link: https://www.cog-genomics.org/plink/1.9/input

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

Purcell, Shaun, et al. 'PLINK: a tool set for whole-genome association and population-based linkage analyses.' The American journal of human genetics 81.3 (2007): 559-575.

See Also

Other linkers: gl2paup.parsimony(), gl2paup.svdquartets(), gl2phylip()

Examples


require("dartR.data")
if (isTRUE(getOption("dartR_fbm"))) platypus.gl <- gl.gen2fbm(platypus.gl)
test <- platypus.gl
# assigning SNP position
test$position <- test$other$loc.metrics$ChromPos_Platypus_Chrom_NCBIv1
# assigning a dummy name for chromosomes
test$chromosome <- as.factor("1")
gl2plink(test, outpath=tempdir())



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