Ymir  .9
Fast\C++toolforcomputationofassemblingprobabilities,statisticalinferenceofassemblingstatisticalmodelandgenerationofartificialsequencesofT-cellreceptorsdata.
clonotype.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 _CLONOTYPE_H
25 #define _CLONOTYPE_H
26 
27 
28 #include "alignment.h"
29 
30 
31 namespace ymir {
32 
33 
34  struct Clonotype;
35 
36 
40  typedef unique_ptr<Clonotype> ClonotypePtr;
41 
42 
46  struct Clonotype : public VDJAlignment {
47 
48  Clonotype(const sequence_t &sequence,
49  SequenceType seq_type,
50  Recombination recomb,
51  const segments_storage_t &segments,
52  const NoGapAlignmentVector &alignments,
53  const n_D_alignments_storage_t &n_D_alignments)
54  : VDJAlignment(segments, alignments, n_D_alignments),
55  _sequence(sequence),
56  _seq_type(seq_type),
57  _recomb(recomb),
58  _good(segments[0] && segments[1] && ((segments[2] && recomb == VDJ_RECOMB) || recomb == VJ_RECOMB))
59  {
60  }
61 
62 
63  Clonotype(const sequence_t &sequence,
64  SequenceType seq_type,
65  Recombination recomb,
66  VDJAlignment alignment)
67  : VDJAlignment(alignment),
68  _sequence(sequence),
69  _seq_type(seq_type),
70  _recomb(recomb),
71  _good(alignment.nVar() && alignment.nJoi() && ((alignment.nDiv() && recomb == VDJ_RECOMB) || recomb == VJ_RECOMB))
72  {
73  }
74 
75 
76  virtual ~Clonotype()
77  {
78  }
79 
80 
89  const sequence_t& sequence() const { return _sequence; }
91 
92  const sequence_t& nuc_sequence() const {
93 #ifndef DNDEBUG
94  check_and_throw(_seq_type != NUCLEOTIDE, "Clonotype's call to nuc_sequence() is incorrect: wrong sequence type.");
95 #endif
96  return _sequence;
97  }
98 
99  sequence_t aa_sequence() const {
100 #ifndef DNDEBUG
101  check_and_throw(_seq_type == UNDEF_SEQ_TYPE, "Clonotype's call to aa_sequence() is incorrect: undefined sequence type.");
102 #endif
103  if (_seq_type == NUCLEOTIDE) {
104  return translate(_sequence);
105  } else {
106  return _sequence;
107  }
108  }
110 
111 
112  sequence_t::const_iterator seq_iterator(seq_len_t pos) const { return _sequence.cbegin() + pos; }
113 
114 
115  Recombination recombination() const { return _recomb; }
116 
117 
118  SequenceType sequence_type() const { return _seq_type; }
119 
120 
124  bool isCoding() const {
126  if (_seq_type == NUCLEOTIDE) {
127  return !(is_out_of_frame(_sequence) || has_end_codon(_sequence));
128  } else {
129  return !has_bad_aa_codons(_sequence);
130  }
131  }
132 
133  bool isNoncoding() const {
134  if (_seq_type == NUCLEOTIDE) {
135  return is_out_of_frame(_sequence) || has_end_codon(_sequence);
136  } else {
137  return has_bad_aa_codons(_sequence);
138  }
139  }
140 
141  bool isOutOfFrame() const {
142  if (_seq_type == NUCLEOTIDE) {
143  return is_out_of_frame(_sequence);
144  } else {
145  return has_oof_aa_codon(_sequence);
146  }
147  }
149 
153  std::string toString() const {
154  std::string res = "";
155  res += this->nuc_sequence() + "\t";
156  res += "V:" + std::to_string(_segments[0]) + "\t";
157  res += "D:" + std::to_string(_segments[2]) + "\t";
158  res += "J:" + std::to_string(_segments[1]);
159  return res;
160  }
161 
162  bool is_good() const { return _good; }
163 
164  protected:
165 
166  Recombination _recomb;
167 
168  SequenceType _seq_type;
169 
170  sequence_t _sequence; //* CDR3 or full nucleotide or amino acid sequence of a clone. */
171 
172  bool _good;
173 
174 
178  Clonotype() {}
179 
180  };
181 
182 }
183 
184 #endif
Definition: aligner.h:37
Definition: nogap_alignment_vector.h:37
std::string toString() const
Return the string representation of the clonotype.
Definition: clonotype.h:153
Definition: clonotype.h:46
VDJAlignment()
Definition: vdj_alignment.h:226
bool isCoding() const
Check if clonotype&#39;s sequence is coding, noncoding or out-of-frame.
Definition: clonotype.h:125
seg_index_t nVar() const
Get the number of alignments for the specific gene.
Definition: vdj_alignment.h:100
Definition: vdj_alignment.h:36
const sequence_t & sequence() const
Get the sequence of this Clonotype.
Definition: clonotype.h:90