/
readPlink.R
38 lines (38 loc) · 1.53 KB
/
readPlink.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#' Read PLINK binary data
#'
#' Read PLINK binary data and save in gData format. This is a wrapper around
#' \code{\link[snpStats]{read.plink}} in the Bioconductor package
#' \code{snpStats}. This package needs to be installed for the function to
#' work.
#'
#' @param bed The name of the file containing the packed binary SNP genotype
#' data. It should have the extension .bed; If it doesn't, then this extension
#' will be appended.
#' @param bim The file containing the SNP descriptions. If not specified
#' \code{bed} is used with its file extension replaced by bim.
#' @param fam The file containing subject (and, possibly, family) identifiers.
#' This is basically a tab-delimited "pedfile". If not specified
#' \code{bed} is used with its file extension replaced by fam.
#' @param ... Further arguments passed to \code{\link[snpStats]{read.plink}}.
#'
#' @return An object of class \code{gData}.
#'
#' @importFrom methods as
#' @export
readPLINK <- function(bed,
bim,
fam,
...) {
if (!requireNamespace("snpStats", quietly = TRUE)) {
stop("Package snpStats needed for reading PLINK files.")
}
genoPLINK <- snpStats::read.plink(bed = bed, bim = bim, fam = fam, ...)
## Get makers.
markers <- as(genoPLINK$genotypes, "numeric")
## Get map.
map <- genoPLINK$map
names(map) <- c("chr", "snp.name", "cM", "pos", "allele.1", "allele.2")
# Create a gData object containing map and marker information.
res <- createGData(geno = markers, map = map)
return(res)
}