Learn R Programming

BIGr (version 0.6.2)

calculate_MAF: Calculate Minor Allele Frequency from a Genotype Matrix

Description

This function calculates the allele frequency and minor allele frequency from a genotype matrix. It assumes that the Samples are the columns, and the genomic markers are in rows. Missing data should be set as NA, which will then be ignored for the calculations. All samples must have the same ploidy.

Usage

calculate_MAF(df, ploidy)

Value

A dataframe of AF and MAF values for each marker

Arguments

df

Genotype matrix or data.frame

ploidy

The ploidy of the species being analyzed

Examples

Run this code
# example input for a diploid
geno <- data.frame(
            Sample1 = c(0, 1, 2, NA, 0),
            Sample2 = c(1, 1, 2, 0, NA),
            Sample3 = c(0, 1, 1, 0, 2),
            Sample4 = c(0, 0, 1, 1, NA)
           )
row.names(geno) <- c("Marker1", "Marker2", "Marker3", "Marker4", "Marker5")

ploidy <- 2

# calculate allele frequency
result <- calculate_MAF(geno, ploidy)

print(result)

Run the code above in your browser using DataLab