BEDMatrix: Create a BEDMatrix Object from a PLINK .bed File

Description Usage Arguments Details Value See Also Examples

View source: R/BEDMatrix.R

Description

This function constructs a new BEDMatrix object by mapping the specified PLINK .bed file into memory.

Usage

1
BEDMatrix(path, n = NULL, p = NULL, simple_names = FALSE)

Arguments

path

Path to the .bed file (with or without extension).

n

The number of samples. If NULL (the default), this number will be determined from the accompanying .fam file (of the same name as the .bed file). If a positive integer, the .fam file is not read and rownames will be set to NULL and have to be provided manually.

p

The number of variants. If NULL (the default) the number of variants will be determined from the accompanying .bim file (of the same name as the .bed file). If a positive integer, the .bim file is not read and colnames will be set to NULL and have to be provided manually.

simple_names

Whether to simplify the format of the dimension names. If FALSE (the default), row names are concatenations of family IDs, _, and within-family IDs, while column names are concatenations of variant names, _, and allele codes for the first allele of the .bim file (A1). If TRUE, row names are within-family IDs only and column names are variant names only.

Details

.bed files must be accompanied by .fam and .bim files: .fam files contain sample information, and .bim files contain variant information. If the name of the .bed file is plink.bed then the names of the .fam and .bim files have to be plink.fam and plink.bim, respectively. The .fam and .bim files are used to extract the number and names of samples and variants.

For very large .bed files, reading the .fam and .bim files can take a long time. If n and p are provided, these files are not read and dimnames have to be provided manually.

Currently, only the variant-major mode of .bed files is supported. PLINK2 "dropped" support for the sample-major mode by automatically converting files in this format to the variant-major mode. Therefore, it is recommended to run files in sample-major mode through PLINK2 first.

Value

A BEDMatrix object.

See Also

BEDMatrix-package to learn more about the BEDMatrix package, BEDMatrix-class to learn more about the BEDMatrix class.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Get the path to the example .bed file
path <- system.file("extdata", "example.bed",
                    package = "BEDMatrix")

# Create a BEDMatrix object the example .bed file
m1 <- BEDMatrix(path)

# Create a BEDMatrix object the example .bed file without loading
# the .fam and .bim files
m2 <- BEDMatrix(path, n = 50, p = 1000)

Example output

Extracting number of samples and rownames from example.fam...
Extracting number of variants and colnames from example.bim...

BEDMatrix documentation built on July 8, 2020, 7:26 p.m.