1 | /* |
---|
2 | Copyright (c) 2006-2018 Elmar Pruesse <elmar.pruesse@ucdenver.edu> |
---|
3 | |
---|
4 | This file is part of SINA. |
---|
5 | SINA is free software: you can redistribute it and/or modify it under |
---|
6 | the terms of the GNU General Public License as published by the Free |
---|
7 | Software Foundation, either version 3 of the License, or (at your |
---|
8 | option) any later version. |
---|
9 | |
---|
10 | SINA is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
11 | WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
---|
13 | for more details. |
---|
14 | |
---|
15 | You should have received a copy of the GNU General Public License |
---|
16 | along with SINA. If not, see <http://www.gnu.org/licenses/>. |
---|
17 | |
---|
18 | Additional permission under GNU GPL version 3 section 7 |
---|
19 | |
---|
20 | If you modify SINA, or any covered work, by linking or combining it |
---|
21 | with components of ARB (or a modified version of that software), |
---|
22 | containing parts covered by the terms of the |
---|
23 | ARB-public-library-license, the licensors of SINA grant you additional |
---|
24 | permission to convey the resulting work. Corresponding Source for a |
---|
25 | non-source form of such a combination shall include the source code |
---|
26 | for the parts of ARB used as well as that of the covered work. |
---|
27 | */ |
---|
28 | |
---|
29 | #ifndef _SCORING_SCHEMES_H_ |
---|
30 | #define _SCORING_SCHEMES_H_ |
---|
31 | |
---|
32 | #include <vector> |
---|
33 | |
---|
34 | namespace sina { |
---|
35 | |
---|
36 | |
---|
37 | class scoring_scheme_profile { |
---|
38 | public: |
---|
39 | using value_type = float; |
---|
40 | |
---|
41 | scoring_scheme_profile(const value_type& _m, const value_type& _mm, |
---|
42 | const value_type& _gp, const value_type& _gpe) |
---|
43 | : match_score(_m), mismatch_score(_mm), |
---|
44 | gap_penalty(_gp), gap_extension_penalty(_gpe) |
---|
45 | {} |
---|
46 | |
---|
47 | template<typename base_type_a, typename base_type_b> |
---|
48 | value_type |
---|
49 | insertion(const value_type& prev, |
---|
50 | const base_type_a& /*b1*/, |
---|
51 | const base_type_b& /*b2*/) const |
---|
52 | { |
---|
53 | return prev + gap_penalty; |
---|
54 | } |
---|
55 | |
---|
56 | template<typename base_type_a, typename base_type_b> |
---|
57 | value_type |
---|
58 | insertion_ext(const value_type& prev, |
---|
59 | const base_type_a& /*b1*/, |
---|
60 | const base_type_b& /*b2*/, |
---|
61 | int /*offset*/) const |
---|
62 | { |
---|
63 | return prev + gap_extension_penalty; |
---|
64 | } |
---|
65 | |
---|
66 | template<typename base_type_a, typename base_type_b> |
---|
67 | value_type |
---|
68 | deletion(const value_type& prev, |
---|
69 | const base_type_a& /*b1*/, |
---|
70 | const base_type_b& /*b2*/) const |
---|
71 | { |
---|
72 | return prev + gap_penalty; |
---|
73 | } |
---|
74 | |
---|
75 | template<typename base_type_a, typename base_type_b> |
---|
76 | value_type |
---|
77 | deletion_ext(const value_type& prev, |
---|
78 | const base_type_a& /*b1*/, |
---|
79 | const base_type_b& /*b2*/, |
---|
80 | int /*offset*/) const |
---|
81 | { |
---|
82 | return prev + gap_extension_penalty; |
---|
83 | } |
---|
84 | |
---|
85 | template<typename base_type_a, typename base_type_b> |
---|
86 | value_type |
---|
87 | match(const value_type& prev, |
---|
88 | const base_type_a& b1, |
---|
89 | const base_type_b& b2) const |
---|
90 | { |
---|
91 | return prev + (b1.comp(b2, match_score, mismatch_score, |
---|
92 | gap_penalty, gap_extension_penalty)); |
---|
93 | } |
---|
94 | |
---|
95 | private: |
---|
96 | const value_type match_score; |
---|
97 | const value_type mismatch_score; |
---|
98 | const value_type gap_penalty; |
---|
99 | const value_type gap_extension_penalty; |
---|
100 | }; |
---|
101 | |
---|
102 | class scoring_scheme_simple { |
---|
103 | public: |
---|
104 | using value_type = float; |
---|
105 | |
---|
106 | scoring_scheme_simple(const value_type& _m, const value_type& _mm, |
---|
107 | const value_type& _gp, const value_type& _gpe) |
---|
108 | : match_score(_m), mismatch_score(_mm), |
---|
109 | gap_penalty(_gp), gap_extension_penalty(_gpe) |
---|
110 | {} |
---|
111 | |
---|
112 | template<typename base_type_a, typename base_type_b> |
---|
113 | value_type |
---|
114 | insertion(const value_type& prev, |
---|
115 | const base_type_a& /*b1*/, |
---|
116 | const base_type_b& /*b2*/) const |
---|
117 | { |
---|
118 | return prev + gap_penalty; |
---|
119 | } |
---|
120 | |
---|
121 | template<typename base_type_a, typename base_type_b> |
---|
122 | value_type |
---|
123 | insertion_ext(const value_type& prev, |
---|
124 | const base_type_a& /*b1*/, |
---|
125 | const base_type_b& /*b2*/, |
---|
126 | int /*offset*/) const |
---|
127 | { |
---|
128 | return prev + gap_extension_penalty; |
---|
129 | } |
---|
130 | |
---|
131 | template<typename base_type_a, typename base_type_b> |
---|
132 | value_type |
---|
133 | deletion(const value_type& prev, |
---|
134 | const base_type_a& /*b1*/, |
---|
135 | const base_type_b& /*b2*/) const |
---|
136 | { |
---|
137 | return prev + gap_penalty;// * b1.getWeight(); |
---|
138 | } |
---|
139 | |
---|
140 | template<typename base_type_a, typename base_type_b> |
---|
141 | value_type |
---|
142 | deletion_ext(const value_type& prev, |
---|
143 | const base_type_a& /*b1*/, |
---|
144 | const base_type_b& /*b2*/, |
---|
145 | int /*offset*/) const |
---|
146 | { |
---|
147 | return prev + gap_extension_penalty;// * b1.getWeight(); |
---|
148 | } |
---|
149 | |
---|
150 | template<typename base_type_a,typename base_type_b> |
---|
151 | value_type |
---|
152 | match(const value_type& prev, |
---|
153 | const base_type_a& b1, |
---|
154 | const base_type_b& b2) const |
---|
155 | { |
---|
156 | return prev + (b1.comp(b2)?match_score:mismatch_score) * b1.getWeight(); |
---|
157 | } |
---|
158 | |
---|
159 | private: |
---|
160 | const value_type match_score; |
---|
161 | const value_type mismatch_score; |
---|
162 | const value_type gap_penalty; |
---|
163 | const value_type gap_extension_penalty; |
---|
164 | }; |
---|
165 | |
---|
166 | class scoring_scheme_weighted { |
---|
167 | public: |
---|
168 | using value_type = float; |
---|
169 | |
---|
170 | scoring_scheme_weighted(const value_type& _m, const value_type& _mm, |
---|
171 | const value_type& _gp, const value_type& _gpe, |
---|
172 | std::vector<value_type>& _weights) |
---|
173 | : match_score(_m), mismatch_score(_mm), |
---|
174 | gap_penalty(_gp), gap_extension_penalty(_gpe), |
---|
175 | weights(_weights) |
---|
176 | {} |
---|
177 | |
---|
178 | template<typename base_type_a, typename base_type_b> |
---|
179 | value_type |
---|
180 | insertion(const value_type& prev, |
---|
181 | const base_type_a& b1, |
---|
182 | const base_type_b& /*b2*/) const |
---|
183 | { |
---|
184 | // the insertion will be placed in the column |
---|
185 | // immediately following the current column. use |
---|
186 | // the weight from that column. |
---|
187 | return prev + gap_penalty * weights[b1.getPosition() +1]; |
---|
188 | } |
---|
189 | |
---|
190 | template<typename base_type_a, typename base_type_b> |
---|
191 | value_type |
---|
192 | insertion_ext(const value_type& prev, |
---|
193 | const base_type_a& b1, |
---|
194 | const base_type_b& /*b2*/, |
---|
195 | int offset) const |
---|
196 | { |
---|
197 | // the insertion will be placed in the column |
---|
198 | // immediately following the current column plus |
---|
199 | // offset (number of previous insertions) |
---|
200 | return prev + gap_extension_penalty |
---|
201 | * weights[b1.getPosition() + 1 + offset]; |
---|
202 | } |
---|
203 | |
---|
204 | template<typename base_type_a, typename base_type_b> |
---|
205 | value_type |
---|
206 | deletion(const value_type& prev, |
---|
207 | const base_type_a& b1, |
---|
208 | const base_type_b& /*b2*/) const |
---|
209 | { |
---|
210 | // deletions always happen in current column |
---|
211 | return prev + gap_penalty * weights[b1.getPosition()];// * b1.getWeight(); |
---|
212 | } |
---|
213 | |
---|
214 | template<typename base_type_a, typename base_type_b> |
---|
215 | value_type |
---|
216 | deletion_ext(const value_type& prev, |
---|
217 | const base_type_a& b1, |
---|
218 | const base_type_b& /*b2*/, |
---|
219 | int /*offset*/) const |
---|
220 | { |
---|
221 | // deletions always happen in current column |
---|
222 | return prev + gap_extension_penalty |
---|
223 | * weights[b1.getPosition()] ;//* b1.getWeight(); |
---|
224 | } |
---|
225 | |
---|
226 | template<typename base_type_a, typename base_type_b> |
---|
227 | value_type |
---|
228 | match(const value_type& prev, |
---|
229 | const base_type_a& b1, |
---|
230 | const base_type_b& b2) const |
---|
231 | { |
---|
232 | return prev + (b1.comp(b2)?match_score:mismatch_score) * weights[b1.getPosition()] * b1.getWeight(); |
---|
233 | } |
---|
234 | |
---|
235 | private: |
---|
236 | const value_type match_score; |
---|
237 | const value_type mismatch_score; |
---|
238 | const value_type gap_penalty; |
---|
239 | const value_type gap_extension_penalty; |
---|
240 | std::vector<value_type>& weights; |
---|
241 | }; |
---|
242 | |
---|
243 | |
---|
244 | template<typename MATRIX_TYPE> |
---|
245 | class scoring_scheme_matrix { |
---|
246 | public: |
---|
247 | using value_type = float; |
---|
248 | using matrix_type = MATRIX_TYPE; |
---|
249 | |
---|
250 | scoring_scheme_matrix(const value_type& _gp, const value_type& _gpe, |
---|
251 | std::vector<value_type>& _weights, |
---|
252 | const matrix_type& _matrix) |
---|
253 | : gap_penalty(_gp), |
---|
254 | gap_extension_penalty(_gpe), |
---|
255 | weights(_weights), |
---|
256 | matrix(_matrix) |
---|
257 | {} |
---|
258 | |
---|
259 | template<typename base_type_a, typename base_type_b> |
---|
260 | value_type |
---|
261 | insertion(const value_type& prev, |
---|
262 | const base_type_a& b1, |
---|
263 | const base_type_b& /*b2*/) const |
---|
264 | { |
---|
265 | return prev + gap_penalty * weights[b1.getPosition()]; |
---|
266 | } |
---|
267 | |
---|
268 | template<typename base_type_a, typename base_type_b> |
---|
269 | value_type |
---|
270 | insertion_ext(const value_type& prev, |
---|
271 | const base_type_a& b1, |
---|
272 | const base_type_b& /*b2*/, |
---|
273 | int /*offset*/) const |
---|
274 | { |
---|
275 | return prev + gap_extension_penalty * weights[b1.getPosition()]; |
---|
276 | } |
---|
277 | |
---|
278 | template<typename base_type_a, typename base_type_b> |
---|
279 | value_type |
---|
280 | deletion(const value_type& prev, |
---|
281 | const base_type_a& b1, |
---|
282 | const base_type_b& b2) const |
---|
283 | { |
---|
284 | return insertion(prev, b1, b2); |
---|
285 | } |
---|
286 | |
---|
287 | template<typename base_type_a, typename base_type_b> |
---|
288 | value_type |
---|
289 | deletion_ext(const value_type& prev, |
---|
290 | const base_type_a& b1, |
---|
291 | const base_type_b& b2, |
---|
292 | int offset) const |
---|
293 | { |
---|
294 | return insertion_ext(prev, b1, b2, offset); |
---|
295 | } |
---|
296 | |
---|
297 | template<typename base_type_a, typename base_type_b> |
---|
298 | value_type |
---|
299 | match(const value_type& prev, |
---|
300 | const base_type_a& b1, |
---|
301 | const base_type_b& b2) const |
---|
302 | { |
---|
303 | return prev + b1.comp(b2,matrix) * weights[b1.getPosition()]; |
---|
304 | } |
---|
305 | |
---|
306 | private: |
---|
307 | const value_type gap_penalty; |
---|
308 | const value_type gap_extension_penalty; |
---|
309 | const std::vector<value_type>& weights; |
---|
310 | const matrix_type& matrix; |
---|
311 | }; |
---|
312 | |
---|
313 | |
---|
314 | } // namespace sina |
---|
315 | |
---|
316 | #endif // _MESH_H_ |
---|
317 | |
---|
318 | /* |
---|
319 | Local Variables: |
---|
320 | mode:c++ |
---|
321 | c-file-style:"stroustrup" |
---|
322 | c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . 0)) |
---|
323 | indent-tabs-mode:nil |
---|
324 | fill-column:99 |
---|
325 | End: |
---|
326 | */ |
---|
327 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : |
---|