28 #include "aligner_parameters.h" 29 #include "alignment_matrix.h" 30 #include "clonotype_builder.h" 31 #include "genesegment.h" 42 template <
typename AlignmentType,
typename V_Aligner,
typename D_Aligner,
typename J_Aligner>
60 : _genes(genes), _params(params)
79 AlignmentType alignVar(seg_index_t
id,
const sequence_t &sequence)
const {
82 this->_alignVar(
id, sequence, &vec);
86 AlignmentType alignDiv(seg_index_t
id,
const sequence_t &sequence)
const {
88 this->_alignDiv(
id, sequence, &vec);
92 AlignmentType alignJoi(seg_index_t
id,
const sequence_t &sequence)
const {
94 this->_alignJoi(
id, sequence, &vec);
110 for (seg_index_t
id = 1;
id <= _genes.V().max(); ++id) {
111 this->_alignVar(
id, _sequence, &vec);
113 this->addVarAlignment(vec);
114 return vec.size() != 0;
119 for (seg_index_t
id = 1;
id <= _genes.D().max(); ++id) {
121 this->_alignDiv(
id, _sequence, &vec);
123 this->addDivAlignment(vec);
126 return vec.size() != 0;
131 for (seg_index_t
id = 1;
id <= _genes.J().max(); ++id) {
132 this->_alignJoi(
id, _sequence, &vec);
134 this->addJoiAlignment(vec);
135 return vec.size() != 0;
145 V_Aligner _V_Aligner;
146 D_Aligner _D_Aligner;
147 J_Aligner _J_Aligner;
157 void _alignVar(seg_index_t
id,
const sequence_t &sequence, AlignmentType *vec)
const {
159 _V_Aligner(
id, _genes.V()[id].sequence, sequence, vec, _params);
162 void _alignDiv(seg_index_t
id,
const sequence_t &sequence, AlignmentType *vec)
const {
163 _D_Aligner(
id, _genes.D()[id].sequence, sequence, vec, _params);
166 void _alignJoi(seg_index_t
id,
const sequence_t &sequence, AlignmentType *vec)
const {
167 _J_Aligner(
id, _genes.J()[id].sequence, sequence, vec, _params);
273 void operator()(seg_index_t gene,
274 const sequence_t &pattern,
275 const sequence_t &text,
279 seq_len_t p_size = pattern.size(), t_size = text.size(), matches = 0;
281 for (seq_len_t i = 0; i < min(p_size, t_size); ++i) {
282 if (pattern[i] != text[i]) {
break; }
291 void operator()(seg_index_t gene,
292 const sequence_t &pattern,
293 const sequence_t &text,
297 seq_len_t match_min_len = params.min_D_len;
298 seq_len_t t_size = text.size(), p_size = pattern.size(), min_size = min(t_size, p_size), min_subsize;
300 seq_len_t p_start, t_start;
302 for (seq_len_t pattern_i = 0 ; pattern_i < p_size - match_min_len + 1; ++pattern_i) {
304 min_subsize = min(p_size - pattern_i, (
int) t_size);
305 for (seq_len_t i = 0; i < min_subsize; ++i) {
306 if (pattern[pattern_i + i] == text[i]) {
308 p_start = pattern_i + i;
312 }
else if (open_match) {
313 if ((pattern_i + i - p_start) >= match_min_len) {
314 avec->
addAlignment(gene, p_start + 1, t_start + 1, pattern_i + i - p_start);
319 if (open_match && (pattern_i + min_subsize - p_start) >= match_min_len) {
320 avec->
addAlignment(gene, p_start + 1, t_start + 1, pattern_i + min_subsize - p_start);
324 for (seq_len_t text_i = 1; text_i < t_size - match_min_len + 1; ++text_i) {
326 min_subsize = min((
int) p_size, t_size - text_i);
327 for (seq_len_t i = 0; i < min_subsize; ++i) {
328 if (pattern[i] == text[text_i + i]) {
331 t_start = text_i + i;
334 }
else if (open_match) {
335 if ((i - p_start) >= match_min_len) {
336 avec->
addAlignment(gene, p_start + 1, t_start + 1, i - p_start);
341 if (open_match && (min_subsize - p_start) >= match_min_len) {
342 avec->
addAlignment(gene, p_start + 1, t_start + 1, min_subsize - p_start);
349 void operator()(seg_index_t gene,
350 const sequence_t &pattern,
351 const sequence_t &text,
355 seq_len_t p_size = pattern.size(), t_size = text.size(), matches = 0;
357 for (seq_len_t i = 0; i < min(p_size, t_size); ++i) {
358 if (pattern[p_size - i - 1] != text[t_size - i - 1]) {
break; }
362 avec->
addAlignment(gene, p_size - matches + 1, t_size - matches + 1, matches);
388 void operator()(seg_index_t gene,
389 const sequence_t &pattern,
390 const sequence_t &text,
391 NoGapAlignmentVector *avec,
394 seq_len_t p_size = pattern.size(), t_size = text.size();
395 NoGapAlignment::events_storage_t vec;
396 vec.reserve(min(p_size, t_size) + 1);
397 alignment_score_t score = 0, val;
399 vec.push_back(pattern[0] != text[0]);
400 score += pattern[0] == text[0] ? params.score.v_score.match : params.score.v_score.mism;
401 for (seq_len_t i = 1; i < min(p_size, t_size); ++i) {
402 vec.push_back(pattern[i] != text[i]);
404 score += pattern[i] == text[i] ? (params.score.v_score.match + params.score.v_score.acc_match * (pattern[i - 1] == text[i - 1])) : params.score.v_score.mism;
409 if (score >= params.threshold.v_threshold) {
416 void operator()(seg_index_t gene,
417 const sequence_t &pattern,
418 const sequence_t &text,
419 NoGapAlignmentVector *avec,
422 seq_len_t match_min_len = params.min_D_len;
423 seq_len_t t_size = text.size(), p_size = pattern.size(), min_size = min(t_size, p_size), min_subsize;
424 seq_len_t p_start, t_start;
425 AlignmentVectorBase::events_storage_t bitvec;
426 bitvec.reserve(p_size + 1);
428 for (seq_len_t pattern_i = 0; pattern_i < p_size - match_min_len + 1; ++pattern_i) {
429 min_subsize = min(p_size - pattern_i, (
int) t_size);
430 if (min_subsize >= match_min_len) {
431 bitvec.resize(min_subsize);
432 for (seq_len_t i = 0; i < min_subsize; ++i) {
433 bitvec[i] = pattern[pattern_i + i] != text[i];
439 for (seq_len_t text_i = 1; text_i < t_size - match_min_len + 1; ++text_i) {
440 min_subsize = min((
int) p_size, t_size - text_i);
441 if (min_subsize >= match_min_len) {
442 bitvec.resize(min_subsize);
443 for (seq_len_t i = 0; i < min_subsize; ++i) {
444 bitvec[i] = pattern[i] != text[text_i + i];
453 void operator()(seg_index_t gene,
454 const sequence_t &pattern,
455 const sequence_t &text,
456 NoGapAlignmentVector *avec,
459 seq_len_t p_size = pattern.size(), t_size = text.size();
460 NoGapAlignment::events_storage_t vec;
461 vec.reserve(min(p_size, t_size) + 1);
462 alignment_score_t score = 0, val;
464 vec.insert(vec.begin(), pattern[p_size - 1] != text[t_size - 1]);
465 for (seq_len_t i = 1; i < min(p_size, t_size); ++i) {
466 vec.insert(vec.begin(), pattern[p_size - i - 1] != text[t_size - i - 1]);
468 score += pattern[p_size - i - 1] == text[t_size - i - 1] ? (params.score.j_score.match + params.score.j_score.acc_match * (pattern[p_size - i] == text[t_size - i])) : params.score.j_score.mism;
473 if (score >= params.threshold.j_threshold) {
474 avec->
addAlignment(gene, p_size - min(t_size, p_size) + 1, t_size - min(t_size, p_size) + 1, vec);
500 void operator()(seg_index_t gene,
501 const sequence_t &pattern,
502 const sequence_t &text,
508 mat.getBestAlignment(avec, pattern, text);
518 void operator()(seg_index_t gene,
519 const sequence_t &pattern,
520 const sequence_t &text,
524 check_and_throw(
false,
"SWAlignerFunctor_D has not been implemented yet");
556 void operator()(seg_index_t gene,
557 const sequence_t &pattern,
558 const sequence_t &text,
559 NoGapAlignmentVector *avec,
564 for (seq_len_t col_i = 0; col_i < text.size(); ++col_i) {
565 for (seq_len_t row_i = 0; row_i < pattern.size(); ++row_i) {
566 mat.score(row_i + 1, col_i + 1) = std::max({mat.score(row_i, col_i) + (text[col_i] == pattern[row_i] ? params.score.v_score.match : params.score.v_score.mism), .0});
570 mat.getBestAlignment(avec, pattern, text);
575 void operator()(seg_index_t gene,
576 const sequence_t &pattern,
577 const sequence_t &text,
578 NoGapAlignmentVector *avec,
582 seq_len_t match_min_len = params.min_D_len;
583 seq_len_t t_size = text.size(), p_size = pattern.size(), min_size = min(t_size, p_size), min_subsize;
584 seq_len_t p_start, t_start;
585 AlignmentVectorBase::events_storage_t bitvec;
586 bitvec.reserve(p_size + 1);
588 for (seq_len_t pattern_i = 0; pattern_i < p_size - match_min_len + 1; ++pattern_i) {
589 min_subsize = min(p_size - pattern_i, (
int) t_size);
590 if (min_subsize >= match_min_len) {
591 bitvec.resize(min_subsize);
592 for (seq_len_t i = 0; i < min_subsize; ++i) {
593 bitvec[i] = pattern[pattern_i + i] != text[i];
599 for (seq_len_t text_i = 1; text_i < t_size - match_min_len + 1; ++text_i) {
600 min_subsize = min((
int) p_size, t_size - text_i);
601 if (min_subsize >= match_min_len) {
602 bitvec.resize(min_subsize);
603 for (seq_len_t i = 0; i < min_subsize; ++i) {
604 bitvec[i] = pattern[i] != text[text_i + i];
613 void operator()(seg_index_t gene,
614 const sequence_t &pattern,
615 const sequence_t &text,
616 NoGapAlignmentVector *avec,
621 for (seq_len_t col_i = 0; col_i < text.size(); ++col_i) {
622 for (seq_len_t row_i = 0; row_i < pattern.size(); ++row_i) {
623 mat.score(row_i + 1, col_i + 1) = std::max({mat.score(row_i, col_i) + (text[col_i] == pattern[row_i] ? params.score.j_score.match : params.score.j_score.mism), .0});
627 mat.getBestAlignment(avec, pattern, text);
Definition: aligner.h:348
Definition: aligner.h:574
Definition: aligner_parameters.h:129
Definition: aligner.h:290
Definition: aligner.h:499
Definition: nogap_alignment_vector.h:37
void addAlignment(seg_index_t id, seq_len_t p_start, seq_len_t t_start, seq_len_t size)
Add a new alignment to the vector.
Definition: nogap_alignment_vector.h:55
Definition: aligner.h:452
Definition: genesegment.h:265
Definition: aligner.h:272
Definition: aligner.h:612
Definition: clonotype_builder.h:37
Definition: aligner.h:415
Definition: aligner.h:517
Definition: gapped_alignment_vector.h:52
Definition: aligner.h:555
Definition: aligner.h:387