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 << 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 }
163 
164 int
166 {
167  int number_of_carbon = AaBase::getNumberOfAtom(atom);
168  for(auto &&mod : m_listMod)
169  {
170  number_of_carbon += mod->getNumberOfAtom(atom);
171  }
172 
173  // qDebug() << "Aa::getMass() end " << mass;
174  return number_of_carbon;
175 }
176 
177 
178 int
180 {
181  int number = 0;
182  for(auto &&mod : m_listMod)
183  {
184  number += mod->getNumberOfIsotope(isotope);
185  }
186 
187  // qDebug() << "Aa::getMass() end " << mass;
188  return number;
189 }
190 
191 unsigned int
193 {
194  unsigned int number_of_mod = 0;
195  for(auto &&modb : m_listMod)
196  {
197  if(modb == mod)
198  number_of_mod += 1;
199  }
200 
201  // qDebug() << "Aa::getMass() end " << mass;
202  return number_of_mod;
203 }
204 
207 {
208  for(auto &&modb : m_listMod)
209  {
210  if(modb->getAccession().startsWith("internal:Nter_"))
211  return modb;
212  }
213  return nullptr;
214 }
215 
218 {
219  for(auto &&modb : m_listMod)
220  {
221  if(modb->getAccession().startsWith("internal:Cter_"))
222  return modb;
223  }
224  return nullptr;
225 }
226 
227 void
229 {
230  std::remove_if(
231  m_listMod.begin(), m_listMod.end(), [](AaModificationP const &mod) {
232  return mod->getAccession().startsWith("internal:Nter_");
233  });
234 }
235 
236 void
238 {
239  std::remove_if(
240  m_listMod.begin(), m_listMod.end(), [](AaModificationP const &mod) {
241  return mod->getAccession().startsWith("internal:Cter_");
242  });
243 }
244 
245 bool
246 Aa::isLesser(Aa const &r) const
247 {
248  qDebug() << m_listMod << "//" << r.m_listMod;
249  // qDebug() << "operator<(const Aa& l, const Aa& r)";
250  if(m_aaLetter == r.m_aaLetter)
251  {
252  std::size_t a = m_listMod.size();
253  std::size_t b = r.m_listMod.size();
254 
255  if(a == b)
256  {
257  return (m_listMod < r.m_listMod);
258  }
259  else
260  {
261  return (a < b);
262  }
263  }
264  else
265  {
266  return (m_aaLetter < r.m_aaLetter);
267  }
268 }
269 
270 bool
271 Aa::isAaEqual(Aa const &r) const
272 {
273 
274  return (std::tie(m_aaLetter, m_listMod) ==
275  std::tie(r.m_aaLetter, r.m_listMod));
276 }
277 
278 bool
279 operator==(Aa const &l, Aa const &r)
280 {
281  return l.isAaEqual(r);
282 }
283 
284 bool
285 operator<(Aa const &l, Aa const &r)
286 {
287  return l.isLesser(r);
288 }
289 } /* namespace pappso */
pappso::Aa::removeInternalNterModification
void removeInternalNterModification()
Definition: aa.cpp:228
pappso::Aa::replaceAaModification
void replaceAaModification(AaModificationP oldmod, AaModificationP newmod)
replaces all occurences of a modification by a new one
Definition: aa.cpp:159
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition: types.h:48
pappso::Aa::toAbsoluteString
const QString toAbsoluteString() const
Definition: aa.cpp:93
pappso::AaBase
Definition: aabase.h:43
pappso::operator<
bool operator<(Aa const &l, Aa const &r)
Definition: aa.cpp:285
pappso::AaModification::getAccession
const QString & getAccession() const
Definition: aamodification.cpp:90
pappso::Aa::removeInternalCterModification
void removeInternalCterModification()
Definition: aa.cpp:237
pappso::AaBase::getMass
virtual pappso_double getMass() const
Definition: aabase.cpp:385
pappso::Aa::toString
const QString toString() const
Definition: aa.cpp:113
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks
Definition: aa.cpp:39
pappso::Isotope
Isotope
Definition: types.h:91
pappso::operator==
bool operator==(Aa const &l, Aa const &r)
Definition: aa.cpp:279
pappso::Aa::addAaModification
void addAaModification(AaModificationP aaModification)
Definition: aa.cpp:150
pappso::Aa::Aa
Aa(char aa_letter)
Definition: aa.cpp:41
pappso::Aa::~Aa
virtual ~Aa()
Definition: aa.cpp:60
pappso::Aa::removeAaModification
void removeAaModification(AaModificationP aaModification)
Definition: aa.cpp:137
pappso::AminoAcidChar
AminoAcidChar
Definition: types.h:133
pappso::Aa::getNumberOfAtom
int getNumberOfAtom(AtomIsotopeSurvey atom) const override final
get the number of atom C, O, N, H in the molecule
Definition: aa.cpp:165
pappso::Aa::getModificationList
const std::vector< AaModificationP > & getModificationList() const
Definition: aa.cpp:73
pappso::Aa::getMass
pappso_double getMass() const override
Definition: aa.cpp:79
pappso::AaBase::getLetter
virtual const char & getLetter() const
Definition: aabase.cpp:432
pappso::Aa::isLesser
bool isLesser(Aa const &r) const
Definition: aa.cpp:246
pappso::Aa::getNumberOfIsotope
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:179
pappso::AaBase::getNumberOfAtom
virtual int getNumberOfAtom(AtomIsotopeSurvey atom) const override
get the number of atom C, O, N, H in the molecule
Definition: aabase.cpp:392
pappso::Aa::getInternalCterModification
AaModificationP getInternalCterModification() const
Definition: aa.cpp:217
pappso::Aa::isAaEqual
bool isAaEqual(Aa const &r) const
Definition: aa.cpp:271
pappso::Aa::getNumberOfModification
unsigned int getNumberOfModification(AaModificationP mod) const
Definition: aa.cpp:192
aa.h
pappso::Aa::operator=
Aa & operator=(const Aa &toCopy)
Definition: aa.cpp:65
pappso::AaBase::m_aaLetter
char m_aaLetter
Definition: aabase.h:65
pappso::Aa::getInternalNterModification
AaModificationP getInternalNterModification() const
Definition: aa.cpp:206
pappso::Aa
Definition: aa.h:45
pappso::Aa::m_listMod
std::vector< AaModificationP > m_listMod
Definition: aa.h:89
pappso::AaModification
Definition: aamodification.h:57
pappso::AtomIsotopeSurvey
AtomIsotopeSurvey
Definition: types.h:76