Difference between revisions of "830 - Haplotyper::SampleOneHaplotype()"

From Genome Analysis Wiki
Jump to navigationJump to search
(Created page with "<source lang="cpp"> float Haplotyper::SampleOneHaplotype(float * vector, double first, double & second, float & choice) { for (second = 0; second < states; second++) ...")
 
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
<source lang="cpp">
 
<source lang="cpp">
float Haplotyper::SampleOneHaplotype(float * vector, double first, double & second, float & choice)
+
void Haplotyper::SampleOneHaplotype(float * vector, double first, double & second, float & choice)
 
   {
 
   {
 
   for (second = 0; second < states; second++)
 
   for (second = 0; second < states; second++)
 
       {
 
       {
       choice += vector[CalculateIndex(first, second)] * 0.5;
+
       choice -= vector[CalculateIndex(first, second)] * 0.5;
       if (choice >= 0.0) return;
+
       if (choice <= 0.0) return;
 
       }
 
       }
  
 
   second = first;
 
   second = first;
 +
  }
 +
 +
int Haplotyper::CalculateIndex(int first, int second)
 +
  {
 +
  if (first >= second)
 +
      return (first * (first + 1) / 2 + second);
 +
  else
 +
      return (second * (second + 1) / 2 + first);
 
   }
 
   }
 
</source>
 
</source>

Latest revision as of 16:03, 2 October 2013

void Haplotyper::SampleOneHaplotype(float * vector, double first, double & second, float & choice)
   {
   for (second = 0; second < states; second++)
      {
      choice -= vector[CalculateIndex(first, second)] * 0.5;
      if (choice <= 0.0) return;
      }

   second = first;
   }

int Haplotyper::CalculateIndex(int first, int second)
   {
   if (first >= second)
       return (first * (first + 1) / 2 + second);
   else
       return (second * (second + 1) / 2 + first);
   }