View source: R/gl.read.PLINK.r
| gl.read.PLINK | R Documentation |
This function imports PLINK data into a genlight object and append available metadata.
gl.read.PLINK(
filename,
ind.metafile = NULL,
loc.metafile = NULL,
plink.cmd = "plink",
plink.path = "path",
fbm = FALSE,
plink.flags = NULL,
verbose = NULL
)
filename |
Fully qualified path to PLINK input file (without including the extension) [required]. |
ind.metafile |
Name of the csv file containing the metrics for individuals [default NULL]. |
loc.metafile |
Name of the csv file containing the metrics for loci [default NULL]. |
plink.cmd |
The 'name' to call plink. This will depend on the file name (without the extension '.exe' if on windows) or the name of the PATH variable |
plink.path |
The path where the executable is. If plink is listed in the PATH then there is no need for this. This is what the option "path" means |
fbm |
Logical. If TRUE, the genotypes of the returned object are held
in a file-backed matrix (fbm) in its @fbm slot rather than in @gen. This
is useful for very large datasets that do not fit into RAM. A binary
fileset (.bed) is read in blocks of SNPs straight into the file-backed
matrix, so the genotypes are never held in memory as a whole; with
fbm = FALSE that matrix is converted to @gen in blocks of loci at the
end. A .ped is read into memory and converted when fbm = TRUE. Note that
using fbm objects requires the package bigsnpr to be installed. To back
convert use |
plink.flags |
additional parameters passed on to PLINK when a .ped
is converted with |
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]. |
This function handles either a binary fileset (.bed with its
.bim and .fam) or a text fileset (.ped, optionally with its .map). Both
are read in R; no PLINK executable is needed. Without a .map, loci are
named locus.1, locus.2, ... and chromosome and position are set to NA.
Loci are returned in file order (note that plink --make-bed sorts
loci by chromosome and position, so a .ped read directly and the .bed
PLINK writes from it can differ in locus order). PLINK's chromosome code
0 (unmapped) is returned as NA on both routes.
The only case that still calls PLINK is when plink.flags is given:
the .ped/.map are then converted with plink --make-bed and those
flags in a temporary directory, so no files are written into the input
directory.
Genotypes are coded as the count of allele.2 (column 6 of the
.bim file, the major allele under PLINK 1.x defaults): 0 = homozygous
allele.1, 2 = homozygous allele.2. The alleles are stored
as "allele.1/allele.2" (see alleles()), so the counted
allele is the second one, as for every dartR object; a missing allele
(PLINK code 0, e.g. for a monomorphic locus) is written as 0. Note that
this is the
opposite orientation to gl.read.vcf, which counts the ALT
allele.
Additional metadata can be included passing .csv files. These will be appended to the existing metadata present in the PLINK files.
The locus metadata needs to be in a csv file with headings, with a mandatory column headed AlleleID corresponding exactly to the locus identity labels provided with the SNP data.
The individual metadata needs a mandatory column headed id whose entries match the individual labels in the PLINK .fam file; rows are matched to individuals by id, so their order in the file does not matter. If a pop column is present it is used to assign populations.
A genlight object with the SNP data and associated metadata included.
Author(s): Carlo Pacioni. Custodian: Carlo Pacioni – Post to https://groups.google.com/d/forum/dartr
Other io:
gl.load(),
gl.read.csv(),
gl.read.dart(),
gl.read.fasta(),
gl.read.silicodart(),
gl.save(),
gl.write.csv(),
utils.read.dart()
# Create a small PLINK binary fileset (4 individuals x 4 SNPs) and read it
base <- file.path(tempdir(), "toy")
writeLines(c("1\tsnp1\t0\t100\tG\tA", "1\tsnp2\t0\t200\tT\tG",
"2\tsnp3\t0\t150\tA\tC", "2\tsnp4\t0\t300\tC\tT"),
paste0(base, ".bim"))
writeLines(c("FAM1 ind1 0 0 1 1", "FAM1 ind2 0 0 2 1",
"FAM2 ind3 0 0 1 2", "FAM2 ind4 0 0 2 2"),
paste0(base, ".fam"))
writeBin(as.raw(c(0x6c, 0x1b, 0x01, 0xcb, 0x2f, 0xab, 0xb7)),
paste0(base, ".bed"))
gl <- gl.read.PLINK(base, verbose = 0)
as.matrix(gl)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.