BEDMatrix-class {BEDMatrix} | R Documentation |
A Class to Extract Genotypes from a PLINK .bed File
Description
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.
Details
The subsets extracted from a BEDMatrix
object are coded as the
allelic dosages of the first allele in the .bim file (A1), similarly to
.raw files
generated with the --recode A
argument in
PLINK).
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 mmap
on
Unix and MapViewOfFile
on Windows.
Slots
xptr
:-
An external pointer to the underlying
C
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
andp
parameters of theBEDMatrix
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 then
andp
parameters of theBEDMatrix
constructor function were provided. path
:-
A character string containing the path to the .bed file.
Methods
[
: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
See Also
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.
Examples
# 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")
]