Last data update: 2014.03.03

R: Data input
read.bedR Documentation

Data input

Description

Loads genotype data from plink format files .bed, .bim, and .fam.

Usage

read.bed(bed, bim, fam, sel.snps = NULL, sel.subs = NULL, encode012 = TRUE)

Arguments

bed

the name of the bed file.

bim

the name of the bim file.

fam

the name of the fam file.

sel.snps

a character vector of SNPs to be extracted from the plink files. The default is NULL, i.e., all SNPs are extracted.

sel.subs

an optional character vector specifying a subset of subject IDs to be extracted from the plink files. These IDs should be matched with the second column of fam files. The default is NULL, i.e., all subjects are extracted.

encode012

logical. Encoding the genotypes using 0/1/2 if TRUE, or using symbols of the reference and effect alleles if FALSE. The default is TRUE.

Value

A data frame of genotypes of specified subjects in the plink files.

Examples


# Load the sample data

bed <- system.file("extdata", package = 'ARTP2', 'chr1.bed')
bim <- system.file("extdata", package = 'ARTP2', 'chr1.bim')
fam <- system.file("extdata", package = 'ARTP2', 'chr1.fam')

## first five SNPs
b <- read.table(bim, header = FALSE, as.is = TRUE, nrows = 5)
## first 50 subjects
f <- read.table(fam, header = FALSE, as.is = TRUE, nrows = 50)
geno <- read.bed(bed, bim, fam, sel.snps = b[, 2], sel.subs = f[, 2])

dim(geno) # 50 x 5


Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(ARTP2)
Loading required package: Formula
Loading required package: data.table
Loading required package: parallel
> png(filename="/home/ddbj/snapshot/RGM3/R_CC/result/ARTP2/read.bed.Rd_%03d_medium.png", width=480, height=480)
> ### Name: read.bed
> ### Title: Data input
> ### Aliases: read.bed
> 
> ### ** Examples
> 
> 
> # Load the sample data
> 
> bed <- system.file("extdata", package = 'ARTP2', 'chr1.bed')
> bim <- system.file("extdata", package = 'ARTP2', 'chr1.bim')
> fam <- system.file("extdata", package = 'ARTP2', 'chr1.fam')
> 
> ## first five SNPs
> b <- read.table(bim, header = FALSE, as.is = TRUE, nrows = 5)
> ## first 50 subjects
> f <- read.table(fam, header = FALSE, as.is = TRUE, nrows = 50)
> geno <- read.bed(bed, bim, fam, sel.snps = b[, 2], sel.subs = f[, 2])
> 
> dim(geno) # 50 x 5
[1] 50  5
> 
> 
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>