allele_freqs: Compute locus allele frequencies

Description Usage Arguments Value Examples

View source: R/allele_freqs.R

Description

On a regular matrix, this is essentially a wrapper for colMeans or rowMeans depending on loci_on_cols. On a BEDMatrix object, the locus allele frequencies are computed keeping memory usage low.

Usage

1
allele_freqs(X, loci_on_cols = FALSE, mem_factor = 0.7, mem_lim = NA)

Arguments

X

The genotype matrix (regular R matrix or BEDMatrix object). Missing values are ignored in averages.

loci_on_cols

If TRUE, X has loci on columns and individuals on rows; if false (the default), loci are on rows and individuals on columns. If X is a BEDMatrix object, columns are averaged to yield locus allele frequencies (regardless of the value of loci_on_cols).

mem_factor

BEDMatrix-specific, sets proportion of available memory to use loading genotypes. Ignored if mem_lim is not NA.

mem_lim

BEDMatrix-specific, sets total memory to use loading genotypes, in GB. If NA (default), a proportion mem_factor of the available memory will be used.

Value

The vector of allele frequencies, one per locus. Names are set to the locus names, if present.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# Construct toy data
X <- matrix(
    c(0, 1, 2,
      1, 0, 1,
      1, NA, 2),
    nrow = 3,
    byrow = TRUE
)

# row means
allele_freqs(X)
c(1/2, 1/3, 3/4)

# col means
allele_freqs(X, loci_on_cols = TRUE)
c(1/3, 1/4, 5/6)

OchoaLab/simtrait documentation built on Oct. 18, 2019, 5:42 a.m.