Ymir  .9
Fast\C++toolforcomputationofassemblingprobabilities,statisticalinferenceofassemblingstatisticalmodelandgenerationofartificialsequencesofT-cellreceptorsdata.
nogap_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 _NOGAP_ALIGNMENT_VECTOR_H_
25 #define _NOGAP_ALIGNMENT_VECTOR_H_
26 
27 
28 #include "alignment_vector_base.h"
29 #include "multimatrixchain.h"
30 
31 
32 namespace ymir {
33 
38 
39 
41 
42  }
43 
44 
54  void addAlignment(seg_index_t id, seq_len_t p_start, seq_len_t t_start, seq_len_t size) {
56  _data.push_back(p_start);
57  _data.push_back(t_start);
58  _data.push_back(size);
59  _data.push_back(id);
60  }
61 
62  void addAlignment(seg_index_t id, seq_len_t p_start, seq_len_t t_start, const events_storage_t &vec) {
63  _data.push_back(p_start);
64  _data.push_back(t_start);
65  _data.push_back(vec.size());
66  _data.push_back(id);
67  _starts.push_back(_events.size());
68  _events.insert(_events.end(), vec.begin(), vec.end());
69  }
71 
72 
76  bool isMismatch(seq_len_t i, seq_len_t j) const {
77 #ifndef DNDEBUG
78  check_and_throw(_events.size() == 0, "Alignment vector: no errors stored in the vector.");
79 
80  if (_starts[i] + j - 1 >= _events.size()) {
81  std::cout << (int) _starts.size() << std::endl;
82  std::cout << (int) i << std::endl;
83  std::cout << (int) _starts[i] << std::endl;
84  std::cout << (int) j << std::endl;
85  std::cout << (int) _events.size() << std::endl;
86  throw(std::runtime_error("Alignment vector: mismatch index is out of bounds."));
87  }
88 #endif
89  return _events[_starts[i] + j - 1];
90  }
91 
92 
93  error_num_t numMismatches(seq_len_t i, seq_len_t start, seq_len_t end) const {
94 #ifndef DNDEBUG
95  check_and_throw(_events.size() == 0, "Alignment vector: no errors stored in the vector.");
96 
97  if (_starts[i] + start - 1 >= _events.size()) {
98  throw(std::runtime_error("Alignment vector: start index is out of bounds."));
99  }
100  if (_starts[i] + end - 1 >= _events.size()) {
101  throw(std::runtime_error("Alignment vector: end index is out of bounds."));
102  }
103 #endif
104  error_num_t res = 0;
105  for (size_t j = start; j <= end; ++j) {
106  res += static_cast<error_num_t>(_events[_starts[i] + j - 1]);
107  }
108  return res;
109  }
110 
111  };
112 
113 }
114 
115 #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: 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: alignment_vector_base.h:41