libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
peptide.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/peptide/peptide.cpp
3 * \date 7/3/2015
4 * \author Olivier Langella
5 * \brief peptide 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 <QDebug>
32#include <algorithm>
33#include "peptide.h"
34#include "../pappsoexception.h"
35#include "../exception/exceptionoutofrange.h"
36#include "../exception/exceptionnotpossible.h"
38
39namespace pappso
40{
41
42bool
44{
45 if(peptideIonIsNter(ion_type))
46 std::swap(ion_type_ref, ion_type);
47 if(peptideIonIsNter(ion_type))
48 return false;
49 if((ion_type_ref == PeptideIon::b) && (ion_type == PeptideIon::y))
50 return true;
51 if((ion_type_ref == PeptideIon::ao) && (ion_type == PeptideIon::yo))
52 return true;
53 if((ion_type_ref == PeptideIon::bstar) && (ion_type == PeptideIon::ystar))
54 return true;
55
56 return false;
57}
58
59bool
61{
62 if((std::int8_t)ion_type < (std::int8_t)8)
63 {
64 return true;
65 }
66 return false;
67}
68
71{
72 if(peptideIonIsNter(ion_type))
73 {
75 }
77}
78
79Peptide::Peptide(const QString &pepstr)
80{
81
82 QString::const_iterator it(pepstr.begin());
83 if(it != pepstr.end())
84 {
85 // first amino acid is the Nter one
86 // by default, it is obtained by hydrolytic cleavage in normal water
87 // and it is loaded with one Hydrogen
88 Aa nter_aa(it->toLatin1());
89 nter_aa.addAaModification(
90 AaModification::getInstance("internal:Nter_hydrolytic_cleavage_H"));
91 m_aaVec.push_back(nter_aa);
92 it++;
93
94 while(it != pepstr.end())
95 {
96 qDebug() << it->toLatin1();
97 m_aaVec.push_back(Aa(it->toLatin1()));
98 it++;
99 }
100 // by default, Nter aa is obtained by hydrolytic cleavage in normal water
101 // and it is loaded with Hydrogen + Oxygen
102 m_aaVec.back().addAaModification(
103 AaModification::getInstance("internal:Cter_hydrolytic_cleavage_HO"));
104 getMass();
105 qDebug() << "blabla " << m_aaVec.back().toString();
106 }
107}
108
112
114 : m_aaVec(peptide.m_aaVec), m_proxyMass(peptide.m_proxyMass)
115{
116}
117
118
119Peptide::Peptide(Peptide &&toCopy) // move constructor
120 : m_aaVec(std::move(toCopy.m_aaVec)), m_proxyMass(toCopy.m_proxyMass)
121{
122}
123
124
127{
128 return std::make_shared<const Peptide>(*this);
129}
130
133{
134 return std::make_shared<Peptide>(*this);
135}
136
137
138std::vector<Aa>::iterator
140{
141 return m_aaVec.begin();
142}
143
144std::vector<Aa>::iterator
146{
147 return m_aaVec.end();
148}
149
150std::vector<Aa>::const_iterator
152{
153 return m_aaVec.begin();
154}
155
156std::vector<Aa>::const_iterator
158{
159 return m_aaVec.end();
160}
161
162std::vector<Aa>::const_reverse_iterator
164{
165 return m_aaVec.rbegin();
166}
167
168std::vector<Aa>::const_reverse_iterator
170{
171 return m_aaVec.rend();
172}
173
174
177{
178 return m_proxyMass;
179}
180
181
182unsigned int
184{
185 return m_aaVec.size();
186}
187void
189 unsigned int position)
190{
191 if(position >= size())
192 {
194 QObject::tr("position (%1) > size (%2)").arg(position).arg(size()));
195 }
196 m_proxyMass = -1;
197 qDebug() << "Peptide::addAaModification begin " << position;
198 std::vector<Aa>::iterator it = m_aaVec.begin() + position;
199 it->addAaModification(aaModification);
200 getMass();
201 qDebug() << "Peptide::addAaModification end";
202}
203
204void
206 AminoAcidChar amino_acid)
207{
208
209 for(auto &aa : *this)
210 {
211 if(aa.getAminoAcidChar() == amino_acid)
212 {
213 aa.addAaModification(aaModification);
214 }
215 }
216
217
218 m_proxyMass = -1;
219 getMass();
220}
221
222const QString
224{
225 QString seq = "";
226 std::vector<Aa>::const_iterator it(m_aaVec.begin());
227 while(it != m_aaVec.end())
228 {
229 seq += it->getLetter();
230 it++;
231 }
232 return seq;
233}
234const QString
236{
237 QString seq = "";
238 std::vector<Aa>::const_iterator it(m_aaVec.begin());
239 while(it != m_aaVec.end())
240 {
241 seq += it->toAbsoluteString();
242 it++;
243 }
244 return seq;
245}
246
247const QString
249{
250 QString seq = "";
251 std::vector<Aa>::const_iterator it(m_aaVec.begin());
252 while(it != m_aaVec.end())
253 {
254 seq += it->toAbsoluteString();
255 it++;
256 }
257 return seq.replace("L", "I");
258}
259
260
261const QString
263{
264 QString seq = "";
265 std::vector<Aa>::const_iterator it(m_aaVec.begin());
266 while(it != m_aaVec.end())
267 {
268 seq += it->toString();
269 it++;
270 }
271 return seq;
272}
273
276{
277 qDebug() << "Aa::getMass() begin";
278 if(m_proxyMass < 0)
279 {
280 m_proxyMass = 0;
281 for(auto aa : m_aaVec)
282 {
283 m_proxyMass += aa.getMass();
284 }
285 }
286 qDebug() << "Aa::getMass() end " << m_proxyMass;
287 return m_proxyMass;
288}
289
290int
292{
293 int number = 0;
294 std::vector<Aa>::const_iterator it(m_aaVec.begin());
295 while(it != m_aaVec.end())
296 {
297 number += it->getNumberOfAtom(atom);
298 it++;
299 }
300 // qDebug() << "Aa::getMass() end " << mass;
301 return number;
302}
303
304int
306{
307 int number = 0;
308 std::vector<Aa>::const_iterator it(m_aaVec.begin());
309 while(it != m_aaVec.end())
310 {
311 number += it->getNumberOfIsotope(isotope);
312 it++;
313 }
314 // qDebug() << "Aa::getMass() end " << mass;
315 return number;
316}
317
318
319unsigned int
321{
322 unsigned int number = 0;
323 std::vector<Aa>::const_iterator it(m_aaVec.begin());
324 while(it != m_aaVec.end())
325 {
326 number += it->getNumberOfModification(mod);
327 it++;
328 }
329 // qDebug() << "Aa::getMass() end " << mass;
330 return number;
331}
332
333unsigned int
335 const std::vector<char> &aa_list) const
336{
337 unsigned int number = 0;
338 std::vector<Aa>::const_iterator it(m_aaVec.begin());
339 while(it != m_aaVec.end())
340 {
341 if(std::find(aa_list.begin(), aa_list.end(), it->getLetter()) !=
342 aa_list.end())
343 {
344 number += it->getNumberOfModification(mod);
345 }
346 it++;
347 }
348 // qDebug() << "Aa::getMass() end " << mass;
349 return number;
350}
351
352void
354{
355 if(oldmod == newmod)
356 return;
357 std::vector<Aa>::iterator it(m_aaVec.begin());
358 while(it != m_aaVec.end())
359 {
360 it->replaceAaModification(oldmod, newmod);
361 it++;
362 }
363 m_proxyMass = -1;
364 getMass();
365}
366void
368{
369 std::vector<Aa>::iterator it(m_aaVec.begin());
370 while(it != m_aaVec.end())
371 {
372 it->removeAaModification(mod);
373 qDebug() << it->toString() << " " << toAbsoluteString();
374 it++;
375 }
376 m_proxyMass = -1;
377 getMass();
378 // qDebug() << "Aa::getMass() end " << mass;
379}
380std::vector<unsigned int>
382{
383 std::vector<unsigned int> position_list;
384 unsigned int position = 0;
385 std::vector<Aa>::const_iterator it(m_aaVec.begin());
386 while(it != m_aaVec.end())
387 {
388 unsigned int number = 0;
389 number += it->getNumberOfModification(mod);
390 for(unsigned int j = 0; j < number; j++)
391 {
392 position_list.push_back(position);
393 }
394 it++;
395 position++;
396 }
397 // qDebug() << "Aa::getMass() end " << mass;
398 return position_list;
399}
400
401std::vector<unsigned int>
403 const std::vector<char> &aa_list) const
404{
405 std::vector<unsigned int> position_list;
406 unsigned int position = 0;
407 std::vector<Aa>::const_iterator it(m_aaVec.begin());
408 while(it != m_aaVec.end())
409 {
410 if(std::find(aa_list.begin(), aa_list.end(), it->getLetter()) !=
411 aa_list.end())
412 {
413 unsigned int number = 0;
414 number += it->getNumberOfModification(mod);
415 for(unsigned int j = 0; j < number; j++)
416 {
417 position_list.push_back(position);
418 }
419 }
420 it++;
421 position++;
422 }
423 // qDebug() << "Aa::getMass() end " << mass;
424 return position_list;
425}
426
427std::vector<unsigned int>
429{
430 std::vector<unsigned int> position_list;
431 unsigned int number = 0;
432 std::vector<Aa>::const_iterator it(m_aaVec.begin());
433 while(it != m_aaVec.end())
434 {
435 if(it->getLetter() == aa)
436 position_list.push_back(number);
437 number++;
438 it++;
439 }
440 // qDebug() << "Aa::getMass() end " << mass;
441 return position_list;
442}
443
444std::vector<unsigned int>
445Peptide::getAaPositionList(std::list<char> list_aa) const
446{
447 std::vector<unsigned int> position_list;
448 unsigned int number = 0;
449 std::vector<Aa>::const_iterator it(m_aaVec.begin());
450 while(it != m_aaVec.end())
451 {
452
453 bool found =
454 (std::find(list_aa.begin(), list_aa.end(), it->getLetter()) !=
455 list_aa.end());
456 if(found)
457 {
458 position_list.push_back(number);
459 }
460 number++;
461 it++;
462 }
463 // qDebug() << "Aa::getMass() end " << mass;
464 return position_list;
465}
466
469{
470 std::vector<Aa>::const_iterator it(m_aaVec.begin());
471 if(it != m_aaVec.end())
472 {
473 return it->getInternalNterModification();
474 }
475
476 return nullptr;
477}
480{
481 std::vector<Aa>::const_iterator it(m_aaVec.end());
482 it--;
483 if(it != m_aaVec.end())
484 {
485 return it->getInternalCterModification();
486 }
487 return nullptr;
488}
489void
491{
492 std::vector<Aa>::iterator it(m_aaVec.begin());
493 if(it != m_aaVec.end())
494 {
495 m_proxyMass -= it->getMass();
496 it->removeInternalNterModification();
497 m_proxyMass += it->getMass();
498 }
499}
500void
502{
503 std::vector<Aa>::iterator it(m_aaVec.end());
504 it--;
505 if(it != m_aaVec.end())
506 {
507 m_proxyMass -= it->getMass();
508 it->removeInternalCterModification();
509 m_proxyMass += it->getMass();
510 }
511}
512
513
514void
516{
517 if(mod->getAccession().startsWith("internal:Nter_"))
518 {
520 std::vector<Aa>::iterator it(m_aaVec.begin());
521 if(it != m_aaVec.end())
522 {
523 it->addAaModification(mod);
524 }
525 else
526 {
527 throw ExceptionOutOfRange(QObject::tr("peptide is empty"));
528 }
529 }
530 else
531 {
533 QObject::tr("modification is not an internal Nter modification : %1")
534 .arg(mod->getAccession()));
535 }
536}
537void
539{
540 if(mod->getAccession().startsWith("internal:Cter_"))
541 {
543 std::vector<Aa>::iterator it(m_aaVec.end());
544 it--;
545 if(it != m_aaVec.end())
546 {
547 it->addAaModification(mod);
548 }
549 else
550 {
551 throw ExceptionOutOfRange(QObject::tr("peptide is empty"));
552 }
553 }
554 else
555 {
557 QObject::tr("modification is not an internal Cter modification : %1")
558 .arg(mod->getAccession()));
559 }
560}
561
562void
564{
567 m_aaVec.begin()->removeInternalNterModification();
569 std::rotate(m_aaVec.begin(), m_aaVec.begin() + 1, m_aaVec.end());
570 m_aaVec.begin()->addAaModification(modNter);
571 (m_aaVec.end() - 1)->addAaModification(modCter);
572}
573
574void
576{
579 m_aaVec.begin()->removeInternalNterModification();
581 std::reverse(m_aaVec.begin(), m_aaVec.end());
582 m_aaVec.begin()->addAaModification(modNter);
583 (m_aaVec.end() - 1)->addAaModification(modCter);
584}
585
586
587bool
589{
590 std::size_t size = m_aaVec.size();
591 std::size_t k = (size - 1);
592 for(std::size_t i = 0; i < (size / 2); i++, k--)
593 {
594 if(m_aaVec[i].getLetter() != m_aaVec[k].getLetter())
595 {
596 return false;
597 }
598 }
599 return true;
600}
601
602Aa &
603Peptide::getAa(unsigned int position)
604{
605 if(position >= m_aaVec.size())
606 {
608 QObject::tr("no AA at position %1").arg(position));
609 }
610 return m_aaVec.at(position);
611}
612const Aa &
613Peptide::getConstAa(unsigned int position) const
614{
615 if(position >= m_aaVec.size())
616 {
618 QObject::tr("no AA at position %1").arg(position));
619 }
620 return m_aaVec.at(position);
621}
622
623
624void
626{
627
628 std::vector<Aa>::iterator it(m_aaVec.begin());
629 std::vector<Aa>::iterator itend(m_aaVec.end());
630 for(; it != itend; it++)
631 {
632 it->replaceLeucineIsoleucine();
633 }
634}
635
636
637void
639{
640 std::vector<Aa>::iterator it(m_aaVec.begin());
641 if(it != m_aaVec.end())
642 {
643 AaModificationP nter_modification = getInternalNterModification();
644 m_aaVec.erase(it);
645 if(nter_modification != nullptr)
646 {
647 m_aaVec.begin()->addAaModification(nter_modification);
648 }
649
650 m_proxyMass = -1;
651 getMass();
652 }
653 else
654 {
655 throw ExceptionOutOfRange(QObject::tr("peptide is empty"));
656 }
657}
658
659
660void
662{
663 std::vector<Aa>::iterator it(m_aaVec.end());
664 it--;
665 if(it != m_aaVec.end())
666 {
667 AaModificationP cter_modification = getInternalCterModification();
668 m_aaVec.erase(it);
669 if(cter_modification != nullptr)
670 {
671 it = m_aaVec.end();
672 it--;
673 it->addAaModification(cter_modification);
674 }
675 m_proxyMass = -1;
676 getMass();
677 }
678 else
679 {
680 throw ExceptionOutOfRange(QObject::tr("peptide is empty"));
681 }
682}
683
684QString
686{
687
688 QString seq = "";
689 std::vector<Aa>::const_iterator it(m_aaVec.begin());
690 while(it != m_aaVec.end())
691 {
692 seq += it->toProForma();
693 it++;
694 }
695 return seq;
696}
697} // namespace pappso
const QString & getAccession() const
static AaModificationP getInstance(const QString &accession)
void addAaModification(AaModificationP aaModification)
Definition aa.cpp:190
void replaceLeucineIsoleucine()
Definition peptide.cpp:625
PeptideSp makePeptideSp() const
Definition peptide.cpp:126
Peptide(const QString &pepstr)
Definition peptide.cpp:79
AaModificationP getInternalNterModification() const
Definition peptide.cpp:468
virtual int getNumberOfIsotope(Isotope isotope) const override
get the number of isotopes C13, H2, O17, O18, N15, S33, S34, S36 in the molecule
Definition peptide.cpp:305
void replaceAaModification(AaModificationP oldmod, AaModificationP newmod)
replaces all occurences of a modification by a new one
Definition peptide.cpp:353
void removeNterAminoAcid()
Definition peptide.cpp:638
std::vector< Aa >::const_reverse_iterator rend() const
Definition peptide.cpp:169
std::vector< unsigned int > getModificationPositionList(AaModificationP mod) const
get modification positions
Definition peptide.cpp:381
NoConstPeptideSp makeNoConstPeptideSp() const
Definition peptide.cpp:132
virtual bool isPalindrome() const override
tells if the peptide sequence is a palindrome
Definition peptide.cpp:588
std::vector< Aa >::const_reverse_iterator rbegin() const
Definition peptide.cpp:163
const QString getLiAbsoluteString() const
get all sequence string with modifications and converting Leucine to Isoleucine
Definition peptide.cpp:248
void removeCterAminoAcid()
Definition peptide.cpp:661
void setInternalCterModification(AaModificationP mod)
Definition peptide.cpp:538
const QString toAbsoluteString() const
print all modifications
Definition peptide.cpp:235
pappso_double m_proxyMass
Definition peptide.h:245
void removeInternalNterModification()
Definition peptide.cpp:490
void setInternalNterModification(AaModificationP mod)
Definition peptide.cpp:515
virtual ~Peptide()
Definition peptide.cpp:109
void removeInternalCterModification()
Definition peptide.cpp:501
unsigned int getNumberOfModification(AaModificationP mod) const
count modification occurence
Definition peptide.cpp:320
void addAaModificationOnAllAminoAcid(AaModificationP aaModification, AminoAcidChar amino_acid)
adds a modification to all amino acid of the sequence
Definition peptide.cpp:205
const QString toString() const
print modification except internal modifications
Definition peptide.cpp:262
AaModificationP getInternalCterModification() const
Definition peptide.cpp:479
QString toProForma() const
get the peptide model in ProForma notation https://github.com/HUPO-PSI/ProForma/blob/master/README....
Definition peptide.cpp:685
void removeAaModification(AaModificationP mod)
removes all occurences of a modification
Definition peptide.cpp:367
unsigned int size() const override
Definition peptide.cpp:183
Aa & getAa(unsigned int position)
Definition peptide.cpp:603
virtual int getNumberOfAtom(AtomIsotopeSurvey atom) const override
get the number of atom C, O, N, H in the molecule
Definition peptide.cpp:291
std::vector< unsigned int > getAaPositionList(char aa) const
get positions of one amino acid in peptide
Definition peptide.cpp:428
pappso_double getMass()
Definition peptide.cpp:275
std::vector< Aa >::iterator begin()
Definition peptide.cpp:139
const QString getSequence() const override
print amino acid sequence without modifications
Definition peptide.cpp:223
void addAaModification(AaModificationP aaModification, unsigned int position)
adds a modification to amino acid sequence
Definition peptide.cpp:188
std::vector< Aa >::iterator end()
Definition peptide.cpp:145
std::vector< Aa > m_aaVec
Definition peptide.h:244
unsigned int countModificationOnAa(AaModificationP mod, const std::vector< char > &aa_list) const
count modification occurence
Definition peptide.cpp:334
const Aa & getConstAa(unsigned int position) const
Definition peptide.cpp:613
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
PeptideIon
PeptideIon enum defines all types of ions (Nter or Cter)
Definition types.h:432
@ y
Cter amino ions.
@ ystar
Cter amino ions + NH3 loss.
@ yo
Cter amino ions + H2O loss.
@ bstar
Nter acylium ions + NH3 loss.
@ b
Nter acylium ions.
@ ao
Nter aldimine ions + H2O loss.
AminoAcidChar
Definition types.h:166
PeptideDirection getPeptideIonDirection(PeptideIon ion_type)
get the direction of a peptide ion
Definition peptide.cpp:70
std::shared_ptr< const Peptide > PeptideSp
PeptideDirection
Definition peptide.h:46
AtomIsotopeSurvey
Definition types.h:89
double pappso_double
A type definition for doubles.
Definition types.h:50
Isotope
Definition types.h:104
bool peptideIonTypeIsComplement(PeptideIon ion_type_ref, PeptideIon ion_type)
tells if an ion type is the complement ion of the other
Definition peptide.cpp:43
bool peptideIonIsNter(PeptideIon ion_type)
tells if an ion is Nter
Definition peptide.cpp:60
std::shared_ptr< Peptide > NoConstPeptideSp
Definition peptide.h:97
peptide model
peptide natural isotope model