int half_sw_banded(const Ts1 &s1, const Ts2 &s2,
                   int match, int mismatch,
                   int indel,
                   const Tf &lizard_tail,
                   int max_indels = 6) {
  using std::min;
  using std::max;
  using seqan::length;
  using std::vector;

  const int INF = 1005000;

  if (max_indels == 0) {
    return half_hamming(s1, s2, match, mismatch, lizard_tail);
  }

  int len1 = length(s1), len2 = length(s2); // Cache lengths because of length(s) computation maybe not O(1) e.g. for char*-strings

  vector<int> base(2*max_indels + 1, -INF);
  for (int i2 = max(0, len1 - max_indels); i2 <= min(len1 + max_indels, len2); ++i2) {
    int ind = i2 + max_indels - len1;
    base[ind] = lizard_tail(len2 - i2);
  }

  vector<int> new_base(2*max_indels + 1, -INF);
  for (int i1 = len1 - 1; i1 >= 0; --i1) {
    for (int i2 = i1 + max_indels; i2 >= i1 - max_indels; --i2) {
      int inx = max_indels + i2 - i1;
      if ((i2 < 0) || (i2 > len2)) {
        new_base[inx] = -INF;
      } else if (i2 == len2) {
        new_base[inx] = lizard_tail(len1 - i1);
      } else {
        int m = (s1[i1] == s2[i2]) ? match : mismatch;

        if (inx == 0)
          new_base[inx] = max( { m + base[inx], indel + new_base[inx + 1]} );
        else if (inx == 2*max_indels)
          new_base[inx] = max( { m + base[inx], indel + base[inx - 1] } );
        else
          new_base[inx] = max( { m + base[inx], indel + base[inx - 1], indel + new_base[inx + 1]} );
      }
    }

    std::swap(base, new_base);
  }

  return max(-INF, base[max_indels]); // Score is always finite due to possibility to align using mismatches
}
int half_hamming(const Ts1 &s1, const Ts2 &s2,
                 int match, int mismatch,
                 const Tf &lizard_tail) {
  int len1 = length(s1), len2 = length(s2); // Cache lengths because of length(s) computation maybe not O(1) e.g. for char*-strings
  size_t len = std::min<size_t>(len1, len2);

  size_t res = 0;
  for (size_t i = 0; i < len; ++i) {
    res += (s1[i] == s2[i]) ? match : mismatch;
  }

  res += lizard_tail(std::abs(len1 - len2));

  return res;
}
Ejemplo n.º 3
0
      void add(const T &s, size_t id, const Tf &toIndex) {
        if (!root) {
          root.reset(new TrieNode);
        }

        typename TrieNode::pointer_type p = this->root.get();

        for (size_t i = 0; i < length(s); ++i) {
          size_t el = toIndex(s[i]);
          assert((0 <= el) && (el < p->children.size()));

          if (!p->children[el]) {
            p->children[el] = new TrieNode();
          }

          p = p->children[el];
        }

        if (!p->ids) {
          p->ids = new std::vector<size_t>;
        }

        p->ids->push_back(id);
      }