Loading...
Searching...
No Matches
posttreatment.cpp
Go to the documentation of this file.
/**
* \file pappsomspp/processing/specglob/sgposttreatment.cpp
* \date 15/11/2023
* \author Olivier Langella
* \brief SpecGlobTool peptide model post treatment
*
* C++ implementation of the SpecGlob algorithm described in :
* 1. Prunier, G. et al. Fast alignment of mass spectra in large proteomics
* datasets, capturing dissimilarities arising from multiple complex
* modifications of peptides. BMC Bioinformatics 24, 421 (2023).
*
* HAL Id : hal-04296170 , version 1
* Mot de passe : hxo20cl
* DOI : 10.1186/s12859-023-05555-y
*/
/*
* SpecGlobTool, Spectra to peptide alignment tool
* Copyright (C) 2023 Olivier Langella
* <olivier.langella@universite-paris-saclay.fr>
*
* This program is free software: you can redistribute ipetide to spectrum
* alignmentt 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "posttreatment.h"
namespace pappso
{
namespace specglob
{
PostTreatment::PostTreatment(pappso::PrecisionPtr precision, const PeptideModel &peptide_model)
: m_originalPeptideModel(peptide_model), m_betterPeptideModel(peptide_model)
{
m_precision = precision;
m_originalPeptideModel.matchExperimentalPeaks(m_precision);
findBetterPeptideModel();
}
PostTreatment::~PostTreatment()
{
}
const PeptideModel &
PostTreatment::getBetterPeptideModel() const
{
return m_betterPeptideModel;
}
void
PostTreatment::findBetterPeptideModel()
{
if(std::abs(m_originalPeptideModel.getMassDelta()) > m_precision->getNominal())
{
// calculate the number of shared peaks with the deltaM on the last aa
m_betterPeptideModel.assignResidualMass2Cter();
m_betterPeptideModel.matchExperimentalPeaks(m_precision);
if(m_betterPeptideModel.getCountSharedPeaks() > m_originalPeptideModel.getCountSharedPeaks())
{
}
else
{
// not better, get back to original peptide
m_betterPeptideModel.copyDeep(m_originalPeptideModel);
}
}
else
{
m_betterPeptideModel.matchExperimentalPeaks(m_precision);
}
// Try to remove complementary mass offset
// Not done if the number of peaks is increased by more than two peaks
// If the number of peaks > +2, it is considered as an information that must
// be kept in the alignment Could be modified...the information is in the
// preAligned column
PeptideModel test_peptide_model_remove_complementary(m_betterPeptideModel);
if(test_peptide_model_remove_complementary.eliminateComplementaryDelta(m_precision))
{
test_peptide_model_remove_complementary.matchExperimentalPeaks(m_precision);
qDebug() << "test_peptide_model_remove_complementary.getCountSharedPeaks()="
<< test_peptide_model_remove_complementary.getCountSharedPeaks()
<< " m_betterPeptideModel.getCountSharedPeaks()="
<< m_betterPeptideModel.getCountSharedPeaks();
if(test_peptide_model_remove_complementary.getCountSharedPeaks() <
m_betterPeptideModel.getCountSharedPeaks() + 2)
{
qDebug() << "replace with " << test_peptide_model_remove_complementary.toString();
m_betterPeptideModel.copyDeep(test_peptide_model_remove_complementary);
}
}
// if bestModified contains negative offSet, try to remove amino acids to
// explain it
PeptideModel test_peptide_model_remove_negative = m_betterPeptideModel;
if(test_peptide_model_remove_negative.eliminateNegativeOffset(m_precision))
{
test_peptide_model_remove_negative.matchExperimentalPeaks(m_precision);
if(test_peptide_model_remove_negative.getCountSharedPeaks() >=
m_betterPeptideModel.getCountSharedPeaks())
{
qDebug() << "replace with " << test_peptide_model_remove_negative.toString();
m_betterPeptideModel.copyDeep(test_peptide_model_remove_negative);
}
}
// findBetterMassDifferencePosition
tryToRemoveOffsets();
tryBetterPositionOffsets();
if(m_betterPeptideModel.getMassDelta() < -m_precision->getNominal())
{
tryToCumulateOffSets();
}
m_betterPeptideModel.removeBracketsForAlignedAA();
}
void
PostTreatment::tryBetterPositionOffsets()
{
PeptideModel better_peptide_model_move_offset = m_betterPeptideModel;
std::size_t best_count_shared_peaks = m_betterPeptideModel.getCountSharedPeaks();
qDebug() << best_count_shared_peaks;
qDebug() << m_betterPeptideModel.toString();
bool move = false;
for(std::size_t i = 0; i < m_betterPeptideModel.size(); i++)
{
qDebug() << "i =" << i;
if(m_betterPeptideModel.at(i).remove == true)
continue;
if(m_betterPeptideModel.at(i).mass_difference == 0.0)
continue;
if(m_betterPeptideModel.at(i).bracket == true)
{
// try to move if
double mass_diff = m_betterPeptideModel.at(i).mass_difference;
PeptideModel test_peptide_model_move_offset = better_peptide_model_move_offset;
test_peptide_model_move_offset.at(i).mass_difference = 0;
qDebug() << test_peptide_model_move_offset.toString();
std::size_t j = i;
while(j > 0)
{
j -= 1;
if(test_peptide_model_move_offset.at(j).bracket == false)
break;
if(test_peptide_model_move_offset.at(j).mass_difference != 0.0)
break;
test_peptide_model_move_offset.at(j).mass_difference = mass_diff;
test_peptide_model_move_offset.matchExperimentalPeaks(m_precision);
qDebug() << test_peptide_model_move_offset.toString() << " "
<< test_peptide_model_move_offset.getCountSharedPeaks() << " "
<< best_count_shared_peaks;
if(test_peptide_model_move_offset.getCountSharedPeaks() > best_count_shared_peaks)
{
best_count_shared_peaks = test_peptide_model_move_offset.getCountSharedPeaks();
better_peptide_model_move_offset.copyDeep(test_peptide_model_move_offset);
move = true;
}
else
{
test_peptide_model_move_offset = better_peptide_model_move_offset;
}
}
}
}
if(move)
{
m_betterPeptideModel.copyDeep(better_peptide_model_move_offset);
}
qDebug() << m_betterPeptideModel.toString();
}
void
PostTreatment::tryToRemoveOffsets()
{
// We'll try to evaluate for each deltaM if it can be a neutral loss or not
// For this, we compare the number of shared peaks with and without the shift
PeptideModel better_peptide_model_for_neutral_loss;
std::size_t best_count_shared_peaks = m_betterPeptideModel.getCountSharedPeaks();
qDebug() << best_count_shared_peaks;
for(std::size_t i = 0; i < m_betterPeptideModel.size(); i++)
{
if(m_betterPeptideModel.at(i).remove == true)
continue;
if(m_betterPeptideModel.at(i).mass_difference == 0.0)
continue;
// try in the case we remove the offset
PeptideModel test_peptide_model_for_neutral_loss = m_betterPeptideModel;
test_peptide_model_for_neutral_loss.at(i).mass_difference = 0;
test_peptide_model_for_neutral_loss.matchExperimentalPeaks(m_precision);
qDebug() << test_peptide_model_for_neutral_loss.toString() << " "
<< test_peptide_model_for_neutral_loss.getCountSharedPeaks() << " "
<< best_count_shared_peaks;
if(test_peptide_model_for_neutral_loss.getCountSharedPeaks() >= best_count_shared_peaks)
{
best_count_shared_peaks = test_peptide_model_for_neutral_loss.getCountSharedPeaks();
better_peptide_model_for_neutral_loss.copyDeep(test_peptide_model_for_neutral_loss);
}
}
if(better_peptide_model_for_neutral_loss.size() > 0)
{
m_betterPeptideModel.copyDeep(better_peptide_model_for_neutral_loss);
}
}
void
PostTreatment::tryToCumulateOffSets()
{
double mass_delta = m_betterPeptideModel.getMassDelta();
std::size_t best_count_shared_peaks = m_betterPeptideModel.getCountSharedPeaks();
PeptideModel better_peptide_model_cumulating_residual_mass_delta;
for(std::size_t i = 0; i < m_betterPeptideModel.size(); i++)
{
if(m_betterPeptideModel.at(i).remove == true)
continue;
if(m_betterPeptideModel.at(i).mass_difference == 0.0)
continue;
PeptideModel test_peptide_model_cumulating_residual_mass_delta = m_betterPeptideModel;
// try to cumulate the current mass difference with unexplained mass delta
// :
test_peptide_model_cumulating_residual_mass_delta.at(i).mass_difference += mass_delta;
test_peptide_model_cumulating_residual_mass_delta.matchExperimentalPeaks(m_precision);
if(test_peptide_model_cumulating_residual_mass_delta.getCountSharedPeaks() >=
best_count_shared_peaks)
{
best_count_shared_peaks =
test_peptide_model_cumulating_residual_mass_delta.getCountSharedPeaks();
better_peptide_model_cumulating_residual_mass_delta.copyDeep(
test_peptide_model_cumulating_residual_mass_delta);
}
}
if(better_peptide_model_cumulating_residual_mass_delta.size() > 0)
{
m_betterPeptideModel.copyDeep(better_peptide_model_cumulating_residual_mass_delta);
}
}
const PeptideModel &
PostTreatment::getOriginalPeptideModel() const
{
return m_originalPeptideModel;
}
bool
PostTreatment::findReplaceMutations()
{
auto peptide_model = m_betterPeptideModel;
bool modif = false;
std::vector<Enums::AminoAcidChar> aa_list = {Enums::AminoAcidChar::alanine,
Enums::AminoAcidChar::aspartic_acid,
Enums::AminoAcidChar::glutamic_acid,
Enums::AminoAcidChar::phenylalanine,
Enums::AminoAcidChar::glycine,
Enums::AminoAcidChar::histidine,
Enums::AminoAcidChar::isoleucine,
Enums::AminoAcidChar::lysine,
Enums::AminoAcidChar::leucine,
Enums::AminoAcidChar::methionine,
Enums::AminoAcidChar::asparagine,
Enums::AminoAcidChar::proline,
Enums::AminoAcidChar::glutamine,
Enums::AminoAcidChar::arginine,
Enums::AminoAcidChar::serine,
Enums::AminoAcidChar::threonine,
Enums::AminoAcidChar::valine,
Enums::AminoAcidChar::tryptophan,
Enums::AminoAcidChar::tyrosine};
if(peptide_model.checkForMutations(aa_list, m_precision))
{
modif = true;
}
pappso::Aa cysteine('C');
cysteine.addAaModification(pappso::AaModification::getInstance("MOD:00397")); // carbamido
if(peptide_model.checkForMutation(cysteine, m_precision))
{
modif = true;
}
pappso::Aa methionine('M');
methionine.addAaModification(pappso::AaModification::getInstance("MOD:00719")); // oxydation
if(peptide_model.checkForMutation(methionine, m_precision))
{
modif = true;
}
if(modif)
{
m_betterPeptideModel = peptide_model;
}
return modif;
}
} // namespace specglob
} // namespace pappso
pappso::AaModification::getInstance
static AaModificationP getInstance(const QString &accession)
Definition aamodification.cpp:368
pappso::Aa
Definition aa.h:45
pappso::specglob::PeptideModel
Definition peptidemodel.h:73
pappso::specglob::PeptideModel::getCountSharedPeaks
std::size_t getCountSharedPeaks() const
Definition peptidemodel.cpp:440
pappso::specglob::PeptideModel::matchExperimentalPeaks
void matchExperimentalPeaks(pappso::PrecisionPtr precision)
Definition peptidemodel.cpp:319
pappso::specglob::PeptideModel::eliminateNegativeOffset
bool eliminateNegativeOffset(pappso::PrecisionPtr precision)
Definition peptidemodel.cpp:541
pappso::specglob::PeptideModel::toString
QString toString() const
Definition peptidemodel.cpp:128
pappso::specglob::PeptideModel::eliminateComplementaryDelta
bool eliminateComplementaryDelta(pappso::PrecisionPtr precision)
Definition peptidemodel.cpp:464
pappso::specglob::PeptideModel::copyDeep
PeptideModel & copyDeep(const PeptideModel &other)
Definition peptidemodel.cpp:109
pappso::specglob::PostTreatment::PostTreatment
PostTreatment(pappso::PrecisionPtr precision, const PeptideModel &peptide_model)
Definition posttreatment.cpp:45
pappso::specglob::PostTreatment::getOriginalPeptideModel
const PeptideModel & getOriginalPeptideModel() const
Definition posttreatment.cpp:275
pappso::specglob::PostTreatment::m_precision
pappso::PrecisionPtr m_precision
Definition posttreatment.h:114
pappso::specglob::PostTreatment::findBetterPeptideModel
void findBetterPeptideModel()
whole processus to find a better peptide model
Definition posttreatment.cpp:65
pappso::specglob::PostTreatment::~PostTreatment
virtual ~PostTreatment()
Definition posttreatment.cpp:54
pappso::specglob::PostTreatment::tryToCumulateOffSets
void tryToCumulateOffSets()
try to assign residual mass delta to non aligned elements
Definition posttreatment.cpp:240
pappso::specglob::PostTreatment::m_betterPeptideModel
PeptideModel m_betterPeptideModel
Definition posttreatment.h:113
pappso::specglob::PostTreatment::findReplaceMutations
bool findReplaceMutations()
Definition posttreatment.cpp:281
pappso::specglob::PostTreatment::getBetterPeptideModel
const PeptideModel & getBetterPeptideModel() const
Definition posttreatment.cpp:59
pappso::specglob::PostTreatment::m_originalPeptideModel
PeptideModel m_originalPeptideModel
Definition posttreatment.h:112
pappso::specglob::PostTreatment::tryToRemoveOffsets
void tryToRemoveOffsets()
try to remove offset (mass difference)
Definition posttreatment.cpp:201
pappso::specglob::PostTreatment::tryBetterPositionOffsets
void tryBetterPositionOffsets()
try to move offset (mass difference)
Definition posttreatment.cpp:138
pappso::Enums::AminoAcidChar::lysine
@ lysine
Definition types.h:205
pappso::Enums::AminoAcidChar::tyrosine
@ tyrosine
Definition types.h:216
pappso::Enums::AminoAcidChar::glycine
@ glycine
Definition types.h:202
pappso::Enums::AminoAcidChar::methionine
@ methionine
Definition types.h:207
pappso::Enums::AminoAcidChar::proline
@ proline
Definition types.h:209
pappso::Enums::AminoAcidChar::asparagine
@ asparagine
Definition types.h:208
pappso::Enums::AminoAcidChar::histidine
@ histidine
Definition types.h:203
pappso::Enums::AminoAcidChar::alanine
@ alanine
Definition types.h:197
pappso::Enums::AminoAcidChar::glutamic_acid
@ glutamic_acid
Definition types.h:200
pappso::Enums::AminoAcidChar::leucine
@ leucine
Definition types.h:206
pappso::Enums::AminoAcidChar::arginine
@ arginine
Definition types.h:211
pappso::Enums::AminoAcidChar::threonine
@ threonine
Definition types.h:213
pappso::Enums::AminoAcidChar::serine
@ serine
Definition types.h:212
pappso::Enums::AminoAcidChar::phenylalanine
@ phenylalanine
Definition types.h:201
pappso::Enums::AminoAcidChar::valine
@ valine
Definition types.h:214
pappso::Enums::AminoAcidChar::aspartic_acid
@ aspartic_acid
Definition types.h:199
pappso::Enums::AminoAcidChar::tryptophan
@ tryptophan
Definition types.h:215
pappso::Enums::AminoAcidChar::isoleucine
@ isoleucine
Definition types.h:204
pappso::Enums::AminoAcidChar::glutamine
@ glutamine
Definition types.h:210
pappso::specglob
Definition experimentalspectrum.cpp:44
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
pappso::PrecisionPtr
const PrecisionBase * PrecisionPtr
Definition precision.h:122
posttreatment.h