Difference between revisions of "830 - Haplotyper::SampleHaplotypes()"
From Genome Analysis Wiki
Jump to navigationJump to searchLine 1: | Line 1: | ||
<source lang="cpp"> | <source lang="cpp"> | ||
− | + | float Haplotyper::SampleHaplotypes(float * vector, int & first, int & second) | |
{ | { | ||
− | + | first = 0; | |
− | + | second = 0; | |
− | + | float sum = 0.0; | |
− | |||
− | + | // Calculate sum over all states | |
− | + | for (int i = 0; i < states; i++) | |
− | + | for (int j = 0; j <= i; j++) | |
− | + | { | |
+ | sum += *probability; | ||
+ | probability++; | ||
+ | } | ||
− | + | // Sample number and select state | |
+ | float choice = rand->Uniform(0, sum); | ||
− | + | sum = 0.0; | |
− | |||
− | + | for (probability = leftMatrices[markers - 1]; first < states; first++) | |
− | + | { | |
− | + | for (second = 0; second <= first; second++) | |
− | |||
− | |||
− | |||
− | |||
{ | { | ||
− | + | sum += *probability; | |
− | + | probability++; | |
− | |||
− | + | if (sum >= choice) break; | |
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
− | + | if (second <= first) break; | |
− | |||
} | } | ||
− | + | ||
− | + | if (rand->Binary()) SWAP(first, second); | |
} | } | ||
</source> | </source> |
Revision as of 14:08, 2 October 2013
float Haplotyper::SampleHaplotypes(float * vector, int & first, int & second)
{
first = 0;
second = 0;
float sum = 0.0;
// Calculate sum over all states
for (int i = 0; i < states; i++)
for (int j = 0; j <= i; j++)
{
sum += *probability;
probability++;
}
// Sample number and select state
float choice = rand->Uniform(0, sum);
sum = 0.0;
for (probability = leftMatrices[markers - 1]; first < states; first++)
{
for (second = 0; second <= first; second++)
{
sum += *probability;
probability++;
if (sum >= choice) break;
}
if (second <= first) break;
}
if (rand->Binary()) SWAP(first, second);
}