Ymir  .9
Fast\C++toolforcomputationofassemblingprobabilities,statisticalinferenceofassemblingstatisticalmodelandgenerationofartificialsequencesofT-cellreceptorsdata.
vdj_alignment.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_H_
25 #define _VDJ_ALIGNMENT_H_
26 
27 
28 #include <array>
29 
30 #include "nogap_alignment_vector.h"
31 
32 
33 namespace ymir {
34 
35 
36  struct VDJAlignment {
37 
38 
39  typedef std::array<seg_index_t, 3> segments_storage_t;
40 
41 
42  typedef std::vector<seg_index_t> n_D_alignments_storage_t;
43 
44 
45  VDJAlignment(const segments_storage_t &segments,
46  const NoGapAlignmentVector &alignments,
47  const n_D_alignments_storage_t &n_D_alignments)
48  : _segments(segments),
49  _alignments(alignments),
50  _n_D_alignments(n_D_alignments)
51  {
52  }
53 
54 
58 // VDJAlignment(segments_storage_t &&segments,
59 // NoGapAlignmentVector &&alignments,
60 // n_D_alignments_storage_t &&n_D_alignments)
61 // : _segments(std::move(segments)),
62 // _alignments(std::move(alignments)),
63 // _n_D_alignments(std::move(n_D_alignments))
64 // {
65 // }
66 
67 
68  // VDJAlignment(const VDJAlignment &other) {
69 
70  // }
71 
72 
73  // VDJAlignment& operator=(const VDJAlignment &other) {
74 
75  // }
76 
77 
78  virtual ~VDJAlignment()
79  {
80  }
81 
82 
83  bool operator==(const VDJAlignment &other) {
84  return _segments == other._segments
85  && _alignments == other._alignments
86  && _n_D_alignments == other._n_D_alignments;
87  }
88 
89  bool operator!=(const VDJAlignment &other) {
90  return _segments != other._segments
91  || _alignments != other._alignments
92  || _n_D_alignments != other._n_D_alignments;
93  }
94 
95 
99  seg_index_t nVar() const { return _segments[0]; }
101 
102  seg_index_t nJoi() const { return _segments[1]; }
103 
104  seg_index_t nDiv() const { return _segments[2]; }
106 
107 
111  seg_index_t getVar(size_t index) const { return _alignments.id(index); }
113 
114  seg_index_t getJoi(size_t index) const { return _alignments.id(_segments[0] + index); }
115 
116  seg_index_t getDiv(size_t index) const { return _alignments.id(_segments[0] + _segments[1] + _n_D_alignments[index]); }
118 
119 
123  seq_len_t getVarGeneStart(seg_index_t vgene) const {
125  return _alignments.pattern_start(vgene);
126  }
127 
128  seq_len_t getVarGeneEnd(seg_index_t vgene) const {
129  return _alignments.pattern_start(vgene) + _alignments.len(vgene) - 1;
130  }
131 
132  seq_len_t getVarSeqStart(seg_index_t vgene) const {
133  return _alignments.text_start(vgene);
134  }
135 
136  seq_len_t getVarSeqEnd(seg_index_t vgene) const {
137  return _alignments.text_start(vgene) + _alignments.len(vgene) - 1;
138  }
139 
140  seq_len_t getVarLen(seg_index_t vgene) const {
141  return _alignments.len(vgene);
142  }
143 
144  bool isVarMismatch(seg_index_t vgene, seq_len_t pos) const {
145  return _alignments.isMismatch(vgene, pos);
146  }
147 
148 
149  seq_len_t getJoiGeneStart(seg_index_t jgene) const {
150  return _alignments.pattern_start(_segments[0] + jgene);
151  }
152 
153  seq_len_t getJoiGeneEnd(seg_index_t jgene) const {
154  return _alignments.pattern_start(_segments[0] + jgene) + _alignments.len(_segments[0] + jgene) - 1;
155  }
156 
157  seq_len_t getJoiSeqStart(seg_index_t jgene) const {
158  return _alignments.text_start(_segments[0] + jgene);
159  }
160 
161  seq_len_t getJoiSeqEnd(seg_index_t jgene) const {
162  return _alignments.text_start(_segments[0] + jgene) + _alignments.len(_segments[0] + jgene) - 1;
163  }
164 
165  seq_len_t getJoiLen(seg_index_t jgene) const {
166  return _alignments.len(_segments[0] + jgene);
167  }
168 
169  bool isJoiMismatch(seg_index_t jgene, seq_len_t pos) const {
170  return _alignments.isMismatch(_segments[0] + jgene, pos);
171  }
172 
173 
174  seq_len_t getDivGeneStart(seg_index_t dgene, seg_index_t align_i) const {
175  return _alignments.pattern_start(_segments[0] + _segments[1] + _n_D_alignments[dgene] + align_i);
176  }
177 
178  seq_len_t getDivGeneEnd(seg_index_t dgene, seg_index_t align_i) const {
179  return _alignments.pattern_start(_segments[0] + _segments[1] + _n_D_alignments[dgene] + align_i)
180  + _alignments.len(_segments[0] + _segments[1] + _n_D_alignments[dgene] + align_i) - 1;
181  }
182 
183  seq_len_t getDivSeqStart(seg_index_t dgene, seg_index_t align_i) const {
184  return _alignments.text_start(_segments[0] + _segments[1] + _n_D_alignments[dgene] + align_i);
185  }
186 
187  seq_len_t getDivSeqEnd(seg_index_t dgene, seg_index_t align_i) const {
188  return _alignments.text_start(_segments[0] + _segments[1] + _n_D_alignments[dgene] + align_i)
189  + _alignments.len(_segments[0] + _segments[1] + _n_D_alignments[dgene] + align_i) - 1;
190  }
191 
192  seq_len_t getDivLen(seg_index_t dgene, seg_index_t align_i) const {
193  return _alignments.len(_segments[0] + _segments[1] + _n_D_alignments[dgene] + align_i);
194  }
195 
196  bool isDivMismatch(seg_index_t dgene, seg_index_t align_i, seq_len_t pos) const {
197  return _alignments.isMismatch(_segments[0] + _segments[1] + _n_D_alignments[dgene] + align_i, pos);
198  }
199 
200  error_num_t numDivMismatches(seg_index_t dgene, seg_index_t align_i, seq_len_t start, seq_len_t end) const {
201  return _alignments.numMismatches(_segments[0] + _segments[1] + _n_D_alignments[dgene] + align_i, start, end);
202  }
204 
205 
209  seq_len_t numDivAlignments(seg_index_t index) const {
210  return _n_D_alignments[index + 1] - _n_D_alignments[index];
211  }
212 
213 
214  protected:
215 
216  segments_storage_t _segments;
217 
220 
221  n_D_alignments_storage_t _n_D_alignments;
222 
225 
227 
228  };
229 
230 }
231 
232 #endif
Definition: aligner.h:37
virtual ~VDJAlignment()
Move constructor for _segments, _alignments and _n_D_alignments.
Definition: vdj_alignment.h:78
Definition: nogap_alignment_vector.h:37
seq_len_t numDivAlignments(seg_index_t index) const
Get the number of D gene alignments for the given D gene.
Definition: vdj_alignment.h:209
NoGapAlignmentVector _alignments
vector of indices of segments, aligned on this clone: V1–V2–V3–J1–J2–D1–D2–...
Definition: vdj_alignment.h:219
VDJAlignment()
Definition: vdj_alignment.h:226
n_D_alignments_storage_t _n_D_alignments
Vector of alignments for segments.
Definition: vdj_alignment.h:221
seg_index_t nVar() const
Get the number of alignments for the specific gene.
Definition: vdj_alignment.h:100
seq_len_t getVarGeneStart(seg_index_t vgene) const
Get alignments for the specific gene.
Definition: vdj_alignment.h:124
seg_index_t getVar(size_t index) const
Get the index of the aligned gene segment for the specific gene.
Definition: vdj_alignment.h:112
Definition: vdj_alignment.h:36