// \$Id: Alignment.cc 1487 2008-09-10 08:41:36Z jari \$ /* Copyright (C) 2004 Jari Hðkkinen Copyright (C) 2005 Peter Johansson Copyright (C) 2006 Jari Hðkkinen Copyright (C) 2007 Jari Hðkkinen, Peter Johansson Copyright (C) 2008 Peter Johansson This file is part of the yat library, http://dev.thep.lu.se/yat The yat library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. The yat library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with yat. If not, see . */ #include "Alignment.h" #include "Matrix.h" #include "stl_utility.h" #include #include #include namespace theplu { namespace yat { namespace utility { double NeedlemanWunsch(const utility::Matrix& s, std::vector >& path, const double gap) { utility::Matrix m(s.rows()+1,s.columns()+1); // Init upper and left border of matrix for (size_t i=1; i m(i-1,j)-gap && m(i-1,j-1) + s(i-1,j-1) > m(i,j-1)-gap){ m(i,j)=m(i-1,j-1) + s(i-1,j-1); choice(i,j)=1; } else if (m(i-1,j) > m(i,j-1)){ m(i,j)=m(i-1,j)-gap; choice(i,j)=2; } else{ m(i,j)=m(i,j-1)-gap; choice(i,j)=3; } } // Going backwards to find best path size_t i = m.rows()-1; size_t j= m.columns()-1; path.resize(0); while (i && j){ if (choice(i,j)==1){ i--; j--; path.push_back(std::make_pair(i,j)); } else if (choice(i,j)==2) i--; else j--; } return m(m.rows()-1,m.columns()-1); } double ssearch(std::string first, std::string second, double gap, double open_gap) { Matrix m(first.size(), second.size()); for (size_t i=0; im(i,j)){ m(i,j) = m(i-1,j-1)+s(i-1,j-1); array(i,j) = diagonal; } if (array(i-1,j)==right && m(i-1,j)-gap > m(i,j)){ m(i,j) = m(i-1,j)-gap; array(i,j) = right; } if (array(i-1,j)!=right && m(i-1,j)-gap-open_gap > m(i,j)){ m(i,j) = m(i-1,j)-gap-open_gap; array(i,j) = right; } if (array(i,j-1)==down && m(i,j-1)-gap > m(i,j)){ m(i,j) = m(i,j-1)-gap; array(i,j) = down; } if (array(i,j-1)!=down && m(i,j-1)-gap-open_gap > m(i,j)){ m(i,j) = m(i,j-1)-gap-open_gap; array(i,j) = down; } } return max(m); } }}} // of namespace utility, yat, and theplu