### freq - calculate allele frequencies
# allele = 0, 2 for missing or heterozygous genotype frequencies
# 1, 3 for allele A, B including AB/2, excluding missing
# by = dimension (1 = per individual, 2 = per SNP)
function freq(x::SnpData, allele::Integer = 1, by::Integer = 2)
if by < 1 || by > 2
error("by out of range")
end
n = size(x, by)
m = size(x, 3 - by)
f = Vector{Real}(n)
for (i in 1:n)
if (by == 2)
s = x[:,i]
else
s = x[i,:]
end
if allele in [0 2]
# missing and heterozygous frequencies
f[i] = length(findin(s, allele)) / m
else
# diploid allele
nmis = length(findin(s, 0))
nall = length(findin(s, allele))
nhet = length(findin(s, 2))/2
f[i] = (nall + nhet) / (m - nmis)
end
end
return(f)
end
function freq(x::SnpMatrix, allele::Integer = 1, by::Integer = 2)
freq(x.data, allele, by)
end
A suggestion for allele frequency calculation:
Should I push?