BEDMatrix-class {BEDMatrix} | R Documentation |
BEDMatrix
is a class that maps a
PLINK .bed file
into memory and behaves similarly to a regular matrix
by
implementing key methods such as [
, dim
, and dimnames
.
Subsets are extracted directly and on-demand from the .bed file without
loading the entire file into memory.
The subsets extracted from a BEDMatrix
object are coded similarly to
.raw files
(generated with the --recodeA
argument in
PLINK): 0
indicates
homozygous major allele, 1
indicates heterozygous, and 2
indicates homozygous minor allele.
Internally, this class is an S4 class with the following slots that should
not be relied upon in actual code: xptr
, dims
, dnames
,
and path
. The .bed file is mapped into memory using the Rcpp
package and the Boost.Interprocess
library provided by the BH
package.
xptr
:An external pointer to the underlying Rcpp
code.
dims
:An integer vector specifying the number of samples and variants as
determined by the the accompanying
.fam and
.bim files
or by the n
and p
parameters of the BEDMatrix
constructor function.
dnames
:A list describing the row names and column names of the object as
determined by the accompanying
.fam and
.bim files,
or NULL
if the n
and p
parameters of the
BEDMatrix
constructor function were provided.
path
:A character string containing the path to the .bed file.
[
:Extract parts of an object
dim
:Retrieve the dimension of an object
dimnames
:Retrieve the dimnames of an object
dimnames<-
:Set the dimnames of an object
as.matrix
:Turn the object into a matrix
is.matrix
:Test if the object is a matrix
length
:Get the length of an object
str
:Display the internal structure of an object
show
:Display the object
BEDMatrix
to create a BEDMatrix
object from a .bed
file, BEDMatrix-package
to learn more about the
BEDMatrix
package,
LinkedMatrix
to link
several BEDMatrix
objects together.
Rcpp-package
and BH-package
for more
details on the Rcpp
and BH
packages.
# Get the path to the example .bed file path <- system.file("extdata", "example.bed", package = "BEDMatrix") # Create a BEDMatrix object the example .bed file m <- BEDMatrix(path) # Get the dimensions of the BEDMatrix object dim(m) # Get the row names of the BEDMatrix object rownames(m) # Get the column names of the BEDMatrix object colnames(m) # Extract genotypes for the specified sample(s) m[1, ] m[1:3, ] m["per0_per0", ] m[c("per0_per0", "per1_per1", "per2_per2"), ] # Extract genotypes for a particular variant m[, 1] m[, c("snp0_A", "snp1_C", "snp2_G")] # Extract genotypes for the specified samples and variants m[ c("per0_per0", "per1_per1", "per2_per2"), c("snp0_A", "snp1_C", "snp2_G") ]