183 |
05 Oct 04 |
jari |
// $Id$ |
183 |
05 Oct 04 |
jari |
2 |
|
675 |
10 Oct 06 |
jari |
3 |
/* |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2004 Jari Häkkinen |
831 |
27 Mar 07 |
peter |
Copyright (C) 2005 Peter Johansson |
2119 |
12 Dec 09 |
peter |
Copyright (C) 2006 Jari Häkkinen |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2007 Peter Johansson |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2008 Jari Häkkinen, Peter Johansson |
4207 |
26 Aug 22 |
peter |
Copyright (C) 2009, 2012, 2022 Peter Johansson |
183 |
05 Oct 04 |
jari |
10 |
|
1437 |
25 Aug 08 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
675 |
10 Oct 06 |
jari |
12 |
|
675 |
10 Oct 06 |
jari |
The yat library is free software; you can redistribute it and/or |
675 |
10 Oct 06 |
jari |
modify it under the terms of the GNU General Public License as |
1486 |
09 Sep 08 |
jari |
published by the Free Software Foundation; either version 3 of the |
675 |
10 Oct 06 |
jari |
License, or (at your option) any later version. |
675 |
10 Oct 06 |
jari |
17 |
|
675 |
10 Oct 06 |
jari |
The yat library is distributed in the hope that it will be useful, |
675 |
10 Oct 06 |
jari |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
675 |
10 Oct 06 |
jari |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
675 |
10 Oct 06 |
jari |
General Public License for more details. |
675 |
10 Oct 06 |
jari |
22 |
|
675 |
10 Oct 06 |
jari |
You should have received a copy of the GNU General Public License |
1487 |
10 Sep 08 |
jari |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
675 |
10 Oct 06 |
jari |
25 |
*/ |
675 |
10 Oct 06 |
jari |
26 |
|
2881 |
18 Nov 12 |
peter |
27 |
#include <config.h> |
2881 |
18 Nov 12 |
peter |
28 |
|
680 |
11 Oct 06 |
jari |
29 |
#include "Alignment.h" |
2815 |
28 Aug 12 |
peter |
30 |
|
2815 |
28 Aug 12 |
peter |
31 |
#include "Aligner.h" |
1121 |
22 Feb 08 |
peter |
32 |
#include "Matrix.h" |
1120 |
21 Feb 08 |
peter |
33 |
#include "stl_utility.h" |
675 |
10 Oct 06 |
jari |
34 |
|
869 |
14 Sep 07 |
peter |
35 |
#include <algorithm> |
256 |
03 Mar 05 |
peter |
36 |
#include <utility> |
256 |
03 Mar 05 |
peter |
37 |
#include <vector> |
256 |
03 Mar 05 |
peter |
38 |
|
183 |
05 Oct 04 |
jari |
39 |
namespace theplu { |
680 |
11 Oct 06 |
jari |
40 |
namespace yat { |
301 |
30 Apr 05 |
peter |
41 |
namespace utility { |
183 |
05 Oct 04 |
jari |
42 |
|
4125 |
14 Jan 22 |
peter |
43 |
double NeedlemanWunsch(const MatrixBase& s, |
256 |
03 Mar 05 |
peter |
44 |
std::vector<std::pair<size_t, size_t> >& path, |
265 |
11 Apr 05 |
peter |
45 |
const double gap) |
183 |
05 Oct 04 |
jari |
46 |
{ |
2815 |
28 Aug 12 |
peter |
// align |
2815 |
28 Aug 12 |
peter |
48 |
Aligner aligner(gap); |
2815 |
28 Aug 12 |
peter |
49 |
double score = aligner.needleman_wunsch(s); |
183 |
05 Oct 04 |
jari |
50 |
|
256 |
03 Mar 05 |
peter |
// Going backwards to find best path |
2815 |
28 Aug 12 |
peter |
52 |
size_t i = s.rows(); |
2815 |
28 Aug 12 |
peter |
53 |
size_t j= s.columns(); |
2815 |
28 Aug 12 |
peter |
54 |
path.clear(); |
2815 |
28 Aug 12 |
peter |
55 |
while (i && j) { |
2816 |
28 Aug 12 |
peter |
56 |
if (aligner.alignment(i,j)==Aligner::diagonal) { |
2815 |
28 Aug 12 |
peter |
57 |
--i; |
2815 |
28 Aug 12 |
peter |
58 |
--j; |
256 |
03 Mar 05 |
peter |
59 |
path.push_back(std::make_pair(i,j)); |
256 |
03 Mar 05 |
peter |
60 |
} |
2816 |
28 Aug 12 |
peter |
61 |
else if (aligner.alignment(i,j)==Aligner::right) |
2815 |
28 Aug 12 |
peter |
62 |
--j; |
256 |
03 Mar 05 |
peter |
63 |
else |
2815 |
28 Aug 12 |
peter |
64 |
--i; |
256 |
03 Mar 05 |
peter |
65 |
} |
2815 |
28 Aug 12 |
peter |
66 |
return score; |
183 |
05 Oct 04 |
jari |
67 |
} |
183 |
05 Oct 04 |
jari |
68 |
|
869 |
14 Sep 07 |
peter |
69 |
|
2792 |
27 Jul 12 |
peter |
70 |
double ssearch(std::string first, std::string second, double gap, |
2792 |
27 Jul 12 |
peter |
71 |
double open_gap, double mismatch) |
869 |
14 Sep 07 |
peter |
72 |
{ |
2011 |
08 Jul 09 |
peter |
73 |
Matrix m; |
2011 |
08 Jul 09 |
peter |
74 |
if (first.size() && second.size()) |
2011 |
08 Jul 09 |
peter |
75 |
m.resize(first.size(), second.size()); |
869 |
14 Sep 07 |
peter |
76 |
for (size_t i=0; i<first.size(); ++i) |
869 |
14 Sep 07 |
peter |
77 |
for (size_t j=0; j<second.size(); ++j) |
2792 |
27 Jul 12 |
peter |
78 |
m(i,j) = (first[i]==second[j] ? 1 : -mismatch); |
2815 |
28 Aug 12 |
peter |
79 |
Aligner aligner(gap, open_gap); |
2815 |
28 Aug 12 |
peter |
80 |
return aligner.smith_waterman(m); |
869 |
14 Sep 07 |
peter |
81 |
} |
869 |
14 Sep 07 |
peter |
82 |
|
869 |
14 Sep 07 |
peter |
83 |
|
1121 |
22 Feb 08 |
peter |
84 |
double SmithWaterman(const utility::Matrix& s, |
869 |
14 Sep 07 |
peter |
85 |
double gap, double open_gap) |
869 |
14 Sep 07 |
peter |
86 |
{ |
2815 |
28 Aug 12 |
peter |
87 |
Aligner aligner(gap, open_gap); |
2815 |
28 Aug 12 |
peter |
88 |
return aligner.smith_waterman(s); |
869 |
14 Sep 07 |
peter |
89 |
} |
869 |
14 Sep 07 |
peter |
90 |
|
687 |
16 Oct 06 |
jari |
91 |
}}} // of namespace utility, yat, and theplu |