MAF in R
1
0
Entering edit mode
2.5 years ago
gosssheen • 0

Hello,

I have a data set like this "AA","AB","BB" and I need calculate minor allele freq and keep only these which are bigger than 5%. Have you ever done something like this?

SNP <- data.frame(SNP = c("AA","AB","BB","AA","BB","BB","AB","AA"), SNP1 = c("AA","AA","AA","BB","AA","AB","BB","AA"), SNP2 = c("AB","AB","AB","BB","AA","AA","AA","BB"))
Minor-Allele-Freq R MAF • 1.8k views
ADD COMMENT
0
Entering edit mode

Your code won't work. You'll need to quote the allele strings

ADD REPLY
0
Entering edit mode

Yeah, sorry :)

ADD REPLY
4
Entering edit mode
2.5 years ago
Ram 44k

You can use HardyWeinberg::maf to calculate MAF from a vector of frequencies. You can create this vector of HOM/HET/HOM-ALT frequencies using a simple table:

library(HardyWeinberg)
SNPs <- data.frame(SNP = c("AA","AB","BB","AA","BB","BB","AB","AA"), SNP1 = c("AA","AA","AA","BB","AA","AB","BB","AA"), SNP2 = c("AB","AB","AB","BB","AA","AA","AA","BB"))
table(sort(SNPs$SNP1))
AA AB BB
 5  1  2
maf(as.vector(table(sort(SNPs$SNP1))))
[1] 0.3125 # which is the same as 1-((nAA + 0.5 * nAB)/(nAA + nAB + nBB))
ADD COMMENT
0
Entering edit mode

You're the best! Thanks! :)

ADD REPLY
0
Entering edit mode

Please accept my answer to mark the post as solved:

upvote_bookmark_accept

ADD REPLY

Login before adding your answer.

Traffic: 2323 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6