A matrix-like data structure that allows for efficient, convenient, and scalable subsetting of binary genotype/phenotype files generated by PLINK (< https://www.cog-genomics.org/plink2>), the whole genome association analysis toolset, without loading the entire file into memory.
BEDMatrix is an R package that provides a matrix-like wrapper around .bed, one of the genotype/phenotype file formats of PLINK, the whole genome association analysis toolset. BEDMatrix objects are created in R by simply providing the path to a .bed file and once created, they behave similarly to regular matrices with the advantage that genotypes are retrieved on demand without loading the entire file into memory. This allows handling of very large files with limited use of memory.
This package is deliberately kept simple. For computational methods that use BEDMatrix check out the BGData package.
This example uses a dummy .bed file that is bundled with this R package. It was generated using
plink --dummy 500 1000 0.02 acgt --seed 4711 --out example with PLINK 1.90 beta 3.452.
To get the path to the example .bed file (
system.file finds the full file names of files in packages and is only used to find the example data):
To wrap the example .bed file in a BEDMatrix object:
> m <- BEDMatrix(path)Extracting number of samples and rownames from FAM file...Extracting number of variants and colnames from BIM file...
To get the dimensions of the BEDMatrix object:
> dim(m) 50 1000
To extract a subset of the BEDMatrix object:
> m[1:3, 1:5]snp0_A snp1_C snp2_G snp3_G snp4_Gper0_per0 0 1 1 1 0per1_per1 1 1 1 1 NAper2_per2 1 0 0 2 0
To get the current released version from CRAN:
To get the current development version from GitHub:
Further documentation can be found on RDocumentation.
colnamesduring initialization if
data.tablepackage is installed.
pathwithout extension (like PLINK).
pathattribute (to reattach instance after saving it to RData).
dimsattribute to allow for faster recreation when saved.
Boost.IOStreamsin favor of
Boost.Interprocesswhich provides header-only memory-mapping and is therefore supported by the