int HaploTree::Traverse(IntArray & pointer, IntArray & state) const
   {
   while (pointer.Length())
      {
      int branch = pointer.Peek();
      int & allele = state[levels[branch]];
      int next = -1;

      while (++allele < alleleCounts[levels[branch]])
         if ((next = PeekBranch(branch, allele)) != -1)
            break;

      if (next == -1)
         {
         allele = -1;
         pointer.Pop();
         continue;
         }

      if (levels[branch] == depth - 1)
         return next;

      pointer.Push(next);
      }

   return -1;
   }
Exemple #2
0
void Family::ShowInvalidCycles()
   {
   // Try and identify key individuals responsible for
   // pedigree mess-up ... when this function is called
   // pedigree has been traversed top-down and individuals
   // that are correctly specified have IDs of >= 0.

   // This routine traverses the pedigree bottom up to
   // identify a subset of individuals likely to be causing
   // the problem
   IntArray descendants(ped.count);
   descendants.Zero();

   for (int i = first; i <= last; i++)
      if (ped[i].traverse == -1)
         {
         descendants[ped[i].father->serial]++;
         descendants[ped[i].mother->serial]++;
         }

   IntArray stack;

   for (int i = first; i <= last; i++)
      if (ped[i].traverse == -1 && descendants[i] == 0)
         {
         stack.Push(i);

         do {
            int j = stack.Pop();

            if (ped[j].traverse != -1) continue;

            ped[j].traverse = 9999;

            if (--descendants[ped[j].father->serial] == 0)
               stack.Push(ped[j].father->serial);
            if (--descendants[ped[j].mother->serial] == 0)
               stack.Push(ped[j].mother->serial);
         } while (stack.Length());
         }

   printf("The structure of family %s requires\n"
          "an individual to be his own ancestor.\n\n"
          "To identify the problem(s), examine the\n"
          "following key individuals:\n\n",
          (const char *) famid);

   for (int i = first; i <= last; i++)
      if (ped[i].traverse == -1)
         printf("Problem Person: %s\n", (const char *) ped[i].pid);

   error("Invalid pedigree structure.");
   }