peptide.cpp
Go to the documentation of this file.
/**
* \file pappsomspp/peptide/peptide.cpp
* \date 7/3/2015
* \author Olivier Langella
* \brief peptide model
*/
/*******************************************************************************
* Copyright (c) 2015 Olivier Langella <Olivier.Langella@moulon.inra.fr>.
*
* This file is part of the PAPPSOms++ library.
*
* PAPPSOms++ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PAPPSOms++ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
*
* Contributors:
* Olivier Langella <Olivier.Langella@moulon.inra.fr> - initial API and
*implementation
******************************************************************************/
#include <QDebug>
#include <algorithm>
#include "peptide.h"
#include "../pappsoexception.h"
#include "../exception/exceptionoutofrange.h"
#include "../exception/exceptionnotpossible.h"
#include "peptidenaturalisotopelist.h"
namespace pappso
{
bool
peptideIonIsNter(PeptideIon ion_type)
{
if((std::int8_t)ion_type < (std::int8_t)8)
{
return true;
}
return false;
}
PeptideDirection
getPeptideIonDirection(PeptideIon ion_type)
{
if(peptideIonIsNter(ion_type))
{
return PeptideDirection::Nter;
}
return PeptideDirection::Cter;
}
Peptide::Peptide(const QString &pepstr)
{
QString::const_iterator it(pepstr.begin());
if(it != pepstr.end())
{
// first amino acid is the Nter one
// by default, it is obtained by hydrolytic cleavage in normal water
// and it is loaded with one Hydrogen
Aa nter_aa(it->toLatin1());
nter_aa.addAaModification(
AaModification::getInstance("internal:Nter_hydrolytic_cleavage_H"));
m_aaVec.push_back(nter_aa);
it++;
while(it != pepstr.end())
{
m_aaVec.push_back(Aa(it->toLatin1()));
it++;
}
// by default, Nter aa is obtained by hydrolytic cleavage in normal water
// and it is loaded with Hydrogen + Oxygen
m_aaVec.back().addAaModification(
AaModification::getInstance("internal:Cter_hydrolytic_cleavage_HO"));
getMass();
qDebug() << "blabla " << m_aaVec.back().toString();
}
}
Peptide::~Peptide()
{
}
Peptide::Peptide(const Peptide &peptide)
: m_aaVec(peptide.m_aaVec), m_proxyMass(peptide.m_proxyMass)
{
}
Peptide::Peptide(Peptide &&toCopy) // move constructor
: m_aaVec(std::move(toCopy.m_aaVec)), m_proxyMass(toCopy.m_proxyMass)
{
}
PeptideSp
Peptide::makePeptideSp() const
{
return std::make_shared<const Peptide>(*this);
}
NoConstPeptideSp
Peptide::makeNoConstPeptideSp() const
{
return std::make_shared<Peptide>(*this);
}
void
Peptide::addAaModification(AaModificationP aaModification,
unsigned int position)
{
if(position >= size())
{
throw ExceptionOutOfRange(
QObject::tr("position (%1) > size (%2)").arg(position).arg(size()));
}
m_proxyMass = -1;
qDebug() << "Peptide::addAaModification begin " << position;
std::vector<Aa>::iterator it = m_aaVec.begin() + position;
it->addAaModification(aaModification);
getMass();
qDebug() << "Peptide::addAaModification end";
}
const QString
Peptide::getSequence() const
{
QString seq = "";
std::vector<Aa>::const_iterator it(m_aaVec.begin());
while(it != m_aaVec.end())
{
seq += it->getLetter();
it++;
}
return seq;
}
const QString
Peptide::toAbsoluteString() const
{
QString seq = "";
std::vector<Aa>::const_iterator it(m_aaVec.begin());
while(it != m_aaVec.end())
{
seq += it->toAbsoluteString();
it++;
}
return seq;
}
const QString
Peptide::getLiAbsoluteString() const
{
QString seq = "";
std::vector<Aa>::const_iterator it(m_aaVec.begin());
while(it != m_aaVec.end())
{
seq += it->toAbsoluteString();
it++;
}
return seq.replace("L", "I");
}
const QString
Peptide::toString() const
{
QString seq = "";
std::vector<Aa>::const_iterator it(m_aaVec.begin());
while(it != m_aaVec.end())
{
seq += it->toString();
it++;
}
return seq;
}
pappso_double
Peptide::getMass()
{
qDebug() << "Aa::getMass() begin";
if(m_proxyMass < 0)
{
m_proxyMass = 0;
for(auto aa : m_aaVec)
{
m_proxyMass += aa.getMass();
}
}
qDebug() << "Aa::getMass() end " << m_proxyMass;
return m_proxyMass;
}
int
Peptide::getNumberOfAtom(AtomIsotopeSurvey atom) const
{
int number = 0;
std::vector<Aa>::const_iterator it(m_aaVec.begin());
while(it != m_aaVec.end())
{
number += it->getNumberOfAtom(atom);
it++;
}
// qDebug() << "Aa::getMass() end " << mass;
return number;
}
int
Peptide::getNumberOfIsotope(Isotope isotope) const
{
int number = 0;
std::vector<Aa>::const_iterator it(m_aaVec.begin());
while(it != m_aaVec.end())
{
number += it->getNumberOfIsotope(isotope);
it++;
}
// qDebug() << "Aa::getMass() end " << mass;
return number;
}
unsigned int
Peptide::getNumberOfModification(AaModificationP mod) const
{
unsigned int number = 0;
std::vector<Aa>::const_iterator it(m_aaVec.begin());
while(it != m_aaVec.end())
{
number += it->getNumberOfModification(mod);
it++;
}
// qDebug() << "Aa::getMass() end " << mass;
return number;
}
unsigned int
Peptide::countModificationOnAa(AaModificationP mod,
const std::vector<char> &aa_list) const
{
unsigned int number = 0;
std::vector<Aa>::const_iterator it(m_aaVec.begin());
while(it != m_aaVec.end())
{
if(std::find(aa_list.begin(), aa_list.end(), it->getLetter()) !=
aa_list.end())
{
number += it->getNumberOfModification(mod);
}
it++;
}
// qDebug() << "Aa::getMass() end " << mass;
return number;
}
void
Peptide::replaceAaModification(AaModificationP oldmod, AaModificationP newmod)
{
if(oldmod == newmod)
return;
std::vector<Aa>::iterator it(m_aaVec.begin());
while(it != m_aaVec.end())
{
it->replaceAaModification(oldmod, newmod);
it++;
}
m_proxyMass = -1;
getMass();
}
void
Peptide::removeAaModification(AaModificationP mod)
{
std::vector<Aa>::iterator it(m_aaVec.begin());
while(it != m_aaVec.end())
{
it->removeAaModification(mod);
qDebug() << it->toString() << " " << toAbsoluteString();
it++;
}
m_proxyMass = -1;
getMass();
// qDebug() << "Aa::getMass() end " << mass;
}
std::vector<unsigned int>
Peptide::getModificationPositionList(AaModificationP mod) const
{
std::vector<unsigned int> position_list;
unsigned int position = 0;
std::vector<Aa>::const_iterator it(m_aaVec.begin());
while(it != m_aaVec.end())
{
unsigned int number = 0;
number += it->getNumberOfModification(mod);
for(unsigned int j = 0; j < number; j++)
{
position_list.push_back(position);
}
it++;
position++;
}
// qDebug() << "Aa::getMass() end " << mass;
return position_list;
}
std::vector<unsigned int>
Peptide::getModificationPositionList(AaModificationP mod,
const std::vector<char> &aa_list) const
{
std::vector<unsigned int> position_list;
unsigned int position = 0;
std::vector<Aa>::const_iterator it(m_aaVec.begin());
while(it != m_aaVec.end())
{
if(std::find(aa_list.begin(), aa_list.end(), it->getLetter()) !=
aa_list.end())
{
unsigned int number = 0;
number += it->getNumberOfModification(mod);
for(unsigned int j = 0; j < number; j++)
{
position_list.push_back(position);
}
}
it++;
position++;
}
// qDebug() << "Aa::getMass() end " << mass;
return position_list;
}
std::vector<unsigned int>
Peptide::getAaPositionList(char aa) const
{
std::vector<unsigned int> position_list;
unsigned int number = 0;
std::vector<Aa>::const_iterator it(m_aaVec.begin());
while(it != m_aaVec.end())
{
if(it->getLetter() == aa)
position_list.push_back(number);
number++;
it++;
}
// qDebug() << "Aa::getMass() end " << mass;
return position_list;
}
std::vector<unsigned int>
Peptide::getAaPositionList(std::list<char> list_aa) const
{
std::vector<unsigned int> position_list;
unsigned int number = 0;
std::vector<Aa>::const_iterator it(m_aaVec.begin());
while(it != m_aaVec.end())
{
bool found =
(std::find(list_aa.begin(), list_aa.end(), it->getLetter()) !=
list_aa.end());
if(found)
{
position_list.push_back(number);
}
number++;
it++;
}
// qDebug() << "Aa::getMass() end " << mass;
return position_list;
}
AaModificationP
Peptide::getInternalNterModification() const
{
std::vector<Aa>::const_iterator it(m_aaVec.begin());
if(it != m_aaVec.end())
{
return it->getInternalNterModification();
}
return nullptr;
}
AaModificationP
Peptide::getInternalCterModification() const
{
std::vector<Aa>::const_iterator it(m_aaVec.end());
it--;
if(it != m_aaVec.end())
{
return it->getInternalCterModification();
}
return nullptr;
}
void
Peptide::removeInternalNterModification()
{
std::vector<Aa>::iterator it(m_aaVec.begin());
if(it != m_aaVec.end())
{
m_proxyMass -= it->getMass();
it->removeInternalNterModification();
m_proxyMass += it->getMass();
}
}
void
Peptide::removeInternalCterModification()
{
std::vector<Aa>::iterator it(m_aaVec.end());
it--;
if(it != m_aaVec.end())
{
m_proxyMass -= it->getMass();
it->removeInternalCterModification();
m_proxyMass += it->getMass();
}
}
void
Peptide::setInternalNterModification(AaModificationP mod)
{
if(mod->getAccession().startsWith("internal:Nter_"))
{
removeInternalNterModification();
std::vector<Aa>::iterator it(m_aaVec.begin());
if(it != m_aaVec.end())
{
it->addAaModification(mod);
}
else
{
throw ExceptionOutOfRange(QObject::tr("peptide is empty"));
}
}
else
{
throw ExceptionNotPossible(
QObject::tr("modification is not an internal Nter modification : %1")
.arg(mod->getAccession()));
}
}
void
Peptide::setInternalCterModification(AaModificationP mod)
{
if(mod->getAccession().startsWith("internal:Cter_"))
{
removeInternalCterModification();
std::vector<Aa>::iterator it(m_aaVec.end());
it--;
if(it != m_aaVec.end())
{
it->addAaModification(mod);
}
else
{
throw ExceptionOutOfRange(QObject::tr("peptide is empty"));
}
}
else
{
throw ExceptionNotPossible(
QObject::tr("modification is not an internal Cter modification : %1")
.arg(mod->getAccession()));
}
}
void
Peptide::rotate()
{
AaModificationP modNter = getInternalNterModification();
AaModificationP modCter = getInternalCterModification();
m_aaVec.begin()->removeInternalNterModification();
(m_aaVec.end() - 1)->removeInternalCterModification();
std::rotate(m_aaVec.begin(), m_aaVec.begin() + 1, m_aaVec.end());
m_aaVec.begin()->addAaModification(modNter);
(m_aaVec.end() - 1)->addAaModification(modCter);
}
void
Peptide::reverse()
{
AaModificationP modNter = getInternalNterModification();
AaModificationP modCter = getInternalCterModification();
m_aaVec.begin()->removeInternalNterModification();
(m_aaVec.end() - 1)->removeInternalCterModification();
std::reverse(m_aaVec.begin(), m_aaVec.end());
m_aaVec.begin()->addAaModification(modNter);
(m_aaVec.end() - 1)->addAaModification(modCter);
}
bool
Peptide::isPalindrome() const
{
std::size_t size = m_aaVec.size();
std::size_t k = (size - 1);
for(std::size_t i = 0; i < (size / 2); i++, k--)
{
if(m_aaVec[i].getLetter() != m_aaVec[k].getLetter())
{
return false;
}
}
return true;
}
Aa &
Peptide::getAa(unsigned int position)
{
if(position >= m_aaVec.size())
{
throw ExceptionOutOfRange(
QObject::tr("no AA at position %1").arg(position));
}
return m_aaVec.at(position);
}
const Aa &
Peptide::getConstAa(unsigned int position) const
{
if(position >= m_aaVec.size())
{
throw ExceptionOutOfRange(
QObject::tr("no AA at position %1").arg(position));
}
return m_aaVec.at(position);
}
void
Peptide::replaceLeucineIsoleucine()
{
std::vector<Aa>::iterator it(m_aaVec.begin());
std::vector<Aa>::iterator itend(m_aaVec.end());
for(; it != itend; it++)
{
it->replaceLeucineIsoleucine();
}
}
void
Peptide::removeNterAminoAcid()
{
std::vector<Aa>::iterator it(m_aaVec.begin());
if(it != m_aaVec.end())
{
AaModificationP nter_modification = getInternalNterModification();
m_aaVec.erase(it);
if(nter_modification != nullptr)
{
m_aaVec.begin()->addAaModification(nter_modification);
}
m_proxyMass = -1;
getMass();
}
else
{
throw ExceptionOutOfRange(QObject::tr("peptide is empty"));
}
}
void
Peptide::removeCterAminoAcid()
{
std::vector<Aa>::iterator it(m_aaVec.end());
it--;
if(it != m_aaVec.end())
{
AaModificationP cter_modification = getInternalCterModification();
m_aaVec.erase(it);
if(cter_modification != nullptr)
{
it = m_aaVec.end();
it--;
it->addAaModification(cter_modification);
}
m_proxyMass = -1;
getMass();
}
else
{
throw ExceptionOutOfRange(QObject::tr("peptide is empty"));
}
}
} // namespace pappso
pappso::AaModification
Definition: aamodification.h:57
pappso::AaModification::getAccession
const QString & getAccession() const
Definition: aamodification.cpp:91
pappso::AaModification::getInstance
static AaModificationP getInstance(const QString &accession)
Definition: aamodification.cpp:366
pappso::Aa
Definition: aa.h:45
pappso::Aa::addAaModification
void addAaModification(AaModificationP aaModification)
Definition: aa.cpp:150
pappso::ExceptionNotPossible
Definition: exceptionnotpossible.h:29
pappso::ExceptionOutOfRange
Definition: exceptionoutofrange.h:32
pappso::Peptide
Definition: peptide.h:93
pappso::Peptide::replaceLeucineIsoleucine
void replaceLeucineIsoleucine()
Definition: peptide.cpp:541
pappso::Peptide::makePeptideSp
PeptideSp makePeptideSp() const
Definition: peptide.cpp:109
pappso::Peptide::Peptide
Peptide(const QString &pepstr)
Definition: peptide.cpp:63
pappso::Peptide::getInternalNterModification
AaModificationP getInternalNterModification() const
Definition: peptide.cpp:384
pappso::Peptide::getNumberOfIsotope
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:221
pappso::Peptide::replaceAaModification
void replaceAaModification(AaModificationP oldmod, AaModificationP newmod)
replaces all occurences of a modification by a new one
Definition: peptide.cpp:269
pappso::Peptide::removeNterAminoAcid
void removeNterAminoAcid()
Definition: peptide.cpp:554
pappso::Peptide::getModificationPositionList
std::vector< unsigned int > getModificationPositionList(AaModificationP mod) const
get modification positions
Definition: peptide.cpp:297
pappso::Peptide::makeNoConstPeptideSp
NoConstPeptideSp makeNoConstPeptideSp() const
Definition: peptide.cpp:115
pappso::Peptide::isPalindrome
virtual bool isPalindrome() const override
tells if the peptide sequence is a palindrome
Definition: peptide.cpp:504
pappso::Peptide::getLiAbsoluteString
const QString getLiAbsoluteString() const
get all sequence string with modifications and converting Leucine to Isoleucine
Definition: peptide.cpp:164
pappso::Peptide::removeCterAminoAcid
void removeCterAminoAcid()
Definition: peptide.cpp:577
pappso::Peptide::setInternalCterModification
void setInternalCterModification(AaModificationP mod)
Definition: peptide.cpp:454
pappso::Peptide::toAbsoluteString
const QString toAbsoluteString() const
print all modifications
Definition: peptide.cpp:151
pappso::Peptide::m_proxyMass
pappso_double m_proxyMass
Definition: peptide.h:96
pappso::Peptide::removeInternalNterModification
void removeInternalNterModification()
Definition: peptide.cpp:406
pappso::Peptide::setInternalNterModification
void setInternalNterModification(AaModificationP mod)
Definition: peptide.cpp:431
pappso::Peptide::~Peptide
virtual ~Peptide()
Definition: peptide.cpp:92
pappso::Peptide::removeInternalCterModification
void removeInternalCterModification()
Definition: peptide.cpp:417
pappso::Peptide::getNumberOfModification
unsigned int getNumberOfModification(AaModificationP mod) const
count modification occurence
Definition: peptide.cpp:236
pappso::Peptide::toString
const QString toString() const
print modification except internal modifications
Definition: peptide.cpp:178
pappso::Peptide::getInternalCterModification
AaModificationP getInternalCterModification() const
Definition: peptide.cpp:395
pappso::Peptide::rotate
void rotate()
Definition: peptide.cpp:479
pappso::Peptide::removeAaModification
void removeAaModification(AaModificationP mod)
removes all occurences of a modification
Definition: peptide.cpp:283
pappso::Peptide::size
unsigned int size() const override
Definition: peptide.h:178
pappso::Peptide::getAa
Aa & getAa(unsigned int position)
Definition: peptide.cpp:519
pappso::Peptide::getNumberOfAtom
virtual int getNumberOfAtom(AtomIsotopeSurvey atom) const override
get the number of atom C, O, N, H in the molecule
Definition: peptide.cpp:207
pappso::Peptide::getAaPositionList
std::vector< unsigned int > getAaPositionList(char aa) const
get positions of one amino acid in peptide
Definition: peptide.cpp:344
pappso::Peptide::reverse
void reverse()
Definition: peptide.cpp:491
pappso::Peptide::getMass
pappso_double getMass()
Definition: peptide.cpp:191
pappso::Peptide::getSequence
const QString getSequence() const override
print amino acid sequence without modifications
Definition: peptide.cpp:139
pappso::Peptide::addAaModification
void addAaModification(AaModificationP aaModification, unsigned int position)
adds a modification to amino acid sequence
Definition: peptide.cpp:121
pappso::Peptide::m_aaVec
std::vector< Aa > m_aaVec
Definition: peptide.h:95
pappso::Peptide::countModificationOnAa
unsigned int countModificationOnAa(AaModificationP mod, const std::vector< char > &aa_list) const
count modification occurence
Definition: peptide.cpp:250
pappso::Peptide::getConstAa
const Aa & getConstAa(unsigned int position) const
Definition: peptide.cpp:529
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
pappso::PeptideIon
PeptideIon
PeptideIon enum defines all types of ions (Nter or Cter)
Definition: types.h:385
pappso::PeptideSp
std::shared_ptr< const Peptide > PeptideSp
Definition: aamodification.h:47
pappso::PeptideDirection
PeptideDirection
Definition: peptide.h:46
pappso::PeptideDirection::Cter
@ Cter
pappso::PeptideDirection::Nter
@ Nter
pappso::AtomIsotopeSurvey
AtomIsotopeSurvey
Definition: types.h:76
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition: types.h:48
pappso::Isotope
Isotope
Definition: types.h:91
pappso::getPeptideIonDirection
PeptideDirection getPeptideIonDirection(PeptideIon ion_type)
get the direction of a peptide ion
Definition: peptide.cpp:54
pappso::peptideIonIsNter
bool peptideIonIsNter(PeptideIon ion_type)
tells if an ion is Nter
Definition: peptide.cpp:44
pappso::NoConstPeptideSp
std::shared_ptr< Peptide > NoConstPeptideSp
Definition: peptide.h:90
peptide.h
peptide model
peptidenaturalisotopelist.h
peptide natural isotope model