Commit ee455b7d authored by Renne Thomas's avatar Renne Thomas
Browse files

Add removeAaModification test plus correct bug pappso/pappsomspp#1

parent 0130685a
......@@ -53,7 +53,7 @@ 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))
: AaBase(toCopy), m_listMod(std::move(toCopy.m_listMod))
{
}
......@@ -64,202 +64,205 @@ Aa::~Aa()
Aa &
Aa::operator=(const Aa &toCopy)
{
m_aaLetter = toCopy.m_aaLetter;
m_listMod = toCopy.m_listMod;
return *this;
m_aaLetter = toCopy.m_aaLetter;
m_listMod = toCopy.m_listMod;
return *this;
}
const std::vector<AaModificationP> &
Aa::getModificationList() const
{
return m_listMod;
return m_listMod;
}
pappso_double
Aa::getMass() const
{
qDebug() << "Aa::getMass() begin";
pappso_double mass = AaBase::getMass();
for(auto &&mod : m_listMod)
qDebug() << "Aa::getMass() begin";
pappso_double mass = AaBase::getMass();
for(auto &&mod : m_listMod)
{
mass += mod->getMass();
mass += mod->getMass();
}
// qDebug() << "Aa::getMass() end " << mass;
return mass;
// 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())
QString seq = "";
seq += this->getLetter();
auto it(m_listMod.begin());
if(it != m_listMod.end())
{
QStringList modification_str_list;
while(it != m_listMod.end())
QStringList modification_str_list;
while(it != m_listMod.end())
{
modification_str_list << (*it)->getAccession();
it++;
modification_str_list << (*it)->getAccession();
it++;
}
if(modification_str_list.size() > 0)
seq += QString("(%1)").arg(modification_str_list.join(","));
if(modification_str_list.size() > 0)
seq += QString("(%1)").arg(modification_str_list.join(","));
}
return seq;
return seq;
}
const QString
Aa::toString() const
{
QString seq = "";
seq += this->getLetter();
auto it(m_listMod.begin());
if(it != m_listMod.end())
QString seq = "";
seq += this->getLetter();
auto it(m_listMod.begin());
if(it != m_listMod.end())
{
QStringList modification_str_list;
while(it != m_listMod.end())
QStringList modification_str_list;
while(it != m_listMod.end())
{
if(!(*it)->isInternal())
if(!(*it)->isInternal())
{
modification_str_list << (*it)->getAccession();
modification_str_list << (*it)->getAccession();
}
it++;
it++;
}
if(modification_str_list.size() > 0)
seq += QString("(%1)").arg(modification_str_list.join(","));
if(modification_str_list.size() > 0)
seq += QString("(%1)").arg(modification_str_list.join(","));
}
return seq;
return seq;
}
void
Aa::removeAaModification(AaModificationP mod)
{
std::vector<AaModificationP>::iterator it =
std::find(m_listMod.begin(), m_listMod.end(), mod);
m_listMod.erase(it);
qDebug() << m_listMod << endl;
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 << 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());
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);
std::replace(m_listMod.begin(), m_listMod.end(), oldmod, newmod);
}
int
Aa::getNumberOfAtom(AtomIsotopeSurvey atom) const
{
int number_of_carbon = AaBase::getNumberOfAtom(atom);
for(auto &&mod : m_listMod)
int number_of_carbon = AaBase::getNumberOfAtom(atom);
for(auto &&mod : m_listMod)
{
number_of_carbon += mod->getNumberOfAtom(atom);
number_of_carbon += mod->getNumberOfAtom(atom);
}
// qDebug() << "Aa::getMass() end " << mass;
return number_of_carbon;
// qDebug() << "Aa::getMass() end " << mass;
return number_of_carbon;
}
int
Aa::getNumberOfIsotope(Isotope isotope) const
{
int number = 0;
for(auto &&mod : m_listMod)
int number = 0;
for(auto &&mod : m_listMod)
{
number += mod->getNumberOfIsotope(isotope);
number += mod->getNumberOfIsotope(isotope);
}
// qDebug() << "Aa::getMass() end " << mass;
return number;
// 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)
unsigned int number_of_mod = 0;
for(auto &&modb : m_listMod)
{
if(modb == mod)
number_of_mod += 1;
if(modb == mod)
number_of_mod += 1;
}
// qDebug() << "Aa::getMass() end " << mass;
return number_of_mod;
// qDebug() << "Aa::getMass() end " << mass;
return number_of_mod;
}
AaModificationP
Aa::getInternalNterModification() const
{
for(auto &&modb : m_listMod)
for(auto &&modb : m_listMod)
{
if(modb->getAccession().startsWith("internal:Nter_"))
return modb;
if(modb->getAccession().startsWith("internal:Nter_"))
return modb;
}
return nullptr;
return nullptr;
}
AaModificationP
Aa::getInternalCterModification() const
{
for(auto &&modb : m_listMod)
for(auto &&modb : m_listMod)
{
if(modb->getAccession().startsWith("internal:Cter_"))
return modb;
if(modb->getAccession().startsWith("internal:Cter_"))
return modb;
}
return nullptr;
return nullptr;
}
void
Aa::removeInternalNterModification()
{
std::remove_if(
std::remove_if(
m_listMod.begin(), m_listMod.end(), [](AaModificationP const &mod) {
return mod->getAccession().startsWith("internal:Nter_");
return mod->getAccession().startsWith("internal:Nter_");
});
}
void
Aa::removeInternalCterModification()
{
std::remove_if(
std::remove_if(
m_listMod.begin(), m_listMod.end(), [](AaModificationP const &mod) {
return mod->getAccession().startsWith("internal:Cter_");
return mod->getAccession().startsWith("internal:Cter_");
});
}
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)
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();
std::size_t a = m_listMod.size();
std::size_t b = r.m_listMod.size();
if(a == b)
if(a == b)
{
return (m_listMod < r.m_listMod);
return (m_listMod < r.m_listMod);
}
else
else
{
return (a < b);
return (a < b);
}
}
else
else
{
return (m_aaLetter < r.m_aaLetter);
return (m_aaLetter < r.m_aaLetter);
}
}
......@@ -267,19 +270,19 @@ bool
Aa::isAaEqual(Aa const &r) const
{
return (std::tie(m_aaLetter, m_listMod) ==
std::tie(r.m_aaLetter, r.m_listMod));
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);
return l.isAaEqual(r);
}
bool
operator<(Aa const &l, Aa const &r)
{
return l.isLesser(r);
return l.isLesser(r);
}
} /* namespace pappso */
This diff is collapsed.
......@@ -219,5 +219,28 @@ main()
<< peptide_normal.get()->isPalindrome() << endl;
return 1;
}
cout << endl << "..:: peptide dimethyl ::.." << endl;
//"Q(internal:Nter_hydrolytic_cleavage_H,MOD:00429)SLPSLSS(MOD:00696)FLNR(internal:Cter_hydrolytic_cleavage_HO)"
Peptide peptide_dimethyl("QSLPSLSSFLNR");
pappso::AaModificationP aaModDimethyl = AaModification::getInstance("MOD:00429");
pappso::AaModificationP aaModDimethyl2 = AaModification::getInstance("MOD:00696");
peptide_dimethyl.addAaModification(aaModDimethyl, 0);
peptide_dimethyl.addAaModification(aaModDimethyl2, 7);
cout << "Before " << peptide_dimethyl.toAbsoluteString().toStdString();
cout << endl << "remove AaModif" << endl;
peptide_dimethyl.removeAaModification(aaModDimethyl);
if(peptide_dimethyl.toAbsoluteString() != "Q(internal:Nter_hydrolytic_cleavage_H)SLPSLSS(MOD:00696)FLNR(internal:Cter_hydrolytic_cleavage_HO)")
{
cerr << "peptide_dimethyl.removeAaModification(aaModDimethyl) ERROR "
<< peptide_dimethyl.toAbsoluteString().toStdString() << " "
<< aaModDimethyl->getName().toStdString();
return 1;
}
cout << "Finish " << peptide_dimethyl.toAbsoluteString().toStdString();
return 0;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment