Ymir  .9
Fast\C++toolforcomputationofassemblingprobabilities,statisticalinferenceofassemblingstatisticalmodelandgenerationofartificialsequencesofT-cellreceptorsdata.
alignment_vector_base.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 _ALIGNMENT_VECTOR_BASE_H_
25 #define _ALIGNMENT_VECTOR_BASE_H_
26 
27 
28 #include <string>
29 #include <vector>
30 
31 #include "alignment.h"
32 #include "tools.h"
33 #include "types.h"
34 
35 
36 namespace ymir {
37 
42 
43 
44  typedef std::vector<bool> events_storage_t;
45 
46 
47  static const size_t default_start_reserve_size = 20;
48 
49  static const size_t default_events_reserve_size = 600;
50 
51 
53  _events.reserve(default_events_reserve_size);
54  _starts.reserve(default_start_reserve_size);
55  }
56 
57 
58  // waiting until C++14 for full support?
59  // AlignmentVectorBase(AlignmentVectorBase &&other)
60  // : _data(std::move(other._data)),
61  // _events(std::move(other._events)),
62  // _starts(std::move(other._starts))
63  // {
64  // }
65 
66  bool operator==(const AlignmentVectorBase &other) {
67  return _data == other._data
68  && _events == other._events
69  && _starts == other._starts;
70  }
71 
72  bool operator!=(const AlignmentVectorBase &other) {
73  return _data != other._data
74  || _events != other._events
75  || _starts != other._starts;
76  }
77 
78 
79  void extend(const AlignmentVectorBase &other) {
80  if (other.size()) {
81  _data.reserve(_data.size() + other._data.size() + 1);
82  _data.insert(_data.end(), other._data.begin(), other._data.end());
83 
84  _starts.reserve(_starts.size() + other._starts.size() + 1);
85  size_t events_size = _events.size();
86  for (size_t i = 0; i < other._starts.size(); ++i) {
87  _starts.push_back(events_size + other._starts[i]);
88  }
89 
90  _events.reserve(_events.size() + other._events.size() + 1);
91  _events.insert(_events.end(), other._events.begin(), other._events.end());
92  }
93  }
94 
95 
96  size_t size() const {
97  return _data.size() / 4;
98  }
99 
100 
101  void finish() {
102  _data.reserve(_data.size() + 1);
103  _events.reserve(_events.size() + 1);
104  }
105 
106 
107  void clear() {
108  _data.clear();
109  _starts.clear();
110  _events.clear();
111  }
112 
113 
114  seq_len_t pattern_start(seq_len_t i) const {
115  check_and_throw(i*4 >= _data.size(), "Alignment vector: pattern index " + std::to_string(i*4) + " is out of bounds (" + std::to_string(_data.size()) + ")");
116  return _data[i*4];
117  }
118 
119 
120  seq_len_t text_start(seq_len_t i) const {
121  check_and_throw(i*4 + 1 >= _data.size(), "Alignment vector: text index " + std::to_string(i*4 + 1) + " is out of bounds (" + std::to_string(_data.size()) + ")");
122  return _data[i*4 + 1];
123  }
124 
125 
126  seq_len_t len(seq_len_t i) const {
127  check_and_throw(i*4 + 2 >= _data.size(), "Alignment vector: length index " + std::to_string(i*4 + 2) + " is out of bounds (" + std::to_string(_data.size()) + ")");
128  return _data[i*4 + 2];
129  }
130 
131 
132  seq_len_t id(seq_len_t i) const {
133  check_and_throw(i*4 + 3 >= _data.size(), "Alignment vector: ID index " + std::to_string(i*4 + 3) + " is out of bounds (" + std::to_string(_data.size()) + ")");
134  return _data[i*4 + 3];
135  }
136 
137 
138  protected:
139 
140  std::vector<seq_len_t> _data;
141  events_storage_t _events;
142  std::vector<size_t> _starts;
143 
144  };
145 
146 }
147 
148 #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