Changes

From Genome Analysis Wiki
Jump to: navigation, search

Relationship between Ploidy, Alleles and Genotypes

870 bytes added, 14:11, 28 June 2016
Getting the genotypes from a genotype index and a given ploidy
= Getting the genotypes from a genotype index and a given ploidy =
 
std::vector<int32_t> bcf_ip2g(int32_t genotype_index, uint32_t no_ploidy)
{
std::vector<int32_t> genotype(no_ploidy, 0);
 
int32_t pth = no_ploidy;
int32_t max_allele_index = genotype_index;
int32_t leftover_genotype_index = genotype_index;
int d = 0;
while (pth>0)
{
for (int32_t allele_index=0; allele_index <= max_allele_index; ++allele_index)
{
int32_t i = choose(pth+allele_index-1, pth);
 
 
if (i>=leftover_genotype_index)
{
if (i>leftover_genotype_index) --allele_index;
leftover_genotype_index -= choose(pth+allele_index-1, pth);
--pth;
max_allele_index = allele_index;
genotype[pth] = allele_index;
break;
}
}
}
return genotype;
}
= Simple cases =
1,102
edits

Navigation menu