maf: Function to compute minor allele frequencies

View source: R/maf.R

mafR Documentation

Function to compute minor allele frequencies

Description

Function maf computes the minor allele frequency for a matrix or vector of genotype counts.

Usage

maf(x, option = 1, verbose = FALSE) 

Arguments

x

a vector or matrix of with genotype counts

option

determines output that is returned. option=1 calculates the minor allele frequency; option=2 returns all allele frequencies; option=3 returns the allele counts.

verbose

be silent (verbose=FALSE) or not.

Value

a vector of minor allele frequencies or minor allele counts.

Author(s)

Jan Graffelman (jan.graffelman@upc.edu)

See Also

mac, MakeCounts

Examples

#
# MAF of a single random marker
#
set.seed(123)
X <- as.vector(rmultinom(1,100,c(0.5,0.4,0.1)))
names(X) <- c("AA","AB","BB")
print(X)
print(maf(X))
#
# MAF of MN bloodgroup counts
#
x <- c(MM=298,MN=489,NN=213)
maf(x)
#
# Both allele frqeuencies, ordered from minor to major
#
maf(x,2)
#
# allele counts of MN bloodgroup counts, order from minor to major
#
maf(x,3)
#
# MAF of single triallelic marker in triangular format
#
x <- c(AA=20,AB=52,AC=34,BB=17,BC=51,CC=26)
print(x)
GT <- toTriangular(x)
print(GT)
maf(GT)
#
# extract all allele frequencies
#
maf(GT,option=2)
#
# extract all allele counts
#
maf(GT,option=3)
#
# Calculate the MAF for 10 random SNPs under HWE
#
set.seed(123)
Z <- HWData(nm=10)
print(Z)
#
# vector with minor allele frequencies, one per marker
#
maf(Z)
#
# Matrix with minor and major allele frequencies, one row per marker 
#
maf(Z,2)
#
# Matrix with minor and major allele count, one row per marker 
#
maf(Z,3)

HardyWeinberg documentation built on May 29, 2024, 6:17 a.m.