source: trunk/yat/utility/Alignment.cc

Last change on this file was 2881, checked in by Peter, 9 years ago

Define PP variables in config.h rather than in CPPFLAGS. Include
config.h into all source files. Only ammend CXXFLAGS with '-Wall
-pedantic' when --enable-debug. In default mode we respect CXXFLAGS
value set by user, or set to default value '-O3'.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.3 KB
Line 
1// $Id: Alignment.cc 2881 2012-11-18 01:28:05Z peter $
2
3/*
4  Copyright (C) 2004 Jari Häkkinen
5  Copyright (C) 2005 Peter Johansson
6  Copyright (C) 2006 Jari Häkkinen
7  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
8  Copyright (C) 2009, 2012 Peter Johansson
9
10  This file is part of the yat library, http://dev.thep.lu.se/yat
11
12  The yat library is free software; you can redistribute it and/or
13  modify it under the terms of the GNU General Public License as
14  published by the Free Software Foundation; either version 3 of the
15  License, or (at your option) any later version.
16
17  The yat library is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20  General Public License for more details.
21
22  You should have received a copy of the GNU General Public License
23  along with yat. If not, see <http://www.gnu.org/licenses/>.
24*/
25
26#include <config.h>
27
28#include "Alignment.h"
29
30#include "Aligner.h"
31#include "Matrix.h"
32#include "stl_utility.h"
33
34#include <algorithm>
35#include <utility>
36#include <vector>
37
38namespace theplu {
39namespace yat {
40namespace utility {
41
42  double NeedlemanWunsch(const Matrix& s,
43                         std::vector<std::pair<size_t, size_t> >& path,
44                         const double gap)
45  {
46    // align
47    Aligner aligner(gap);
48    double score = aligner.needleman_wunsch(s);
49
50    // Going backwards to find best path
51    size_t i = s.rows();
52    size_t j= s.columns();
53    path.clear();
54    while (i && j) {
55      if (aligner.alignment(i,j)==Aligner::diagonal) {
56        --i;
57        --j;
58        path.push_back(std::make_pair(i,j));
59      }
60      else if (aligner.alignment(i,j)==Aligner::right)
61        --j;
62      else
63        --i;
64    }
65    return score;
66  }
67
68
69  double ssearch(std::string first, std::string second, double gap,
70                 double open_gap, double mismatch)
71  {
72    Matrix m;
73    if (first.size() && second.size())
74      m.resize(first.size(), second.size());
75    for (size_t i=0; i<first.size(); ++i)
76      for (size_t j=0; j<second.size(); ++j)
77        m(i,j) = (first[i]==second[j] ? 1 : -mismatch);
78    Aligner aligner(gap, open_gap);
79    return aligner.smith_waterman(m);
80  }
81
82
83  double SmithWaterman(const utility::Matrix& s,
84                       double gap, double open_gap)
85  {
86    Aligner aligner(gap, open_gap);
87    return aligner.smith_waterman(s);
88  }
89
90}}} // of namespace utility, yat, and theplu
Note: See TracBrowser for help on using the repository browser.