libpappsomspp
Library for mass spectrometry
aa.cpp
Go to the documentation of this file.
1 /**
2  * \file pappsomspp/amino_acid/aaBase.cpp
3  * \date 7/3/2015
4  * \author Olivier Langella
5  * \brief amino acid model
6  */
7 
8 /*******************************************************************************
9  * Copyright (c) 2015 Olivier Langella <Olivier.Langella@moulon.inra.fr>.
10  *
11  * This file is part of the PAPPSOms++ library.
12  *
13  * PAPPSOms++ is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation, either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * PAPPSOms++ is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
25  *
26  * Contributors:
27  * Olivier Langella <Olivier.Langella@moulon.inra.fr> - initial API and
28  *implementation
29  ******************************************************************************/
30 
31 #include "aa.h"
32 #include <QDebug>
33 #include <vector>
34 #include <QStringList>
35 #include <algorithm>
36 
37 
38 namespace pappso
39 {
40 
41 Aa::Aa(char aa_letter) : AaBase(aa_letter)
42 {
43 }
44 
45 
46 Aa::Aa(AminoAcidChar aa_char) : AaBase(aa_char)
47 {
48 }
49 
50 Aa::Aa(const Aa &other) : AaBase(other), m_listMod(other.m_listMod)
51 {
52 }
53 
54 
55 Aa::Aa(Aa &&toCopy) // move constructor
56  : AaBase(toCopy), m_listMod(std::move(toCopy.m_listMod))
57 {
58 }
59 
61 {
62 }
63 
64 Aa &
65 Aa::operator=(const Aa &toCopy)
66 {
67  m_aaLetter = toCopy.m_aaLetter;
68  m_listMod = toCopy.m_listMod;
69  return *this;
70 }
71 
72 const std::vector<AaModificationP> &
74 {
75  return m_listMod;
76 }
77 
79 Aa::getMass() const
80 {
81  // qDebug() << "Aa::getMass() begin";
83  for(auto &&mod : m_listMod)
84  {
85  mass += mod->getMass();
86  }
87 
88  // qDebug() << "Aa::getMass() end " << mass;
89  return mass;
90 }
91 
92 const QString
94 {
95  QString seq = "";
96  seq += this->getLetter();
97  auto it(m_listMod.begin());
98  if(it != m_listMod.end())
99  {
100  QStringList modification_str_list;
101  while(it != m_listMod.end())
102  {
103  modification_str_list << (*it)->getAccession();
104  it++;
105  }
106  if(modification_str_list.size() > 0)
107  seq += QString("(%1)").arg(modification_str_list.join(","));
108  }
109  return seq;
110 }
111 
112 const QString
114 {
115  QString seq = "";
116  seq += this->getLetter();
117  auto it(m_listMod.begin());
118  if(it != m_listMod.end())
119  {
120  QStringList modification_str_list;
121  while(it != m_listMod.end())
122  {
123  if(!(*it)->isInternal())
124  {
125  modification_str_list << (*it)->getAccession();
126  }
127  it++;
128  }
129  if(modification_str_list.size() > 0)
130  seq += QString("(%1)").arg(modification_str_list.join(","));
131  }
132  return seq;
133 }
134 
135 
136 void
138 {
139  std::vector<AaModificationP>::iterator it =
140  std::find(m_listMod.begin(), m_listMod.end(), mod);
141  if(it != m_listMod.end())
142  {
143  m_listMod.erase(it);
144  }
145 
146  qDebug() << m_listMod << Qt::endl;
147 }
148 
149 void
151 {
152  qDebug() << "Aa::addAaModification begin";
153  qDebug() << aaModification->getAccession();
154  m_listMod.push_back(aaModification);
155  sort(m_listMod.begin(), m_listMod.end());
156 }
157 
158 void
160 {
161  std::replace(m_listMod.begin(), m_listMod.end(), oldmod, newmod);
162  sort(m_listMod.begin(), m_listMod.end());
163 }
164 
165 int
167 {
168  int number_of_carbon = AaBase::getNumberOfAtom(atom);
169  for(auto &&mod : m_listMod)
170  {
171  number_of_carbon += mod->getNumberOfAtom(atom);
172  }
173 
174  // qDebug() << "Aa::getMass() end " << mass;
175  return number_of_carbon;
176 }
177 
178 
179 int
181 {
182  int number = 0;
183  for(auto &&mod : m_listMod)
184  {
185  number += mod->getNumberOfIsotope(isotope);
186  }
187 
188  // qDebug() << "Aa::getMass() end " << mass;
189  return number;
190 }
191 
192 unsigned int
194 {
195  unsigned int number_of_mod = 0;
196  for(auto &&modb : m_listMod)
197  {
198  if(modb == mod)
199  number_of_mod += 1;
200  }
201 
202  // qDebug() << "Aa::getMass() end " << mass;
203  return number_of_mod;
204 }
205 
208 {
209  for(auto &&modb : m_listMod)
210  {
211  if(modb->getAccession().startsWith("internal:Nter_"))
212  return modb;
213  }
214  return nullptr;
215 }
216 
219 {
220  for(auto &&modb : m_listMod)
221  {
222  if(modb->getAccession().startsWith("internal:Cter_"))
223  return modb;
224  }
225  return nullptr;
226 }
227 
228 void
230 {
231  std::remove_if(
232  m_listMod.begin(), m_listMod.end(), [](AaModificationP const &mod) {
233  return mod->getAccession().startsWith("internal:Nter_");
234  });
235 }
236 
237 void
239 {
240  std::remove_if(
241  m_listMod.begin(), m_listMod.end(), [](AaModificationP const &mod) {
242  return mod->getAccession().startsWith("internal:Cter_");
243  });
244 }
245 
246 bool
247 Aa::isLesser(Aa const &r) const
248 {
249  qDebug() << m_listMod << "//" << r.m_listMod;
250  // qDebug() << "operator<(const Aa& l, const Aa& r)";
251  if(m_aaLetter == r.m_aaLetter)
252  {
253  std::size_t a = m_listMod.size();
254  std::size_t b = r.m_listMod.size();
255 
256  if(a == b)
257  {
258  return (m_listMod < r.m_listMod);
259  }
260  else
261  {
262  return (a < b);
263  }
264  }
265  else
266  {
267  return (m_aaLetter < r.m_aaLetter);
268  }
269 }
270 
271 bool
272 Aa::isAaEqual(Aa const &r) const
273 {
274 
275  return (std::tie(m_aaLetter, m_listMod) ==
276  std::tie(r.m_aaLetter, r.m_listMod));
277 }
278 
279 bool
280 operator==(Aa const &l, Aa const &r)
281 {
282  return l.isAaEqual(r);
283 }
284 
285 bool
286 operator<(Aa const &l, Aa const &r)
287 {
288  return l.isLesser(r);
289 }
290 } /* namespace pappso */
virtual pappso_double getMass() const
Definition: aabase.cpp:387
char m_aaLetter
Definition: aabase.h:65
virtual const char & getLetter() const
Definition: aabase.cpp:434
virtual int getNumberOfAtom(AtomIsotopeSurvey atom) const override
get the number of atom C, O, N, H in the molecule
Definition: aabase.cpp:394
const QString & getAccession() const
Definition: aa.h:45
int getNumberOfAtom(AtomIsotopeSurvey atom) const override final
get the number of atom C, O, N, H in the molecule
Definition: aa.cpp:166
const QString toAbsoluteString() const
Definition: aa.cpp:93
void removeInternalCterModification()
Definition: aa.cpp:238
AaModificationP getInternalCterModification() const
Definition: aa.cpp:218
int getNumberOfIsotope(Isotope isotope) const override final
get the number of isotopes C13, H2, O17, O18, N15, S33, S34, S36 in the molecule
Definition: aa.cpp:180
Aa(char aa_letter)
Definition: aa.cpp:41
AaModificationP getInternalNterModification() const
Definition: aa.cpp:207
const std::vector< AaModificationP > & getModificationList() const
Definition: aa.cpp:73
const QString toString() const
Definition: aa.cpp:113
bool isAaEqual(Aa const &r) const
Definition: aa.cpp:272
void replaceAaModification(AaModificationP oldmod, AaModificationP newmod)
replaces all occurences of a modification by a new one
Definition: aa.cpp:159
void addAaModification(AaModificationP aaModification)
Definition: aa.cpp:150
virtual ~Aa()
Definition: aa.cpp:60
unsigned int getNumberOfModification(AaModificationP mod) const
Definition: aa.cpp:193
std::vector< AaModificationP > m_listMod
Definition: aa.h:89
bool isLesser(Aa const &r) const
Definition: aa.cpp:247
void removeInternalNterModification()
Definition: aa.cpp:229
Aa & operator=(const Aa &toCopy)
Definition: aa.cpp:65
void removeAaModification(AaModificationP aaModification)
Definition: aa.cpp:137
pappso_double getMass() const override
Definition: aa.cpp:79
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
AminoAcidChar
Definition: types.h:134
bool operator<(Aa const &l, Aa const &r)
Definition: aa.cpp:286
AtomIsotopeSurvey
Definition: types.h:77
double pappso_double
A type definition for doubles.
Definition: types.h:49
Isotope
Definition: types.h:92
bool operator==(Aa const &l, Aa const &r)
Definition: aa.cpp:280