Ymir  .9
Fast\C++toolforcomputationofassemblingprobabilities,statisticalinferenceofassemblingstatisticalmodelandgenerationofartificialsequencesofT-cellreceptorsdata.
gapped_alignment_vector.h
1 /*
2  * Ymir <imminfo.github.io/ymir>
3  *
4  * This file is part of Ymir, a fast C++ tool for computation of assembling
5  * probabilities, statistical inference of assembling statistical model
6  * and generation of artificial sequences of T-cell receptors data.
7  *
8  *
9  * Copyright 2015 Vadim Nazarov <vdn at mailbox dot com>
10  *
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  * http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  */
23 
24 #ifndef _GAPPED_ALIGNMENT_VECTOR_H_
25 #define _GAPPED_ALIGNMENT_VECTOR_H_
26 
27 
28 #include "alignment_vector_base.h"
29 
30 
31 namespace ymir {
32 
33 
38  inline void add_match(AlignmentVectorBase::events_storage_t *vec) { vec->push_back(false); vec->push_back(false); }
40 
41  inline void add_mismatch(AlignmentVectorBase::events_storage_t *vec) { vec->push_back(false); vec->push_back(true); }
42 
43  inline void add_ins(AlignmentVectorBase::events_storage_t *vec) { vec->push_back(true); vec->push_back(false); }
44 
45  inline void add_del(AlignmentVectorBase::events_storage_t *vec) { vec->push_back(true); vec->push_back(true); }
47 
48 
53 
54 
56 
57  }
58 
59 
60  void addAlignment(seg_index_t id, seq_len_t p_start, seq_len_t t_start, const events_storage_t &vec) {
61  _data.push_back(p_start);
62  _data.push_back(t_start);
63  _data.push_back(vec.size() / 2);
64  _data.push_back(id);
65  _starts.push_back(_events.size());
66  _events.insert(_events.end(), vec.begin(), vec.end());
67  }
68 
69 
73  bool isMatch(seq_len_t i, seq_len_t j) const {
75  --j;
76 #ifndef DNDEBUG
77  if (_starts[i] + j*2 + 1 >= _events.size()) {
78  throw(std::runtime_error("Alignment vector: index is out of bounds."));
79  }
80 #endif
81  return !(_events[_starts[i] + j*2] && _events[_starts[i] + j*2 + 1]);
82  }
83 
84  bool isMismatch(seq_len_t i, seq_len_t j) const {
85  --j;
86 #ifndef DNDEBUG
87  if (_starts[i] + j*2 + 1 >= _events.size()) {
88  throw(std::runtime_error("Alignment vector: index is out of bounds."));
89  }
90 #endif
91  return !_events[_starts[i] + j*2] && _events[_starts[i] + j*2 + 1];
92  }
93 
94  bool isIns(seq_len_t i, seq_len_t j) const {
95  --j;
96 #ifndef DNDEBUG
97  if (_starts[i] + j*2 + 1 >= _events.size()) {
98  throw(std::runtime_error("Alignment vector: index is out of bounds."));
99  }
100 #endif
101  return _events[_starts[i] + j*2] && !_events[_starts[i] + j*2 + 1];
102  }
103 
104  bool isDel(seq_len_t i, seq_len_t j) const {
105  --j;
106 #ifndef DNDEBUG
107  if (_starts[i] + j*2 + 1 >= _events.size()) {
108  throw(std::runtime_error("Alignment vector: index is out of bounds."));
109  }
110 #endif
111  return _events[_starts[i] + j*2] && _events[_starts[i] + j*2 + 1];
112  }
114 
115  };
116 
117 }
118 
119 #endif
events_storage_t _events
Vector of 4-tpuples - pattern start, text start, alignment length and a text ID.
Definition: alignment_vector_base.h:141
Definition: aligner.h:37
Definition: alignment_vector_base.h:41
Definition: gapped_alignment_vector.h:52
bool isMatch(seq_len_t i, seq_len_t j) const
Check if a some alignment has a specific events at a specific position.
Definition: gapped_alignment_vector.h:74