Loading...
Searching...
No Matches
aa.cpp
Go to the documentation of this file.
/**
* \file pappsomspp/amino_acid/aaBase.cpp
* \date 7/3/2015
* \author Olivier Langella
* \brief amino acid 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 "aa.h"
#include <QDebug>
#include <vector>
#include <QStringList>
#include <algorithm>
namespace pappso
{
Aa::Aa(char aa_letter) : AaBase(aa_letter)
{
}
Aa::Aa(AminoAcidChar aa_char) : AaBase(aa_char)
{
}
Aa::Aa(const Aa &other) : AaBase(other), m_listMod(other.m_listMod)
{
}
Aa::Aa(Aa &&toCopy) // move constructor
: AaBase(toCopy), m_listMod(std::move(toCopy.m_listMod))
{
}
Aa::~Aa()
{
}
Aa &
Aa::operator=(const Aa &toCopy)
{
m_aaLetter = toCopy.m_aaLetter;
m_listMod = toCopy.m_listMod;
return *this;
}
const std::vector<AaModificationP> &
Aa::getModificationList() const
{
return m_listMod;
}
double
Aa::getTotalModificationMass() const
{
double mass = 0;
for(auto &&mod : m_listMod)
{
mass += mod->getMass();
}
return mass;
}
pappso_double
Aa::getMass() const
{
// qDebug() << "Aa::getMass() begin";
pappso_double mass = AaBase::getMass();
for(auto &&mod : m_listMod)
{
mass += mod->getMass();
}
// qDebug() << "Aa::getMass() end " << mass;
return mass;
}
const QString
Aa::toAbsoluteString() const
{
QString seq = "";
seq += this->getLetter();
auto it(m_listMod.begin());
if(it != m_listMod.end())
{
QStringList modification_str_list;
while(it != m_listMod.end())
{
modification_str_list << (*it)->getAccession();
it++;
}
if(modification_str_list.size() > 0)
seq += QString("(%1)").arg(modification_str_list.join(","));
}
return seq;
}
const QString
Aa::toString() const
{
QString seq = "";
seq += this->getLetter();
auto it(m_listMod.begin());
if(it != m_listMod.end())
{
QStringList modification_str_list;
while(it != m_listMod.end())
{
if(!(*it)->isInternal())
{
modification_str_list << (*it)->getAccession();
}
it++;
}
if(modification_str_list.size() > 0)
seq += QString("(%1)").arg(modification_str_list.join(","));
}
return seq;
}
const QString
Aa::toProForma() const
{
QString seq = "";
seq += this->getLetter();
std::vector<AaModificationP> copy_mod_list = m_listMod;
std::sort(copy_mod_list.begin(),
copy_mod_list.end(),
[](const AaModificationP &a, const AaModificationP &b) {
return a->getAccession() < b->getAccession();
});
auto it(copy_mod_list.begin());
if(it != copy_mod_list.end())
{
QStringList modification_str_list;
while(it != copy_mod_list.end())
{
if(!(*it)->isInternal())
{
modification_str_list << (*it)->toProForma();
}
it++;
}
if(modification_str_list.size() > 0)
seq += QString("[%1]").arg(modification_str_list.join("]["));
}
return seq;
}
void
Aa::removeAaModification(AaModificationP mod)
{
std::vector<AaModificationP>::iterator it =
std::find(m_listMod.begin(), m_listMod.end(), mod);
if(it != m_listMod.end())
{
m_listMod.erase(it);
}
qDebug() << m_listMod << Qt::endl;
}
void
Aa::addAaModification(AaModificationP aaModification)
{
qDebug() << "Aa::addAaModification begin";
qDebug() << aaModification->getAccession();
m_listMod.push_back(aaModification);
sort(m_listMod.begin(), m_listMod.end());
}
void
Aa::replaceAaModification(AaModificationP oldmod, AaModificationP newmod)
{
std::replace(m_listMod.begin(), m_listMod.end(), oldmod, newmod);
sort(m_listMod.begin(), m_listMod.end());
}
int
Aa::getNumberOfAtom(AtomIsotopeSurvey atom) const
{
int number_of_carbon = AaBase::getNumberOfAtom(atom);
for(auto &&mod : m_listMod)
{
number_of_carbon += mod->getNumberOfAtom(atom);
}
// qDebug() << "Aa::getMass() end " << mass;
return number_of_carbon;
}
int
Aa::getNumberOfIsotope(Isotope isotope) const
{
int number = 0;
for(auto &&mod : m_listMod)
{
number += mod->getNumberOfIsotope(isotope);
}
// qDebug() << "Aa::getMass() end " << mass;
return number;
}
unsigned int
Aa::getNumberOfModification(AaModificationP mod) const
{
unsigned int number_of_mod = 0;
for(auto &&modb : m_listMod)
{
if(modb == mod)
number_of_mod += 1;
}
// qDebug() << "Aa::getMass() end " << mass;
return number_of_mod;
}
AaModificationP
Aa::getInternalNterModification() const
{
for(auto &&modb : m_listMod)
{
if(modb->getAccession().startsWith("internal:Nter_"))
return modb;
}
return nullptr;
}
AaModificationP
Aa::getInternalCterModification() const
{
for(auto &&modb : m_listMod)
{
if(modb->getAccession().startsWith("internal:Cter_"))
return modb;
}
return nullptr;
}
void
Aa::removeInternalNterModification()
{
m_listMod.erase(std::remove_if(m_listMod.begin(),
m_listMod.end(),
[](AaModificationP const &mod) {
return mod->getAccession().startsWith(
"internal:Nter_");
}),
m_listMod.end());
sort(m_listMod.begin(), m_listMod.end());
}
void
Aa::removeInternalCterModification()
{
m_listMod.erase(std::remove_if(m_listMod.begin(),
m_listMod.end(),
[](AaModificationP const &mod) {
return mod->getAccession().startsWith(
"internal:Cter_");
}),
m_listMod.end());
sort(m_listMod.begin(), m_listMod.end());
}
void
Aa::removeAllButInternalModification()
{
m_listMod.erase(std::remove_if(m_listMod.begin(),
m_listMod.end(),
[](AaModificationP const &mod) {
return !mod->getAccession().startsWith(
"internal:");
}),
m_listMod.end());
}
bool
Aa::isLesser(Aa const &r) const
{
qDebug() << m_listMod << "//" << r.m_listMod;
// qDebug() << "operator<(const Aa& l, const Aa& r)";
if(m_aaLetter == r.m_aaLetter)
{
std::size_t a = m_listMod.size();
std::size_t b = r.m_listMod.size();
if(a == b)
{
return (m_listMod < r.m_listMod);
}
else
{
return (a < b);
}
}
else
{
return (m_aaLetter < r.m_aaLetter);
}
}
bool
Aa::isAaEqual(Aa const &r) const
{
return (std::tie(m_aaLetter, m_listMod) ==
std::tie(r.m_aaLetter, r.m_listMod));
}
bool
operator==(Aa const &l, Aa const &r)
{
return l.isAaEqual(r);
}
bool
operator<(Aa const &l, Aa const &r)
{
return l.isLesser(r);
}
} /* namespace pappso */
aa.h
pappso::AaBase
Definition aabase.h:44
pappso::AaBase::getMass
virtual pappso_double getMass() const
Definition aabase.cpp:386
pappso::AaBase::m_aaLetter
char m_aaLetter
Definition aabase.h:68
pappso::AaBase::getLetter
virtual const char & getLetter() const
Definition aabase.cpp:433
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:393
pappso::AaModification
Definition aamodification.h:57
pappso::AaModification::getAccession
const QString & getAccession() const
Definition aamodification.cpp:91
pappso::Aa
Definition aa.h:45
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:206
pappso::Aa::toProForma
const QString toProForma() const
get the amino acid in ProForma notation https://github.com/HUPO-PSI/ProForma/blob/master/README....
Definition aa.cpp:147
pappso::Aa::toAbsoluteString
const QString toAbsoluteString() const
Definition aa.cpp:104
pappso::Aa::getTotalModificationMass
double getTotalModificationMass() const
get the sum of mass modifications
Definition aa.cpp:79
pappso::Aa::removeInternalCterModification
void removeInternalCterModification()
Definition aa.cpp:282
pappso::Aa::getInternalCterModification
AaModificationP getInternalCterModification() const
Definition aa.cpp:258
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:220
pappso::Aa::Aa
Aa(char aa_letter)
Definition aa.cpp:41
pappso::Aa::getInternalNterModification
AaModificationP getInternalNterModification() const
Definition aa.cpp:247
pappso::Aa::getModificationList
const std::vector< AaModificationP > & getModificationList() const
Definition aa.cpp:73
pappso::Aa::toString
const QString toString() const
Definition aa.cpp:124
pappso::Aa::isAaEqual
bool isAaEqual(Aa const &r) const
Definition aa.cpp:333
pappso::Aa::replaceAaModification
void replaceAaModification(AaModificationP oldmod, AaModificationP newmod)
replaces all occurences of a modification by a new one
Definition aa.cpp:199
pappso::Aa::addAaModification
void addAaModification(AaModificationP aaModification)
Definition aa.cpp:190
pappso::Aa::~Aa
virtual ~Aa()
Definition aa.cpp:60
pappso::Aa::getNumberOfModification
unsigned int getNumberOfModification(AaModificationP mod) const
Definition aa.cpp:233
pappso::Aa::removeAllButInternalModification
void removeAllButInternalModification()
remove all non internat modifications
Definition aa.cpp:295
pappso::Aa::m_listMod
std::vector< AaModificationP > m_listMod
Definition aa.h:103
pappso::Aa::isLesser
bool isLesser(Aa const &r) const
Definition aa.cpp:308
pappso::Aa::removeInternalNterModification
void removeInternalNterModification()
Definition aa.cpp:269
pappso::Aa::operator=
Aa & operator=(const Aa &toCopy)
Definition aa.cpp:65
pappso::Aa::removeAaModification
void removeAaModification(AaModificationP aaModification)
Definition aa.cpp:177
pappso::Aa::getMass
pappso_double getMass() const override
Definition aa.cpp:90
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
pappso::AminoAcidChar
AminoAcidChar
Definition types.h:159
pappso::operator<
bool operator<(Aa const &l, Aa const &r)
Definition aa.cpp:347
pappso::PeptideIonNter::a
@ a
pappso::PeptideIonNter::b
@ b
pappso::AtomIsotopeSurvey
AtomIsotopeSurvey
Definition types.h:89
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition types.h:50
pappso::Isotope
Isotope
Definition types.h:104
pappso::operator==
bool operator==(Aa const &l, Aa const &r)
Definition aa.cpp:341