4300 |
07 Feb 23 |
peter |
// $Id$ |
4300 |
07 Feb 23 |
peter |
2 |
|
4300 |
07 Feb 23 |
peter |
3 |
/* |
4300 |
07 Feb 23 |
peter |
Copyright (C) 2023 Peter Johansson |
4300 |
07 Feb 23 |
peter |
5 |
|
4300 |
07 Feb 23 |
peter |
This file is part of the yat library, https://dev.thep.lu.se/yat |
4300 |
07 Feb 23 |
peter |
7 |
|
4300 |
07 Feb 23 |
peter |
The yat library is free software; you can redistribute it and/or |
4300 |
07 Feb 23 |
peter |
modify it under the terms of the GNU General Public License as |
4300 |
07 Feb 23 |
peter |
published by the Free Software Foundation; either version 3 of the |
4300 |
07 Feb 23 |
peter |
License, or (at your option) any later version. |
4300 |
07 Feb 23 |
peter |
12 |
|
4300 |
07 Feb 23 |
peter |
The yat library is distributed in the hope that it will be useful, |
4300 |
07 Feb 23 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
4300 |
07 Feb 23 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4300 |
07 Feb 23 |
peter |
General Public License for more details. |
4300 |
07 Feb 23 |
peter |
17 |
|
4300 |
07 Feb 23 |
peter |
You should have received a copy of the GNU General Public License |
4300 |
07 Feb 23 |
peter |
along with yat. If not, see <https://www.gnu.org/licenses/>. |
4300 |
07 Feb 23 |
peter |
20 |
*/ |
4300 |
07 Feb 23 |
peter |
21 |
|
4300 |
07 Feb 23 |
peter |
22 |
#include <config.h> |
4300 |
07 Feb 23 |
peter |
23 |
|
4300 |
07 Feb 23 |
peter |
24 |
#include "Suite.h" |
4300 |
07 Feb 23 |
peter |
25 |
|
4300 |
07 Feb 23 |
peter |
26 |
#include "yat/utility/Aligner.h" |
4300 |
07 Feb 23 |
peter |
27 |
#include "yat/utility/Matrix.h" |
4300 |
07 Feb 23 |
peter |
28 |
|
4300 |
07 Feb 23 |
peter |
29 |
#include <string> |
4300 |
07 Feb 23 |
peter |
30 |
|
4300 |
07 Feb 23 |
peter |
31 |
using namespace theplu::yat; |
4300 |
07 Feb 23 |
peter |
32 |
|
4300 |
07 Feb 23 |
peter |
33 |
|
4300 |
07 Feb 23 |
peter |
34 |
void check(test::Suite& suite, const std::string& ref, |
4300 |
07 Feb 23 |
peter |
35 |
const std::string& seq, double expected, |
4300 |
07 Feb 23 |
peter |
36 |
double q, double r, double b) |
4300 |
07 Feb 23 |
peter |
37 |
{ |
4300 |
07 Feb 23 |
peter |
38 |
utility::Aligner aligner(r,q); |
4300 |
07 Feb 23 |
peter |
39 |
|
4300 |
07 Feb 23 |
peter |
40 |
utility::Matrix dot(ref.size(), seq.size(), -b); |
4300 |
07 Feb 23 |
peter |
41 |
for (size_t i=0; i<dot.rows(); ++i) |
4300 |
07 Feb 23 |
peter |
42 |
for (size_t j=0; j<dot.columns(); ++j) |
4300 |
07 Feb 23 |
peter |
43 |
if (ref[i] == seq[j]) |
4300 |
07 Feb 23 |
peter |
44 |
dot(i,j) = 1.0; |
4300 |
07 Feb 23 |
peter |
45 |
|
4300 |
07 Feb 23 |
peter |
46 |
double score = aligner.needleman_wunsch(dot); |
4300 |
07 Feb 23 |
peter |
47 |
if (!suite.equal(score, expected)) { |
4300 |
07 Feb 23 |
peter |
48 |
suite.err() << "incorrect score\n"; |
4300 |
07 Feb 23 |
peter |
49 |
suite.err() << "ref: " << ref << "\n"; |
4300 |
07 Feb 23 |
peter |
50 |
suite.err() << "seq: " << seq << "\n"; |
4300 |
07 Feb 23 |
peter |
51 |
suite.err() << "aligner score: " << score << "\n"; |
4300 |
07 Feb 23 |
peter |
52 |
suite.err() << "expected: " << expected << "\n"; |
4300 |
07 Feb 23 |
peter |
53 |
suite.add(false); |
4300 |
07 Feb 23 |
peter |
54 |
} |
4300 |
07 Feb 23 |
peter |
55 |
|
4300 |
07 Feb 23 |
peter |
56 |
} |
4300 |
07 Feb 23 |
peter |
57 |
|
4300 |
07 Feb 23 |
peter |
58 |
|
4300 |
07 Feb 23 |
peter |
59 |
int main(int argc, char* argv[]) |
4300 |
07 Feb 23 |
peter |
60 |
{ |
4300 |
07 Feb 23 |
peter |
61 |
test::Suite suite(argc, argv); |
4300 |
07 Feb 23 |
peter |
62 |
|
4300 |
07 Feb 23 |
peter |
63 |
double q=5; |
4300 |
07 Feb 23 |
peter |
64 |
double r=2; |
4300 |
07 Feb 23 |
peter |
65 |
double b=3; |
4300 |
07 Feb 23 |
peter |
66 |
check(suite, "ABCDEFG", "ABCDEFG", 7, q, r, b); |
4300 |
07 Feb 23 |
peter |
67 |
check(suite, "ABCDEFG", "BCDEFG", 6 - (q + r), q, r, b); |
4300 |
07 Feb 23 |
peter |
68 |
check(suite, "ABCDEFG", "ABCDEF", 6 - (q + r), q, r, b); |
4300 |
07 Feb 23 |
peter |
69 |
check(suite, "ABCDEFG", "CD", 2 - (q + 2*r) - (q + 3*r), q, r, b); |
4300 |
07 Feb 23 |
peter |
70 |
check(suite, "BCDEFG", "ABCDEFG", 6 - (q + r), q, r, b); |
4300 |
07 Feb 23 |
peter |
71 |
check(suite, "ABCDE", "ABCDEFG", 5 - (q + 2*r), q, r, b); |
4300 |
07 Feb 23 |
peter |
72 |
|
4300 |
07 Feb 23 |
peter |
73 |
return suite.return_value(); |
4300 |
07 Feb 23 |
peter |
74 |
} |