コード例 #1
0
ファイル: alignment.cpp プロジェクト: anukat2015/hunalign
int countIntersectionOfTrails( const Trail& sx, const Trail& sy )
{
  int inter(0);

  Trail::const_iterator sxt = sx.begin();
  Trail::const_iterator syt = sy.begin();
  Trail::const_iterator sxe = sx.end();
  Trail::const_iterator sye = sy.end();
  for ( ; sxt!=sxe && syt!=sye ; )
  {
    if ( *sxt < *syt )
      ++sxt;
    else if ( *sxt > *syt )
      ++syt;
    else
    {
      ++inter;
      ++sxt;
      ++syt;
    }
  }
  return inter;
}
コード例 #2
0
ファイル: alignment.cpp プロジェクト: anukat2015/hunalign
void trelliToLadder( const TrelliMatrix& trellis, Trail& bestTrail )
{
  bestTrail.clear();

  // The -1 is needed because the trellis matrix is one larger than the similarity matrix.
  // This points to its downmost rightmost element.
  const int huBookSize = trellis.size()-1;
  const int enBookSize = trellis.otherSize()-1;

  int huPos=huBookSize;
  int enPos=enBookSize;

  bool logging = false;

  if (logging) std::cerr << std::endl;

  bool over = false;
  bool hopelesslyBadTrail = false;
  bestTrail.push_back(std::make_pair(huPos,enPos));

  while (true)
  {
    unsigned char trelli = trellis[huPos][enPos];

    // std::cerr << huPos << "," << enPos << "," << (int)trelli << std::endl;

    if ((huPos==0) || (enPos==0))
      break;

    switch (trelli)
    {
    case Diag :
    {
      --huPos;
      --enPos;
      break;
    }
    case HuSkip :
    {
      --huPos;
      break;
    }
    case EnSkip :
    {
      --enPos;
      break;
    }
    case HuHuEnSkip :
    {
      huPos -= 2;
      --enPos;
      break;
    }
    case HuEnEnSkip :
    {
      --huPos;
      enPos -= 2;
      break;
    }
    case Dead :
    {
      over = true;
      break;
    }
    default:
    {
      hopelesslyBadTrail = true;
      over = true;
      break;
    }
    }

    if (over)
      break;

    bestTrail.push_back(std::make_pair(huPos,enPos));

    if (logging)
    {
      std::cerr << huPos << " \t" << enPos << std::endl;
    }

  }

  if (hopelesslyBadTrail)
  {
    bestTrail.clear();
    bestTrail.push_back(std::make_pair(huBookSize,enBookSize));
    bestTrail.push_back(std::make_pair(0,0));
    std::cerr << "Error: hopelessly bad trail." << std::endl;
  }

  std::reverse(bestTrail.begin(),  bestTrail.end()  );
}