Skip to main content

AlleleFreq.jl

PopGenCore.jl/src/AlleleFreq.jl

📦 not exported🟪 exported by PopGenCore.jl🔵 exported by PopGen.jl

🟪 allelefreq

allelefreq(genos::GenoArray, allele::Int)

Return the frequency of a specific allele from a vector of Genotypes genos.

Example

ncats = @nancycats;
ncats_sub = ncats[(ncats.genodata.locus .== "fca8") .& (ncats.genodata.genotype .!== missing)]
pop_grp = groupby(ncats_sub, :population)
DataFrames.combine(pop_grp, :genotype => (geno -> allelefreq(137, geno)) => :freq_137)

allelefreq(geno::Genotype)

Return a Dict of allele frequencies of the alleles within a single Genotype in a PopData object.


allelefreq(locus::T) where T<:GenotypeArray

Return a Dict of allele frequencies of a single locus in a PopData object.


allelefreq(data::PopData, locus::String; population::Bool = false)

Return a Dict of allele frequencies of a single locus in a PopData object. Use population = true to return a table of allele frequencies of that locus per population.

Example

cats = @nancycats
allelefreq(cats, "fca8")
allelefreq(cats, "fca8", population = true)

🟪 avg_allelefreq

avg_allelefreq(allele_dicts::AbstractVector{Dict{T, Float64}}, power::Int = 1) where T<:Signed  

Takes a Vector of Dicts generated by allelefreq and returns a Dict of the average allele frequencies raised to the power (exponent) specified (default: 1). This is typically done to calculate average allele frequencies across populations.

Example

cats = @nancycats;
alleles_df = DataFrames.combine(
groupby(cats.genodata, [:locus, :population]),
:genotype => allelefreq => :alleles
);
DataFrames.combine(
groupby(alleles_df, :locus),
:alleles => (i -> sum(avg_allelefreq(i, 2))) => :avg_freq
)

🟪 allelefreq_vec

allelefreq_vec(locus::T) where T<:GenotypeArray

Return a Vector of allele frequencies of a single locus in a PopData object. Similar to allelefreq(), except it returns only the frequencies, without the allele names, meaning they can be in any order. This can be useful for getting the expected genotype frequencies.