Loading...
Searching...
No Matches
peptidespectrummatch.cpp
Go to the documentation of this file.
/**
* \file pappsomspp/psm/peptidespectrummatch.cpp
* \date 2/4/2015
* \author Olivier Langella
* \brief find peaks matching between ions and spectrum
*/
/*******************************************************************************
* 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 <list>
#include <numeric>
#include "peakionmatch.h"
#include "peptidespectrummatch.h"
#include "pappsomspp/core/pappsoexception.h"
#include "pappsomspp/core/peptide/peptidefragment.h"
#include "pappsomspp/core/peptide/peptidefragmentionlistbase.h"
namespace pappso
{
void
PeptideSpectrumMatch::privMatchIonList(const MassSpectrum &spectrum,
const PeptideFragmentIonListBase &fragmentIonList,
unsigned int max_charge,
const std::list<Enums::PeptideIon> &ion_type_list_in)
{
// qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
// << " ion_type_list.size()=" << ion_type_list.size();
std::list<DataPoint> peak_list(spectrum.begin(), spectrum.end());
// qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
// << " peak_list.size()=" << peak_list.size();
std::list<Enums::PeptideIon> ion_type_list(ion_type_list_in);
ion_type_list.sort([](const Enums::PeptideIon &iona, const Enums::PeptideIon &ionb) {
if(iona == Enums::PeptideIon::b)
return true;
if(ionb == Enums::PeptideIon::b)
return false;
if(iona == Enums::PeptideIon::y)
return true;
if(ionb == Enums::PeptideIon::y)
return false;
return iona > ionb;
});
for(auto ion_type : ion_type_list)
{
auto ion_list = fragmentIonList.getPeptideFragmentIonSp(ion_type);
// qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
// << " ion_list.size()=" << ion_list.size();
for(unsigned int charge = 1; charge <= max_charge; charge++)
{
for(auto &&ion : ion_list)
{
std::list<DataPoint>::iterator it_peak = getBestPeakIterator(peak_list, ion, charge);
if(it_peak != peak_list.end())
{
// qDebug() << __FILE__ << " " << __FUNCTION__ << " " <<
// __LINE__
// << " peak FOUND";
_peak_ion_match_list.push_back(PeakIonMatch(*it_peak, ion, charge));
_ion_type_count[(std::int8_t)ion->getPeptideIonType()]++;
peak_list.erase(it_peak);
}
}
}
}
}
PeptideSpectrumMatch::PeptideSpectrumMatch(
const MassSpectrum &spectrum,
std::vector<PeptideFragmentIonSp> &v_peptide_fragment_ion,
std::vector<unsigned int> &v_peptide_fragment_ion_charge,
PrecisionPtr precision)
: _precision(precision)
{
qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
// throw PappsoException(QObject::tr("v_peptideIsotopeList.size() %1 !=
// v_peptideIonList.size()
// %2").arg(v_peptideIsotopeList.size()).arg(v_peptideIonList.size()));
if(v_peptide_fragment_ion.size() != v_peptide_fragment_ion_charge.size())
{
throw PappsoException(QObject::tr("v_peptide_fragment_ion.size() != "
"v_peptide_fragment_ion_charge.size() %2")
.arg(v_peptide_fragment_ion.size())
.arg(v_peptide_fragment_ion_charge.size()));
}
auto ionIt = v_peptide_fragment_ion.begin();
auto chargeIt = v_peptide_fragment_ion_charge.begin();
std::list<DataPoint> peak_list(spectrum.begin(), spectrum.end());
while(ionIt != v_peptide_fragment_ion.end())
{
std::list<DataPoint>::iterator it_peak = getBestPeakIterator(peak_list, *ionIt, *chargeIt);
if(it_peak != peak_list.end())
{
_peak_ion_match_list.push_back(PeakIonMatch(*it_peak, *ionIt, *chargeIt));
_ion_type_count[(std::int8_t)ionIt->get()->getPeptideIonType()]++;
peak_list.erase(it_peak);
}
ionIt++;
chargeIt++;
}
qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
<< " _ion_type_count[PeptideIon::y]="
<< _ion_type_count[(std::int8_t)Enums::PeptideIon::y];
}
PeptideSpectrumMatch::PeptideSpectrumMatch(const MassSpectrum &spectrum,
const PeptideFragmentIonListBase &fragmentIonList,
unsigned int max_charge,
PrecisionPtr precision,
const std::list<Enums::PeptideIon> &ion_type_list)
: _precision(precision)
{
privMatchIonList(spectrum, fragmentIonList, max_charge, ion_type_list);
qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
<< " _ion_type_count[PeptideIon::y]="
<< _ion_type_count[(std::int8_t)Enums::PeptideIon::y];
}
PeptideSpectrumMatch::PeptideSpectrumMatch(const MassSpectrum &spectrum,
const pappso::PeptideSp &peptideSp,
unsigned int parent_charge,
PrecisionPtr precision,
const std::list<Enums::PeptideIon> &ion_type_list)
: _precision(precision)
{
PeptideFragmentIonListBase fragmentIonList(peptideSp, ion_type_list);
privMatchIonList(spectrum, fragmentIonList, parent_charge, ion_type_list);
qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
<< " _ion_type_count[PeptideIon::y]="
<< _ion_type_count[(std::int8_t)Enums::PeptideIon::y];
}
PeptideSpectrumMatch::PeptideSpectrumMatch(const PeptideSpectrumMatch &other)
: _precision(other._precision), _peak_ion_match_list(other._peak_ion_match_list)
{
}
std::list<DataPoint>::iterator
PeptideSpectrumMatch::getBestPeakIterator(std::list<DataPoint> &peak_list,
const PeptideFragmentIonSp &ion,
unsigned int charge) const
{
// qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
// << " peak_list.size()=" << peak_list.size();
std::list<DataPoint>::iterator itpeak = peak_list.begin();
std::list<DataPoint>::iterator itend = peak_list.end();
std::list<DataPoint>::iterator itselect = peak_list.end();
pappso_double best_intensity = 0;
while(itpeak != itend)
{
// qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
// << " itpeak->x=" << itpeak->x;
if(ion.get()->matchPeak(_precision, itpeak->x, charge))
{
// qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
// << " ion.get()->matchPeak";
if(itpeak->y > best_intensity)
{
best_intensity = itpeak->y;
itselect = itpeak;
}
}
itpeak++;
}
return (itselect);
}
PeptideSpectrumMatch::~PeptideSpectrumMatch()
{
}
unsigned int
PeptideSpectrumMatch::size() const
{
return _peak_ion_match_list.size();
}
PeptideSpectrumMatch::const_iterator
PeptideSpectrumMatch::begin() const
{
return _peak_ion_match_list.begin();
}
PeptideSpectrumMatch::const_iterator
PeptideSpectrumMatch::end() const
{
return _peak_ion_match_list.end();
}
unsigned int
PeptideSpectrumMatch::countTotalMatchedIons() const
{
return std::accumulate(_ion_type_count.begin(), _ion_type_count.end(), 0);
}
const std::array<unsigned int, PEPTIDE_ION_TYPE_COUNT> &
PeptideSpectrumMatch::getIonTypeCountArray() const
{
return _ion_type_count;
}
bool
PeptideSpectrumMatch::contains(const PeptideFragmentIon *peptideFragmentIonSp, unsigned int z) const
{
auto it = _peak_ion_match_list.begin();
while(it != _peak_ion_match_list.end())
{
const PeakIonMatch &ref = *it;
if((ref.getCharge() == z) && (ref.getPeptideFragmentIonSp().get() == peptideFragmentIonSp))
{
return true;
}
it++;
}
return false;
}
} // namespace pappso
pappso::MassSpectrum
Class to represent a mass spectrum.
Definition massspectrum.h:70
pappso::PappsoException
Definition pappsoexception.h:41
pappso::PeakIonMatch
Definition peakionmatch.h:40
pappso::PeakIonMatch::getPeptideFragmentIonSp
virtual const PeptideFragmentIonSp & getPeptideFragmentIonSp() const
Definition peakionmatch.cpp:68
pappso::PeakIonMatch::getCharge
unsigned int getCharge() const
Definition peakionmatch.cpp:80
pappso::PeptideFragmentIonListBase
Definition peptidefragmentionlistbase.h:45
pappso::PeptideFragmentIonListBase::getPeptideFragmentIonSp
const std::list< PeptideFragmentIonSp > getPeptideFragmentIonSp(Enums::PeptideIon ion_type) const
Definition peptidefragmentionlistbase.cpp:226
pappso::PeptideFragmentIon
Definition peptidefragmention.h:50
pappso::PeptideSpectrumMatch::getBestPeakIterator
virtual std::list< DataPoint >::iterator getBestPeakIterator(std::list< DataPoint > &peak_list, const PeptideFragmentIonSp &ion, unsigned int charge) const
Definition peptidespectrummatch.cpp:172
pappso::PeptideSpectrumMatch::contains
bool contains(const PeptideFragmentIon *peptideFragmentIonSp, unsigned int z) const
Definition peptidespectrummatch.cpp:240
pappso::PeptideSpectrumMatch::_ion_type_count
std::array< unsigned int, PEPTIDE_ION_TYPE_COUNT > _ion_type_count
Definition peptidespectrummatch.h:96
pappso::PeptideSpectrumMatch::countTotalMatchedIons
unsigned int countTotalMatchedIons() const
Definition peptidespectrummatch.cpp:228
pappso::PeptideSpectrumMatch::end
const_iterator end() const
Definition peptidespectrummatch.cpp:222
pappso::PeptideSpectrumMatch::size
unsigned int size() const
Definition peptidespectrummatch.cpp:211
pappso::PeptideSpectrumMatch::~PeptideSpectrumMatch
virtual ~PeptideSpectrumMatch()
Definition peptidespectrummatch.cpp:205
pappso::PeptideSpectrumMatch::_peak_ion_match_list
std::list< PeakIonMatch > _peak_ion_match_list
Definition peptidespectrummatch.h:94
pappso::PeptideSpectrumMatch::getIonTypeCountArray
const std::array< unsigned int, PEPTIDE_ION_TYPE_COUNT > & getIonTypeCountArray() const
Definition peptidespectrummatch.cpp:234
pappso::PeptideSpectrumMatch::PeptideSpectrumMatch
PeptideSpectrumMatch(const MassSpectrum &spectrum, const pappso::PeptideSp &peptideSp, unsigned int parent_charge, PrecisionPtr precision, const std::list< Enums::PeptideIon > &ion_type_list)
Definition peptidespectrummatch.cpp:151
pappso::PeptideSpectrumMatch::_precision
PrecisionPtr _precision
Definition peptidespectrummatch.h:92
pappso::PeptideSpectrumMatch::const_iterator
std::list< PeakIonMatch >::const_iterator const_iterator
Definition peptidespectrummatch.h:69
pappso::PeptideSpectrumMatch::begin
const_iterator begin() const
Definition peptidespectrummatch.cpp:217
pappso::PeptideSpectrumMatch::privMatchIonList
void privMatchIonList(const MassSpectrum &spectrum, const PeptideFragmentIonListBase &fragmentIonList, unsigned int max_charge, const std::list< Enums::PeptideIon > &ion_type_list)
Definition peptidespectrummatch.cpp:45
pappso::Enums::PeptideIon
PeptideIon
Enums::PeptideIon enum defines all types of ions (Nter or Cter).
Definition types.h:286
pappso::Enums::PeptideIon::y
@ y
Cter amino ions.
Definition types.h:295
pappso::Enums::PeptideIon::b
@ b
Nter acylium ions.
Definition types.h:287
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
pappso::PeptideFragmentIonSp
std::shared_ptr< const PeptideFragmentIon > PeptideFragmentIonSp
Definition peptidefragmention.h:46
pappso::PeptideSp
std::shared_ptr< const Peptide > PeptideSp
Definition aamodification.h:48
pappso::PeptideIonCter::z
@ z
Definition peptide.h:90
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition types.h:60
pappso::PrecisionPtr
const PrecisionBase * PrecisionPtr
Definition precision.h:122
pappsoexception.h
peakionmatch.h
peptidefragment.h
peptidefragmentionlistbase.h
peptidespectrummatch.h