Ymir  .9
Fast\C++toolforcomputationofassemblingprobabilities,statisticalinferenceofassemblingstatisticalmodelandgenerationofartificialsequencesofT-cellreceptorsdata.
vdj_alignment_builder.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 _VDJ_ALIGNMENT_BUILDER_H_
25 #define _VDJ_ALIGNMENT_BUILDER_H_
26 
27 #include <iostream>
28 
29 #include "vdj_alignment.h"
30 
31 
32 namespace ymir {
33 
34 
35  struct VDJAlignmentBuilder : protected VDJAlignment {
36 
41  {
42  _segments.fill(0);
43  _n_Dalign.push_back(0);
44  }
45 
46 
47  virtual ~VDJAlignmentBuilder()
48  {
49  }
50 
51 
52  VDJAlignment buildAlignment() {
53  segments_storage_t segments;
54  segments[0] = _segments[0];
55  segments[1] = _segments[1];
56  segments[2] = _segments[2];
57 
58  n_D_alignments_storage_t nDs = _n_Dalign;
59  for (size_t i = 1; i < nDs.size(); ++i) {
60  nDs[i] += nDs[i-1];
61  }
62  // std::copy(_n_Dalign.begin(), _n_Dalign.end(), nDs.begin());
63 
65  avec.extend(_Valign);
66  avec.extend(_Jalign);
67  avec.extend(_Dalign);
68 
69  _Valign.clear();
70  _Jalign.clear();
71  _Dalign.clear();
72 
73  _segments.fill(0);
74  _n_Dalign.resize(1);
75 
76  // return std::move(VDJAlignment(std::move(segments), std::move(avec), std::move(nDs)));
77  // return VDJAlignment(std::move(segments), std::move(avec), std::move(nDs));
78  return VDJAlignment(segments, avec, nDs);
79  }
80 
81 
85  VDJAlignmentBuilder& addVarAlignment(seg_index_t vseg, seq_len_t vstart, seq_len_t seqstart, seq_len_t alignment_len) {
87  ++_segments[0];
88  _Valign.addAlignment(vseg, vstart, seqstart, alignment_len);
89  return *this;
90  }
91 
92 
93  VDJAlignmentBuilder& addJoiAlignment(seg_index_t jseg, seq_len_t jstart, seq_len_t seqstart, seq_len_t alignment_len) {
94  ++_segments[1];
95  _Jalign.addAlignment(jseg, jstart, seqstart, alignment_len);
96  return *this;
97  }
98 
99  VDJAlignmentBuilder& addDivAlignment(seg_index_t dseg, seq_len_t dstart, seq_len_t seqstart, seq_len_t alignment_len) {
100  if (_Dseg.size() == 0 || dseg != _Dseg[_Dseg.size() - 1]) {
101  _n_Dalign.push_back(0);
102  _Dseg.push_back(dseg);
103  ++_segments[2];
104  }
105 
106  ++_n_Dalign[_n_Dalign.size() - 1];
107 
108  _Dalign.addAlignment(dseg, dstart, seqstart, alignment_len);
109  return *this;
110  }
112 
113 
123  _Valign.extend(vec);
124  _segments[0] += vec.size();
125  return *this;
126  }
127 
128  VDJAlignmentBuilder& addJoiAlignment(const NoGapAlignmentVector &vec) {
129  _Jalign.extend(vec);
130  _segments[1] += vec.size();
131  return *this;
132  }
133 
134  VDJAlignmentBuilder& addDivAlignment(const NoGapAlignmentVector &vec) {
135  _n_Dalign.push_back(vec.size());
136  ++_segments[2];
137  _Dalign.extend(vec);
138  return *this;
139  }
141 
142 
143 // template <GeneSegments GENE>
144 // inline VDJAlignmentBuilder& addAlignment(seg_index_t seg_index, seq_len_t genestart, seq_len_t seqstart, seq_len_t alignment_len);
145 
146  inline VDJAlignmentBuilder& addAlignment(GeneSegments gene, seg_index_t seg_index, seq_len_t genestart, seq_len_t seqstart, seq_len_t alignment_len) {
147  switch (gene) {
148  case VARIABLE:
149  return this->addVarAlignment(seg_index, genestart, seqstart, alignment_len);
150  case JOINING:
151  return this->addJoiAlignment(seg_index, genestart, seqstart, alignment_len);
152  case DIVERSITY:
153  return this->addDivAlignment(seg_index, genestart, seqstart, alignment_len);
154  default:
155  return *this;
156  }
157  }
158 
159  protected:
160 
161  NoGapAlignmentVector _Valign, _Jalign, _Dalign;
162  std::vector<seg_index_t> _n_Dalign, _Dseg;
163 
164  };
165 
166 
167 // template <>
168 // VDJAlignmentBuilder& VDJAlignmentBuilder::addAlignment<VARIABLE>(seg_index_t seg_index, seq_len_t genestart, seq_len_t seqstart, seq_len_t alignment_len) {
169 // return this->addVarAlignment(seg_index, genestart, seqstart, alignment_len);
170 // }
171 //
172 //
173 // template <>
174 // VDJAlignmentBuilder& VDJAlignmentBuilder::addAlignment<DIVERSITY>(seg_index_t seg_index, seq_len_t genestart, seq_len_t seqstart, seq_len_t alignment_len) {
175 // return this->addDivAlignment(seg_index, genestart, seqstart, alignment_len);
176 // }
177 //
178 //
179 // template <>
180 // VDJAlignmentBuilder& VDJAlignmentBuilder::addAlignment<JOINING>(seg_index_t seg_index, seq_len_t genestart, seq_len_t seqstart, seq_len_t alignment_len) {
181 // return this->addJoiAlignment(seg_index, genestart, seqstart, alignment_len);
182 // }
183 
184 }
185 
186 #endif
VDJAlignmentBuilder & addVarAlignment(seg_index_t vseg, seq_len_t vstart, seq_len_t seqstart, seq_len_t alignment_len)
Add singular alignments to the builder.
Definition: vdj_alignment_builder.h:86
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
VDJAlignment()
Definition: vdj_alignment.h:226
Definition: vdj_alignment_builder.h:35
Definition: vdj_alignment.h:36
VDJAlignmentBuilder()
Move constructor for _segments, _alignments and _n_D_alignments.
Definition: vdj_alignment_builder.h:40