24 #ifndef _MODELPARAMETERVECTOR_H_ 25 #define _MODELPARAMETERVECTOR_H_ 84 const vector<prob_t>& param_vec,
85 const vector<event_ind_t>& lens_vec,
86 const vector<event_ind_t>& event_classes,
87 const vector<seq_len_t>& event_family_col_numbers,
88 const vector<prob_t>& laplace_vec = vector<prob_t>(),
90 bool do_normalise =
true,
91 const vector<seq_len_t>& d_genes_min_len = vector<seq_len_t>())
96 _vec = vector<prob_t>();
97 _vec.reserve(param_vec.size() + 1);
99 _vec.insert(_vec.end(), param_vec.begin(), param_vec.end());
101 _event_classes = vector<event_ind_t>();
102 _event_classes.reserve(event_classes.size() + 1);
103 _event_classes.push_back(0);
104 for (event_ind_t i = 0; i < event_classes.size(); ++i) {
105 _event_classes.push_back(event_classes[i] + 1);
108 _event_family_col_numbers = vector<seq_len_t>();
109 _event_family_col_numbers.reserve(event_family_col_numbers.size() + 1);
110 _event_family_col_numbers.push_back(0);
111 for (event_ind_t i = 0; i < event_family_col_numbers.size(); ++i) {
112 _event_family_col_numbers.push_back(event_family_col_numbers[i]);
115 _edges.reserve(lens_vec.size() + 4);
118 for (event_ind_t i = 0; i < lens_vec.size(); ++i) {
119 _edges.push_back(_edges[i + 1] + lens_vec[i]);
121 _edges.push_back(_vec.size());
122 _event_classes.push_back(_edges.size() - 1);
124 _laplace = vector<prob_t>();
125 if (laplace_vec.size()) {
126 _laplace.reserve(laplace_vec.size() + 1);
127 _laplace.push_back(0);
128 for (event_ind_t i = 0; i < laplace_vec.size(); ++i) {
129 _laplace.push_back(laplace_vec[i]);
133 _laplace.resize(_edges.size() - 2, 0);
136 _d_genes_min_len = vector<seq_len_t>();
137 if (vec_type == VDJ_RECOMB) {
138 if (d_genes_min_len.size()) {
139 _d_genes_min_len = d_genes_min_len;
141 _d_genes_min_len.resize(this->eventClassSize(VDJ_DIV_DEL), DEFAULT_DIV_GENE_MIN_LEN);
146 this->normaliseEventFamilies();
152 if ((_recomb != other._recomb)
153 || (_err_prob != other._err_prob)
154 || (_vec.size() != other._vec.size())
155 || (_edges.size() != other._edges.size())
156 || (_event_classes.size() != other._event_classes.size())
157 || (_event_family_col_numbers.size() != other._event_family_col_numbers.size())
158 || (_laplace.size() != other._laplace.size())
159 || (_d_genes_min_len.size() != other._d_genes_min_len.size())) {
163 for (
size_t i = 0; i < _vec.size(); ++i) {
if (_vec[i] != other._vec[i]) {
return false; } }
164 for (
size_t i = 0; i < _edges.size(); ++i) {
if (_edges[i] != other._edges[i]) {
return false; } }
165 for (
size_t i = 0; i < _event_classes.size(); ++i) {
if (_event_classes[i] != other._event_classes[i]) {
return false; } }
166 for (
size_t i = 0; i < _event_family_col_numbers.size(); ++i) {
if (_event_family_col_numbers[i] != other._event_family_col_numbers[i]) {
return false; } }
167 for (
size_t i = 0; i < _laplace.size(); ++i) {
if (_laplace[i] != other._laplace[i]) {
return false; } }
168 for (
size_t i = 0; i < _d_genes_min_len.size(); ++i) {
if (_d_genes_min_len[i] != other._d_genes_min_len[i]) {
return false; } }
174 Recombination recombination()
const {
return _recomb; }
180 event_ind_t eventFamilySize(event_ind_t event_family)
const {
182 if (event_family >= _edges.size() || event_family + 1 >= _edges.size()) {
183 throw(std::runtime_error(
"Index is out of bounds."));
186 return _edges[event_family + 1] - _edges[event_family];
189 event_ind_t eventFamilySize(event_ind_t event_class, event_ind_t event_family)
const {
191 if (event_class >= _event_classes.size()) {
192 throw(std::runtime_error(
"Index is out of bounds."));
195 return eventFamilySize(_event_classes[event_class] + event_family);
198 event_ind_t eventClassSize(event_ind_t event_class)
const {
200 if (event_class + 1 >= _event_classes.size()
201 || _event_classes[event_class + 1] >= _edges.size()
202 || event_class >= _event_classes.size()
203 || _event_classes[event_class] >= _edges.size()) {
204 throw(std::runtime_error(
"Index is out of bounds."));
207 return _edges[_event_classes[event_class + 1]] - _edges[_event_classes[event_class]];
220 prob_t& operator[] (event_ind_t gl_event_index) {
223 if (gl_event_index >= _vec.size()) {
224 throw(std::runtime_error(
"Index " + std::to_string(gl_event_index) +
" is out of bounds."));
227 return _vec[gl_event_index];
230 prob_t operator[] (event_ind_t gl_event_index)
const {
232 if (gl_event_index >= _vec.size()) {
233 throw(std::runtime_error(
"Index " + std::to_string(gl_event_index) +
" is out of bounds."));
236 return _vec[gl_event_index];
239 prob_t operator() (event_ind_t event_family, event_ind_t loc_event_index)
const {
241 if (event_family >= _edges.size() || (_edges[event_family] + loc_event_index) >= _vec.size()) {
242 throw(std::runtime_error(
"Index is out of bounds."));
245 return _vec[_edges[event_family] + loc_event_index];
249 vector<prob_t>::const_iterator get_iterator(event_ind_t i)
const {
251 if (i > _vec.size()) {
throw(std::runtime_error(
"Index is out of bounds.")); }
253 return _vec.begin() + i;
261 event_ind_t
event_index(EventClass event_class, event_ind_t event_family, event_ind_t event_index)
const {
263 if (!(_edges[_event_classes[event_class] + event_family] + event_index < _edges[_event_classes[event_class] + event_family + 1])) {
264 throw(std::runtime_error(
"Index " + std::to_string(event_class) +
":" + std::to_string(event_family) +
":" + std::to_string(event_index) +
" is out of bounds."));
268 return _edges[_event_classes[event_class] + event_family] + event_index;
271 event_ind_t event_index(EventClass event_class, event_ind_t event_family, event_ind_t event_row, event_ind_t event_column)
const {
273 if (event_class >= _event_classes.size()) {
274 throw(std::runtime_error(
"Index is out of bounds."));
277 if (_event_classes[event_class] + event_family >= _edges.size()) {
278 throw(std::runtime_error(
"Index is out of bounds."));
281 if (_event_classes[event_class] + event_family >= _event_family_col_numbers.size()) {
282 throw(std::runtime_error(
"Index is out of bounds."));
285 if ((_edges[_event_classes[event_class] + event_family]
286 + event_row * _event_family_col_numbers[_event_classes[event_class] + event_family] + event_column) >= _vec.size()) {
287 throw(std::runtime_error(
"Index is out of bounds."));
290 return _edges[_event_classes[event_class] + event_family]
291 + event_row * _event_family_col_numbers[_event_classes[event_class] + event_family] + event_column;
294 prob_t event_prob(EventClass event_class, event_ind_t event_family, event_ind_t event_index)
const {
296 if (this->event_index(event_class, event_family, event_index) >= _vec.size()) {
297 throw(std::runtime_error(
"Index " + std::to_string(event_class) +
":" + std::to_string(event_family) +
":" + std::to_string(event_index) +
" is out of bounds."));
300 return _vec[this->event_index(event_class, event_family, event_index)];
303 prob_t event_prob(EventClass event_class, event_ind_t event_family, event_ind_t event_row, event_ind_t event_column)
const {
305 if (this->event_index(event_class, event_family, event_row, event_column) >= _vec.size()) {
306 throw(std::runtime_error(
"Index is out of bounds."));
309 return _vec[this->event_index(event_class, event_family, event_row, event_column)];
318 for (event_ind_t i = 2; i < _edges.size(); ++i) {
319 prob_sum = _laplace[i-1] * (_edges[i] - _edges[i-1]);
320 for (event_ind_t j = _edges[i-1]; j < _edges[i]; ++j) {
325 for (event_ind_t j = _edges[i-1]; j < _edges[i]; ++j) {
326 _vec[j] = (_vec[j] + _laplace[i-1]) / prob_sum;
332 void normaliseEventClass(EventClass event_class) {
333 event_ind_t event_family = _event_classes[event_class];
335 prob_t prob_sum = _laplace[event_family] * (_edges[event_family + 1] - _edges[event_family]);
336 for (event_ind_t j = _edges[event_family]; j < _edges[event_family + 1]; ++j) {
341 for (event_ind_t j = _edges[event_family]; j < _edges[event_family + 1]; ++j) {
342 _vec[j] = (_vec[j] + _laplace[event_family]) / prob_sum;
351 event_ind_t max_VJ_ins_len()
const {
352 return this->eventFamilySize(VJ_VAR_JOI_INS_LEN, 0) - 1;
354 event_ind_t max_VD_ins_len()
const {
355 return this->eventFamilySize(VDJ_VAR_DIV_INS_LEN, 0) - 1;
357 event_ind_t max_DJ_ins_len()
const {
358 return this->eventFamilySize(VDJ_DIV_JOI_INS_LEN, 0) - 1;
365 inline seq_len_t D_min_len(event_ind_t d_index)
const {
return _d_genes_min_len[d_index - 1]; }
368 inline prob_t error_prob()
const {
return _err_prob; }
371 inline void set_error_prob(prob_t val) { _err_prob = val; }
379 for (
size_t i = 1; i < _vec.size(); ++i) {
387 void familyFill(event_ind_t event_family, prob_t val = 0) {
388 for (event_ind_t i = _edges[_event_classes[event_family]]; i < _edges[_event_classes[event_family + 1]]; ++i) {
394 size_t families()
const {
return _event_classes.size(); }
397 size_t size()
const {
return _vec.size(); }
400 seq_len_t n_columns(EventClass event_class, event_ind_t event_family = 0)
const {
402 if (event_class >= _event_classes.size()) {
403 throw(std::runtime_error(
"Wrong event class " + std::to_string(event_class)));
405 if ((_event_classes[event_class] + event_family) >= _event_family_col_numbers.size()) {
406 throw(std::runtime_error(
"Index " + std::to_string(_event_classes[event_class] + event_family) +
" is out of bounds."));
409 return _event_family_col_numbers[_event_classes[event_class] + event_family];
416 vector<event_ind_t> _edges;
417 vector<event_ind_t> _event_classes;
418 vector<seq_len_t> _event_family_col_numbers;
419 vector<prob_t> _laplace;
420 vector<seq_len_t> _d_genes_min_len;
421 Recombination _recomb;
event_ind_t event_index(EventClass event_class, event_ind_t event_family, event_ind_t event_index) const
Definition: modelparametervector.h:261
void normaliseEventFamilies()
Normalise each event family to have sum equal to 1.
Definition: modelparametervector.h:316
Class for storing parameters of assembling statistical model. Note: event with index 0 (zero) is "nul...
Definition: modelparametervector.h:68
ModelParameterVector(Recombination vec_type, const vector< prob_t > ¶m_vec, const vector< event_ind_t > &lens_vec, const vector< event_ind_t > &event_classes, const vector< seq_len_t > &event_family_col_numbers, const vector< prob_t > &laplace_vec=vector< prob_t >(), prob_t err_prob=0, bool do_normalise=true, const vector< seq_len_t > &d_genes_min_len=vector< seq_len_t >())
Definition: modelparametervector.h:83
void fill(prob_t val=0)
Fill the vector with the given value.
Definition: modelparametervector.h:377