4353 |
23 Aug 23 |
peter |
// $Id$ |
4353 |
23 Aug 23 |
peter |
2 |
|
4353 |
23 Aug 23 |
peter |
3 |
/* |
4353 |
23 Aug 23 |
peter |
Copyright (C) 2023 Peter Johansson |
4353 |
23 Aug 23 |
peter |
5 |
|
4353 |
23 Aug 23 |
peter |
This file is part of the yat library, https://dev.thep.lu.se/yat |
4353 |
23 Aug 23 |
peter |
7 |
|
4353 |
23 Aug 23 |
peter |
The yat library is free software; you can redistribute it and/or |
4353 |
23 Aug 23 |
peter |
modify it under the terms of the GNU General Public License as |
4353 |
23 Aug 23 |
peter |
published by the Free Software Foundation; either version 3 of the |
4353 |
23 Aug 23 |
peter |
License, or (at your option) any later version. |
4353 |
23 Aug 23 |
peter |
12 |
|
4353 |
23 Aug 23 |
peter |
The yat library is distributed in the hope that it will be useful, |
4353 |
23 Aug 23 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
4353 |
23 Aug 23 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4353 |
23 Aug 23 |
peter |
General Public License for more details. |
4353 |
23 Aug 23 |
peter |
17 |
|
4353 |
23 Aug 23 |
peter |
You should have received a copy of the GNU General Public License |
4353 |
23 Aug 23 |
peter |
along with yat. If not, see <https://www.gnu.org/licenses/>. |
4353 |
23 Aug 23 |
peter |
20 |
*/ |
4353 |
23 Aug 23 |
peter |
21 |
|
4353 |
23 Aug 23 |
peter |
22 |
#include <config.h> |
4353 |
23 Aug 23 |
peter |
23 |
|
4353 |
23 Aug 23 |
peter |
24 |
#include "Suite.h" |
4353 |
23 Aug 23 |
peter |
25 |
|
4353 |
23 Aug 23 |
peter |
26 |
#include <yat/utility/mSmithWaterman2.h> |
4353 |
23 Aug 23 |
peter |
27 |
|
4353 |
23 Aug 23 |
peter |
28 |
using namespace theplu::yat; |
4353 |
23 Aug 23 |
peter |
29 |
using utility::mSmithWaterman2; |
4353 |
23 Aug 23 |
peter |
30 |
|
4353 |
23 Aug 23 |
peter |
31 |
std::string stringify(const utility::Aligner::Cigar& cigar) |
4353 |
23 Aug 23 |
peter |
32 |
{ |
4353 |
23 Aug 23 |
peter |
33 |
std::ostringstream ss; |
4353 |
23 Aug 23 |
peter |
34 |
ss << cigar; |
4353 |
23 Aug 23 |
peter |
35 |
return ss.str(); |
4353 |
23 Aug 23 |
peter |
36 |
} |
4353 |
23 Aug 23 |
peter |
37 |
|
4353 |
23 Aug 23 |
peter |
38 |
|
4353 |
23 Aug 23 |
peter |
39 |
int main(int argc, char* argv[]) |
4353 |
23 Aug 23 |
peter |
40 |
{ |
4353 |
23 Aug 23 |
peter |
41 |
test::Suite suite(argc, argv); |
4353 |
23 Aug 23 |
peter |
42 |
|
4353 |
23 Aug 23 |
peter |
43 |
size_t left = 13; |
4353 |
23 Aug 23 |
peter |
44 |
size_t middle1 = 23; |
4353 |
23 Aug 23 |
peter |
45 |
size_t middle2 = 17; |
4353 |
23 Aug 23 |
peter |
46 |
size_t right = 50; |
4353 |
23 Aug 23 |
peter |
47 |
|
4353 |
23 Aug 23 |
peter |
48 |
std::string ref1(left, 'x'); |
4353 |
23 Aug 23 |
peter |
49 |
ref1 += "Hello"; |
4353 |
23 Aug 23 |
peter |
50 |
ref1 += std::string(middle1, 'x'); |
4353 |
23 Aug 23 |
peter |
51 |
|
4353 |
23 Aug 23 |
peter |
52 |
std::string ref2(middle2, 'x'); |
4353 |
23 Aug 23 |
peter |
53 |
ref2 += "World"; |
4353 |
23 Aug 23 |
peter |
54 |
ref2 += std::string(right, 'x'); |
4353 |
23 Aug 23 |
peter |
55 |
|
4353 |
23 Aug 23 |
peter |
56 |
suite.out() << "ref1: '" << ref1 << "'\n"; |
4353 |
23 Aug 23 |
peter |
57 |
suite.out() << "ref2: '" << ref2 << "'\n"; |
4353 |
23 Aug 23 |
peter |
58 |
|
4353 |
23 Aug 23 |
peter |
59 |
std::string query("Hello World"); |
4353 |
23 Aug 23 |
peter |
60 |
suite.out() << "query: '" << query << "'\n"; |
4353 |
23 Aug 23 |
peter |
61 |
|
4353 |
23 Aug 23 |
peter |
62 |
mSmithWaterman2 aligner(1, 6); |
4353 |
23 Aug 23 |
peter |
63 |
utility::mAlignerBase::MatchKernel kernel(4); |
4353 |
23 Aug 23 |
peter |
64 |
double s = aligner(ref1.begin(), ref1.end(), ref2.begin(), ref2.end(), |
4353 |
23 Aug 23 |
peter |
65 |
query.begin(), query.end(), kernel); |
4353 |
23 Aug 23 |
peter |
66 |
|
4353 |
23 Aug 23 |
peter |
67 |
suite.out() << "score: " << s << "\n"; |
4353 |
23 Aug 23 |
peter |
68 |
suite.out() << "first:\n"; |
4353 |
23 Aug 23 |
peter |
69 |
suite.out() << " score: " << aligner.first().score() << "\n"; |
4353 |
23 Aug 23 |
peter |
70 |
suite.out() << " position: " << aligner.first().position() << "\n"; |
4353 |
23 Aug 23 |
peter |
71 |
suite.out() << " cigar: " << aligner.first().cigar() << "\n"; |
4353 |
23 Aug 23 |
peter |
72 |
suite.out() << " cigar2: " << aligner.first().cigar2() << "\n"; |
4353 |
23 Aug 23 |
peter |
73 |
suite.out() << "second:\n"; |
4353 |
23 Aug 23 |
peter |
74 |
suite.out() << " score: " << aligner.second().score() << "\n"; |
4353 |
23 Aug 23 |
peter |
75 |
suite.out() << " position: " << aligner.second().position() << "\n"; |
4353 |
23 Aug 23 |
peter |
76 |
suite.out() << " cigar: " << aligner.second().cigar() << "\n"; |
4353 |
23 Aug 23 |
peter |
77 |
suite.out() << " cigar2: " << aligner.second().cigar2() << "\n"; |
4353 |
23 Aug 23 |
peter |
78 |
|
4353 |
23 Aug 23 |
peter |
79 |
if (!suite.equal(s, query.size()-1)) { |
4353 |
23 Aug 23 |
peter |
80 |
suite.add(false); |
4353 |
23 Aug 23 |
peter |
81 |
suite.err() << "error: incorrect score: " << s << "\n"; |
4353 |
23 Aug 23 |
peter |
82 |
} |
4353 |
23 Aug 23 |
peter |
83 |
if (!suite.equal(aligner.first().score(), 5)) { |
4353 |
23 Aug 23 |
peter |
84 |
suite.add(false); |
4353 |
23 Aug 23 |
peter |
85 |
suite.err() << "error: incorrect first score\n"; |
4353 |
23 Aug 23 |
peter |
86 |
} |
4353 |
23 Aug 23 |
peter |
87 |
if (!suite.equal(aligner.second().score(), 5)) { |
4353 |
23 Aug 23 |
peter |
88 |
suite.add(false); |
4353 |
23 Aug 23 |
peter |
89 |
suite.err() << "error: incorrect second score\n"; |
4353 |
23 Aug 23 |
peter |
90 |
} |
4353 |
23 Aug 23 |
peter |
91 |
|
4353 |
23 Aug 23 |
peter |
92 |
if (aligner.first().position() != left) { |
4353 |
23 Aug 23 |
peter |
93 |
suite.add(false); |
4353 |
23 Aug 23 |
peter |
94 |
suite.err() << "error: incorrect first position: " |
4353 |
23 Aug 23 |
peter |
95 |
<< aligner.first().position() |
4353 |
23 Aug 23 |
peter |
96 |
<< "; expected: " << left << "\n"; |
4353 |
23 Aug 23 |
peter |
97 |
} |
4353 |
23 Aug 23 |
peter |
98 |
if (aligner.second().position() != middle2) { |
4353 |
23 Aug 23 |
peter |
99 |
suite.add(false); |
4353 |
23 Aug 23 |
peter |
100 |
suite.err() << "error: incorrect second position: " |
4353 |
23 Aug 23 |
peter |
101 |
<< aligner.second().position() |
4353 |
23 Aug 23 |
peter |
102 |
<< "; expected: " << middle2 << "\n"; |
4353 |
23 Aug 23 |
peter |
103 |
} |
4353 |
23 Aug 23 |
peter |
104 |
|
4353 |
23 Aug 23 |
peter |
105 |
std::string first_cigar = "5M6S"; |
4353 |
23 Aug 23 |
peter |
106 |
std::string first_cigar2 = "5=6S"; |
4353 |
23 Aug 23 |
peter |
107 |
std::string second_cigar = "6S5M"; |
4353 |
23 Aug 23 |
peter |
108 |
std::string second_cigar2 = "6S5="; |
4353 |
23 Aug 23 |
peter |
109 |
if (stringify(aligner.first().cigar()) != first_cigar) { |
4353 |
23 Aug 23 |
peter |
110 |
suite.add(false); |
4353 |
23 Aug 23 |
peter |
111 |
suite.err() << "error: incorrect first cigar: " |
4353 |
23 Aug 23 |
peter |
112 |
<< aligner.first().cigar() |
4353 |
23 Aug 23 |
peter |
113 |
<< "; expected: " << first_cigar << "\n"; |
4353 |
23 Aug 23 |
peter |
114 |
} |
4353 |
23 Aug 23 |
peter |
115 |
if (stringify(aligner.first().cigar2()) != first_cigar2) { |
4353 |
23 Aug 23 |
peter |
116 |
suite.add(false); |
4353 |
23 Aug 23 |
peter |
117 |
suite.err() << "error: incorrect first cigar2: " |
4353 |
23 Aug 23 |
peter |
118 |
<< aligner.first().cigar2() |
4353 |
23 Aug 23 |
peter |
119 |
<< "; expected: " << first_cigar2 << "\n"; |
4353 |
23 Aug 23 |
peter |
120 |
} |
4353 |
23 Aug 23 |
peter |
121 |
if (stringify(aligner.second().cigar()) != second_cigar) { |
4353 |
23 Aug 23 |
peter |
122 |
suite.add(false); |
4353 |
23 Aug 23 |
peter |
123 |
suite.err() << "error: incorrect second cigar: " |
4353 |
23 Aug 23 |
peter |
124 |
<< aligner.second().cigar() |
4353 |
23 Aug 23 |
peter |
125 |
<< "; expected: " << second_cigar << "\n"; |
4353 |
23 Aug 23 |
peter |
126 |
} |
4353 |
23 Aug 23 |
peter |
127 |
if (stringify(aligner.second().cigar2()) != second_cigar2) { |
4353 |
23 Aug 23 |
peter |
128 |
suite.add(false); |
4353 |
23 Aug 23 |
peter |
129 |
suite.err() << "error: incorrect second cigar2: " |
4353 |
23 Aug 23 |
peter |
130 |
<< aligner.second().cigar2() |
4353 |
23 Aug 23 |
peter |
131 |
<< "; expected: " << second_cigar2 << "\n"; |
4353 |
23 Aug 23 |
peter |
132 |
} |
4353 |
23 Aug 23 |
peter |
133 |
|
4353 |
23 Aug 23 |
peter |
134 |
return suite.return_value(); |
4353 |
23 Aug 23 |
peter |
135 |
} |