4340 |
16 Apr 23 |
peter |
// $Id$ |
4340 |
16 Apr 23 |
peter |
2 |
|
4340 |
16 Apr 23 |
peter |
3 |
/* |
4340 |
16 Apr 23 |
peter |
Copyright (C) 2023 Peter Johansson |
4340 |
16 Apr 23 |
peter |
5 |
|
4340 |
16 Apr 23 |
peter |
This file is part of the yat library, https://dev.thep.lu.se/yat |
4340 |
16 Apr 23 |
peter |
7 |
|
4340 |
16 Apr 23 |
peter |
The yat library is free software; you can redistribute it and/or |
4340 |
16 Apr 23 |
peter |
modify it under the terms of the GNU General Public License as |
4340 |
16 Apr 23 |
peter |
published by the Free Software Foundation; either version 3 of the |
4340 |
16 Apr 23 |
peter |
License, or (at your option) any later version. |
4340 |
16 Apr 23 |
peter |
12 |
|
4340 |
16 Apr 23 |
peter |
The yat library is distributed in the hope that it will be useful, |
4340 |
16 Apr 23 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
4340 |
16 Apr 23 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4340 |
16 Apr 23 |
peter |
General Public License for more details. |
4340 |
16 Apr 23 |
peter |
17 |
|
4340 |
16 Apr 23 |
peter |
You should have received a copy of the GNU General Public License |
4340 |
16 Apr 23 |
peter |
along with yat. If not, see <https://www.gnu.org/licenses/>. |
4340 |
16 Apr 23 |
peter |
20 |
*/ |
4340 |
16 Apr 23 |
peter |
21 |
|
4340 |
16 Apr 23 |
peter |
22 |
#include <config.h> |
4340 |
16 Apr 23 |
peter |
23 |
|
4340 |
16 Apr 23 |
peter |
24 |
#include "Suite.h" |
4340 |
16 Apr 23 |
peter |
25 |
|
4340 |
16 Apr 23 |
peter |
26 |
#include <yat/utility/mNeedlemanWunsch.h> |
4340 |
16 Apr 23 |
peter |
27 |
#include <yat/utility/mSemiLocalAligner.h> |
4340 |
16 Apr 23 |
peter |
28 |
#include <yat/utility/mSmithWaterman.h> |
4340 |
16 Apr 23 |
peter |
29 |
|
4340 |
16 Apr 23 |
peter |
30 |
#include <yat/utility/version.h> |
4340 |
16 Apr 23 |
peter |
31 |
|
4340 |
16 Apr 23 |
peter |
32 |
using namespace theplu::yat; |
4340 |
16 Apr 23 |
peter |
33 |
using utility::mAligner; |
4340 |
16 Apr 23 |
peter |
34 |
using utility::mNeedlemanWunsch; |
4340 |
16 Apr 23 |
peter |
35 |
using utility::mSmithWaterman; |
4340 |
16 Apr 23 |
peter |
36 |
using utility::mSemiLocalAligner; |
4340 |
16 Apr 23 |
peter |
37 |
|
4340 |
16 Apr 23 |
peter |
38 |
template<class ALIGNER> |
4340 |
16 Apr 23 |
peter |
39 |
void check_aligner(ALIGNER& aligner, |
4340 |
16 Apr 23 |
peter |
40 |
const std::string& ref, const std::string& query, |
4340 |
16 Apr 23 |
peter |
41 |
double score, const std::string& cig, |
4340 |
16 Apr 23 |
peter |
42 |
const std::string& cig2, |
4340 |
16 Apr 23 |
peter |
43 |
test::Suite& suite) |
4340 |
16 Apr 23 |
peter |
44 |
{ |
4340 |
16 Apr 23 |
peter |
45 |
theplu::yat::utility::Aligner::Cigar cigar(cig); |
4340 |
16 Apr 23 |
peter |
46 |
theplu::yat::utility::Aligner::Cigar cigar2(cig2); |
4340 |
16 Apr 23 |
peter |
47 |
try { |
4340 |
16 Apr 23 |
peter |
48 |
aligner(ref.begin(), ref.end(), query.begin(), query.end(), |
4353 |
23 Aug 23 |
peter |
49 |
utility::mAlignerBase::MatchKernel(4)); |
4340 |
16 Apr 23 |
peter |
50 |
if (aligner.score() != score) { |
4340 |
16 Apr 23 |
peter |
51 |
suite.out() << "score: " << aligner.score() << "\n"; |
4340 |
16 Apr 23 |
peter |
52 |
suite.err() << "error: incorrect score; expected: " << score << "\n"; |
4340 |
16 Apr 23 |
peter |
53 |
suite.add(false); |
4340 |
16 Apr 23 |
peter |
54 |
} |
4340 |
16 Apr 23 |
peter |
55 |
if (aligner.cigar() != cigar) { |
4340 |
16 Apr 23 |
peter |
56 |
suite.out() << "cigar: " << aligner.cigar() << "\n"; |
4340 |
16 Apr 23 |
peter |
57 |
suite.err() << "error: incorrect cigar; expected: " << cigar << "\n"; |
4340 |
16 Apr 23 |
peter |
58 |
suite.add(false); |
4340 |
16 Apr 23 |
peter |
59 |
} |
4340 |
16 Apr 23 |
peter |
60 |
if (aligner.cigar2() != cigar2) { |
4340 |
16 Apr 23 |
peter |
61 |
suite.out() << "cigar2: " << aligner.cigar2() << "\n"; |
4340 |
16 Apr 23 |
peter |
62 |
suite.err() << "error: incorrect cigar2; expected: " << cigar2 << "\n"; |
4340 |
16 Apr 23 |
peter |
63 |
suite.add(false); |
4340 |
16 Apr 23 |
peter |
64 |
} |
4340 |
16 Apr 23 |
peter |
65 |
} |
4340 |
16 Apr 23 |
peter |
66 |
catch (std::exception& e) { |
4340 |
16 Apr 23 |
peter |
67 |
suite.err() << "what(): " << e.what() << "\n"; |
4340 |
16 Apr 23 |
peter |
68 |
suite.add(false); |
4340 |
16 Apr 23 |
peter |
69 |
} |
4340 |
16 Apr 23 |
peter |
70 |
} |
4340 |
16 Apr 23 |
peter |
71 |
|
4340 |
16 Apr 23 |
peter |
72 |
|
4340 |
16 Apr 23 |
peter |
73 |
void check_nw(const std::string& ref, const std::string& query, |
4340 |
16 Apr 23 |
peter |
74 |
double score, const std::string& cigar, |
4340 |
16 Apr 23 |
peter |
75 |
const std::string& cigar2, test::Suite& suite) |
4340 |
16 Apr 23 |
peter |
76 |
{ |
4340 |
16 Apr 23 |
peter |
77 |
suite.out() << "check NeedlemanWunsch\n"; |
4340 |
16 Apr 23 |
peter |
78 |
mNeedlemanWunsch aligner(1, 6); |
4340 |
16 Apr 23 |
peter |
79 |
check_aligner(aligner, ref, query, score, cigar, cigar2, suite); |
4340 |
16 Apr 23 |
peter |
80 |
} |
4340 |
16 Apr 23 |
peter |
81 |
|
4340 |
16 Apr 23 |
peter |
82 |
|
4340 |
16 Apr 23 |
peter |
83 |
void check_sla(const std::string& ref, const std::string& query, |
4340 |
16 Apr 23 |
peter |
84 |
double score, const std::string& cigar, |
4340 |
16 Apr 23 |
peter |
85 |
const std::string& cigar2, test::Suite& suite) |
4340 |
16 Apr 23 |
peter |
86 |
{ |
4340 |
16 Apr 23 |
peter |
87 |
suite.out() << "check SemiLocalAligner\n"; |
4340 |
16 Apr 23 |
peter |
88 |
mSemiLocalAligner aligner(1, 6); |
4340 |
16 Apr 23 |
peter |
89 |
check_aligner(aligner, ref, query, score, cigar, cigar2, suite); |
4340 |
16 Apr 23 |
peter |
90 |
} |
4340 |
16 Apr 23 |
peter |
91 |
|
4340 |
16 Apr 23 |
peter |
92 |
|
4340 |
16 Apr 23 |
peter |
93 |
void check_sw(const std::string& ref, const std::string& query, |
4340 |
16 Apr 23 |
peter |
94 |
double score, const std::string& cigar,const std::string& cigar2, |
4340 |
16 Apr 23 |
peter |
95 |
test::Suite& suite) |
4340 |
16 Apr 23 |
peter |
96 |
{ |
4340 |
16 Apr 23 |
peter |
97 |
suite.out() << "check SmithWaterman\n"; |
4340 |
16 Apr 23 |
peter |
98 |
mSmithWaterman aligner(1, 6); |
4340 |
16 Apr 23 |
peter |
99 |
check_aligner(aligner, ref, query, score, cigar, cigar2, suite); |
4340 |
16 Apr 23 |
peter |
100 |
} |
4340 |
16 Apr 23 |
peter |
101 |
|
4340 |
16 Apr 23 |
peter |
102 |
|
4340 |
16 Apr 23 |
peter |
103 |
void check(test::Suite& suite, |
4340 |
16 Apr 23 |
peter |
104 |
const std::string& ref, const std::string& query, |
4340 |
16 Apr 23 |
peter |
105 |
double nw_score, const std::string& nw_cigar, |
4340 |
16 Apr 23 |
peter |
106 |
const std::string& nw_cigar2, |
4340 |
16 Apr 23 |
peter |
107 |
double sla_score, const std::string& sla_cigar, |
4340 |
16 Apr 23 |
peter |
108 |
const std::string& sla_cigar2, |
4340 |
16 Apr 23 |
peter |
109 |
double sw_score, const std::string& sw_cigar, |
4340 |
16 Apr 23 |
peter |
110 |
const std::string& sw_cigar2) |
4340 |
16 Apr 23 |
peter |
111 |
{ |
4340 |
16 Apr 23 |
peter |
112 |
suite.out() << "\nref: " << ref << "\n" |
4340 |
16 Apr 23 |
peter |
113 |
<< "query: " << query << "\n"; |
4340 |
16 Apr 23 |
peter |
114 |
check_nw(ref, query, nw_score, nw_cigar, nw_cigar2, suite); |
4340 |
16 Apr 23 |
peter |
115 |
check_sla(ref, query, sla_score, sla_cigar, sla_cigar2, suite); |
4340 |
16 Apr 23 |
peter |
116 |
check_sw(ref, query, sw_score, sw_cigar, sw_cigar2, suite); |
4340 |
16 Apr 23 |
peter |
117 |
} |
4340 |
16 Apr 23 |
peter |
118 |
|
4340 |
16 Apr 23 |
peter |
119 |
|
4340 |
16 Apr 23 |
peter |
120 |
int main(int argc, char* argv[]) |
4340 |
16 Apr 23 |
peter |
121 |
{ |
4340 |
16 Apr 23 |
peter |
122 |
test::Suite suite(argc, argv); |
4340 |
16 Apr 23 |
peter |
123 |
|
4340 |
16 Apr 23 |
peter |
124 |
check(suite, |
4340 |
16 Apr 23 |
peter |
125 |
"abcdefghijklmnopqrstuvwxyz", |
4340 |
16 Apr 23 |
peter |
126 |
"abcdefghijklmnxpqrstuvwxyz", |
4340 |
16 Apr 23 |
peter |
127 |
25-1*4, "26M", "14=1X11=", |
4340 |
16 Apr 23 |
peter |
128 |
25-1*4, "26M", "14=1X11=", |
4340 |
16 Apr 23 |
peter |
129 |
25-1*4, "26M", "14=1X11="); |
4340 |
16 Apr 23 |
peter |
130 |
|
4340 |
16 Apr 23 |
peter |
131 |
check(suite, |
4340 |
16 Apr 23 |
peter |
132 |
"abcdefghijklmnopqrstuvwxyz", |
4340 |
16 Apr 23 |
peter |
133 |
"abcdefghijklxxxpqrstuvwxyz", |
4340 |
16 Apr 23 |
peter |
134 |
12-3*4+11, "26M", "12=3X11=", |
4340 |
16 Apr 23 |
peter |
135 |
12-3*4+11, "26M", "12=3X11=", |
4340 |
16 Apr 23 |
peter |
136 |
12, "12M14S", "12=14S"); |
4340 |
16 Apr 23 |
peter |
137 |
|
4340 |
16 Apr 23 |
peter |
138 |
check(suite, |
4340 |
16 Apr 23 |
peter |
139 |
"abcdefghijklmnopqrstuvwxyz", |
4340 |
16 Apr 23 |
peter |
140 |
"abcdefhijklxxxpqrstuvwxyz", |
4340 |
16 Apr 23 |
peter |
141 |
6-7-3*4+16, "6M1D19M", "6=1D5=3X11=", |
4340 |
16 Apr 23 |
peter |
142 |
6-7-3*4+16, "6M1D19M", "6=1D5=3X11=", |
4353 |
23 Aug 23 |
peter |
143 |
11, "14S11M", "14S11="); |
4340 |
16 Apr 23 |
peter |
144 |
|
4340 |
16 Apr 23 |
peter |
145 |
check(suite, |
4340 |
16 Apr 23 |
peter |
146 |
"abcdefghijklmnopqrstuvwxyz", |
4340 |
16 Apr 23 |
peter |
147 |
"fghijklmnoqrstuvwahaxyz!", |
4353 |
23 Aug 23 |
peter |
148 |
-(6+5)+10-(6+1)+7-(6+3)+3-(6+1), "10M1D7M3I3M1I", "10=1D7=3I3=1I", |
4353 |
23 Aug 23 |
peter |
149 |
10-7+7-(6+7), "10M1D7M7I", "10=1D7=7I", |
4340 |
16 Apr 23 |
peter |
150 |
10, "10M14S", "10=14S"); |
4340 |
16 Apr 23 |
peter |
151 |
|
4340 |
16 Apr 23 |
peter |
// left clipped |
4340 |
16 Apr 23 |
peter |
153 |
check(suite, |
4340 |
16 Apr 23 |
peter |
154 |
"abcdefghijklmnopqrstuvwxyz", |
4340 |
16 Apr 23 |
peter |
155 |
"xxabcdefghijxlmnopqrstuvwxyz", |
4340 |
16 Apr 23 |
peter |
156 |
-(6+2)+10-4+15, "2S26M", "2S10=1X15=", |
4340 |
16 Apr 23 |
peter |
157 |
-(6+2)+10-4+15, "2S26M", "2S10=1X15=", |
4340 |
16 Apr 23 |
peter |
158 |
10-4+15, "2S26M", "2S10=1X15="); |
4340 |
16 Apr 23 |
peter |
159 |
|
4340 |
16 Apr 23 |
peter |
160 |
return suite.return_value(); |
4340 |
16 Apr 23 |
peter |
161 |
} |