libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
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
38namespace pappso
39{
40
41Aa::Aa(char aa_letter) : AaBase(aa_letter)
42{
43}
44
45
46Aa::Aa(AminoAcidChar aa_char) : AaBase(aa_char)
47{
48}
49
50Aa::Aa(const Aa &other) : AaBase(other), m_listMod(other.m_listMod)
51{
52}
53
54
55Aa::Aa(Aa &&toCopy) // move constructor
56 : AaBase(toCopy), m_listMod(std::move(toCopy.m_listMod))
57{
58}
59
61{
62}
63
64Aa &
65Aa::operator=(const Aa &toCopy)
66{
67 m_aaLetter = toCopy.m_aaLetter;
68 m_listMod = toCopy.m_listMod;
69 return *this;
70}
71
72const std::vector<AaModificationP> &
74{
75 return m_listMod;
76}
77
78double
80{
81 double mass = 0;
82 for(auto &&mod : m_listMod)
83 {
84 mass += mod->getMass();
85 }
86 return mass;
87}
88
91{
92 // qDebug() << "Aa::getMass() begin";
94 for(auto &&mod : m_listMod)
95 {
96 mass += mod->getMass();
97 }
98
99 // qDebug() << "Aa::getMass() end " << mass;
100 return mass;
101}
102
103const QString
105{
106 QString seq = "";
107 seq += this->getLetter();
108 auto it(m_listMod.begin());
109 if(it != m_listMod.end())
110 {
111 QStringList modification_str_list;
112 while(it != m_listMod.end())
113 {
114 modification_str_list << (*it)->getAccession();
115 it++;
116 }
117 if(modification_str_list.size() > 0)
118 seq += QString("(%1)").arg(modification_str_list.join(","));
119 }
120 return seq;
121}
122
123const QString
125{
126 QString seq = "";
127 seq += this->getLetter();
128 auto it(m_listMod.begin());
129 if(it != m_listMod.end())
130 {
131 QStringList modification_str_list;
132 while(it != m_listMod.end())
133 {
134 if(!(*it)->isInternal())
135 {
136 modification_str_list << (*it)->getAccession();
137 }
138 it++;
139 }
140 if(modification_str_list.size() > 0)
141 seq += QString("(%1)").arg(modification_str_list.join(","));
142 }
143 return seq;
144}
145
146const QString
148{
149 QString seq = "";
150 seq += this->getLetter();
151
152 std::vector<AaModificationP> copy_mod_list = m_listMod;
153 std::sort(copy_mod_list.begin(),
154 copy_mod_list.end(),
155 [](const AaModificationP &a, const AaModificationP &b) {
156 return a->getAccession() < b->getAccession();
157 });
158 auto it(copy_mod_list.begin());
159 if(it != copy_mod_list.end())
160 {
161 QStringList modification_str_list;
162 while(it != copy_mod_list.end())
163 {
164 if(!(*it)->isInternal())
165 {
166 modification_str_list << (*it)->toProForma();
167 }
168 it++;
169 }
170 if(modification_str_list.size() > 0)
171 seq += QString("[%1]").arg(modification_str_list.join("]["));
172 }
173 return seq;
174}
175
176void
178{
179 std::vector<AaModificationP>::iterator it =
180 std::find(m_listMod.begin(), m_listMod.end(), mod);
181 if(it != m_listMod.end())
182 {
183 m_listMod.erase(it);
184 }
185
186 qDebug() << m_listMod << Qt::endl;
187}
188
189void
191{
192 qDebug() << "Aa::addAaModification begin";
193 qDebug() << aaModification->getAccession();
194 m_listMod.push_back(aaModification);
195 sort(m_listMod.begin(), m_listMod.end());
196}
197
198void
200{
201 std::replace(m_listMod.begin(), m_listMod.end(), oldmod, newmod);
202 sort(m_listMod.begin(), m_listMod.end());
203}
204
205int
207{
208 int number_of_carbon = AaBase::getNumberOfAtom(atom);
209 for(auto &&mod : m_listMod)
210 {
211 number_of_carbon += mod->getNumberOfAtom(atom);
212 }
213
214 // qDebug() << "Aa::getMass() end " << mass;
215 return number_of_carbon;
216}
217
218
219int
221{
222 int number = 0;
223 for(auto &&mod : m_listMod)
224 {
225 number += mod->getNumberOfIsotope(isotope);
226 }
227
228 // qDebug() << "Aa::getMass() end " << mass;
229 return number;
230}
231
232unsigned int
234{
235 unsigned int number_of_mod = 0;
236 for(auto &&modb : m_listMod)
237 {
238 if(modb == mod)
239 number_of_mod += 1;
240 }
241
242 // qDebug() << "Aa::getMass() end " << mass;
243 return number_of_mod;
244}
245
248{
249 for(auto &&modb : m_listMod)
250 {
251 if(modb->getAccession().startsWith("internal:Nter_"))
252 return modb;
253 }
254 return nullptr;
255}
256
259{
260 for(auto &&modb : m_listMod)
261 {
262 if(modb->getAccession().startsWith("internal:Cter_"))
263 return modb;
264 }
265 return nullptr;
266}
267
268void
270{
271 m_listMod.erase(std::remove_if(m_listMod.begin(),
272 m_listMod.end(),
273 [](AaModificationP const &mod) {
274 return mod->getAccession().startsWith(
275 "internal:Nter_");
276 }),
277 m_listMod.end());
278 sort(m_listMod.begin(), m_listMod.end());
279}
280
281void
283{
284 m_listMod.erase(std::remove_if(m_listMod.begin(),
285 m_listMod.end(),
286 [](AaModificationP const &mod) {
287 return mod->getAccession().startsWith(
288 "internal:Cter_");
289 }),
290 m_listMod.end());
291 sort(m_listMod.begin(), m_listMod.end());
292}
293
294void
296{
297
298 m_listMod.erase(std::remove_if(m_listMod.begin(),
299 m_listMod.end(),
300 [](AaModificationP const &mod) {
301 return !mod->getAccession().startsWith(
302 "internal:");
303 }),
304 m_listMod.end());
305}
306
307bool
308Aa::isLesser(Aa const &r) const
309{
310 qDebug() << m_listMod << "//" << r.m_listMod;
311 // qDebug() << "operator<(const Aa& l, const Aa& r)";
312 if(m_aaLetter == r.m_aaLetter)
313 {
314 std::size_t a = m_listMod.size();
315 std::size_t b = r.m_listMod.size();
316
317 if(a == b)
318 {
319 return (m_listMod < r.m_listMod);
320 }
321 else
322 {
323 return (a < b);
324 }
325 }
326 else
327 {
328 return (m_aaLetter < r.m_aaLetter);
329 }
330}
331
332bool
333Aa::isAaEqual(Aa const &r) const
334{
335
336 return (std::tie(m_aaLetter, m_listMod) ==
337 std::tie(r.m_aaLetter, r.m_listMod));
338}
339
340bool
341operator==(Aa const &l, Aa const &r)
342{
343 return l.isAaEqual(r);
344}
345
346bool
347operator<(Aa const &l, Aa const &r)
348{
349 return l.isLesser(r);
350}
351} /* namespace pappso */
virtual pappso_double getMass() const
Definition aabase.cpp:386
char m_aaLetter
Definition aabase.h:68
virtual const char & getLetter() const
Definition aabase.cpp:433
virtual int getNumberOfAtom(AtomIsotopeSurvey atom) const override
get the number of atom C, O, N, H in the molecule
Definition aabase.cpp:393
const QString & getAccession() const
int getNumberOfAtom(AtomIsotopeSurvey atom) const override final
get the number of atom C, O, N, H in the molecule
Definition aa.cpp:206
const QString toProForma() const
get the amino acid in ProForma notation https://github.com/HUPO-PSI/ProForma/blob/master/README....
Definition aa.cpp:147
const QString toAbsoluteString() const
Definition aa.cpp:104
double getTotalModificationMass() const
get the sum of mass modifications
Definition aa.cpp:79
void removeInternalCterModification()
Definition aa.cpp:282
AaModificationP getInternalCterModification() const
Definition aa.cpp:258
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:220
Aa(char aa_letter)
Definition aa.cpp:41
AaModificationP getInternalNterModification() const
Definition aa.cpp:247
const std::vector< AaModificationP > & getModificationList() const
Definition aa.cpp:73
const QString toString() const
Definition aa.cpp:124
bool isAaEqual(Aa const &r) const
Definition aa.cpp:333
void replaceAaModification(AaModificationP oldmod, AaModificationP newmod)
replaces all occurences of a modification by a new one
Definition aa.cpp:199
void addAaModification(AaModificationP aaModification)
Definition aa.cpp:190
virtual ~Aa()
Definition aa.cpp:60
unsigned int getNumberOfModification(AaModificationP mod) const
Definition aa.cpp:233
void removeAllButInternalModification()
remove all non internat modifications
Definition aa.cpp:295
std::vector< AaModificationP > m_listMod
Definition aa.h:103
bool isLesser(Aa const &r) const
Definition aa.cpp:308
void removeInternalNterModification()
Definition aa.cpp:269
Aa & operator=(const Aa &toCopy)
Definition aa.cpp:65
void removeAaModification(AaModificationP aaModification)
Definition aa.cpp:177
pappso_double getMass() const override
Definition aa.cpp:90
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
AminoAcidChar
Definition types.h:161
bool operator<(Aa const &l, Aa const &r)
Definition aa.cpp:347
AtomIsotopeSurvey
Definition types.h:89
double pappso_double
A type definition for doubles.
Definition types.h:50
Isotope
Definition types.h:104
bool operator==(Aa const &l, Aa const &r)
Definition aa.cpp:341