libpappsomspp
Library for mass spectrometry
peptideisotopespectrummatch.cpp
Go to the documentation of this file.
1 /*
2  * *******************************************************************************
3  * * Copyright (c) 2015 Olivier Langella <Olivier.Langella@moulon.inra.fr>.
4  * *
5  * * This file is part of MassChroqPRM.
6  * *
7  * * MassChroqPRM is free software: you can redistribute it and/or modify
8  * * it under the terms of the GNU General Public License as published by
9  * * the Free Software Foundation, either version 3 of the License, or
10  * * (at your option) any later version.
11  * *
12  * * MassChroqPRM is distributed in the hope that it will be useful,
13  * * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * * GNU General Public License for more details.
16  * *
17  * * You should have received a copy of the GNU General Public License
18  * * along with MassChroqPRM. If not, see <http://www.gnu.org/licenses/>.
19  * *
20  * * Contributors:
21  * * Olivier Langella <Olivier.Langella@moulon.inra.fr> - initial API and
22  * implementation
23  * ******************************************************************************/
24 
25 
27 
28 namespace pappso
29 {
31  const MassSpectrum &spectrum,
32  const PeptideSp &peptideSp,
33  unsigned int parent_charge,
34  PrecisionPtr precision,
35  std::list<PeptideIon> ion_type_list,
36  unsigned int max_isotope_number,
37  [[maybe_unused]] unsigned int max_isotope_rank)
38  : _precision(precision)
39 {
40 
41  try
42  {
43  qDebug() << "PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch "
44  "begin max_isotope_number="
45  << max_isotope_number;
46  PeptideFragmentIonListBase fragmentIonList(peptideSp, ion_type_list);
47  qDebug() << "PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch "
48  "peak_list spectrum.size="
49  << spectrum.size();
50  std::list<DataPoint> peak_list(spectrum.begin(), spectrum.end());
51 
52  qDebug() << "PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch "
53  "ion_type_list";
54  for(auto ion_type : ion_type_list)
55  {
56  auto ion_list = fragmentIonList.getPeptideFragmentIonSp(ion_type);
57  qDebug() << "PeptideIsotopeSpectrumMatch::"
58  "PeptideIsotopeSpectrumMatch fragmentIonList";
59 
60  for(unsigned int charge = 1; charge <= parent_charge; charge++)
61  {
62  for(auto &&ion : ion_list)
63  {
64  unsigned int askedIsotopeRank = 1;
65  for(unsigned int isotope_number = 0;
66  isotope_number <= max_isotope_number;
67  isotope_number++)
68  {
69  PeptideNaturalIsotopeAverage isotopeIon(ion,
70  askedIsotopeRank,
71  isotope_number,
72  charge,
73  precision);
74 
75  std::list<DataPoint>::iterator it_peak =
76  getBestPeakIterator(peak_list, isotopeIon);
77  if(it_peak != peak_list.end())
78  {
79  _peak_ion_match_list.push_back(PeakIonIsotopeMatch(
80  *it_peak,
81  isotopeIon.makePeptideNaturalIsotopeAverageSp(),
82  ion));
83  peak_list.erase(it_peak);
84  }
85  }
86  }
87  }
88  }
89  qDebug()
90  << "PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch end";
91  }
92  catch(PappsoException &exception_pappso)
93  {
94  QString errorStr =
95  QObject::tr(
96  "ERROR building PeptideIsotopeSpectrumMatch, PAPPSO exception:\n%1")
97  .arg(exception_pappso.qwhat());
98  qDebug() << "PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch "
99  "PappsoException :\n"
100  << errorStr;
101  throw PappsoException(errorStr);
102  }
103  catch(std::exception &exception_std)
104  {
105  QString errorStr =
106  QObject::tr(
107  "ERROR building PeptideIsotopeSpectrumMatch, std exception:\n%1")
108  .arg(exception_std.what());
109  qDebug() << "PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch "
110  "std::exception :\n"
111  << errorStr;
112  throw PappsoException(errorStr);
113  }
114 }
115 
116 PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch(
117  const MassSpectrum &spectrum,
118  std::vector<PeptideNaturalIsotopeAverageSp> v_peptideIsotopeList,
119  std::vector<PeptideFragmentIonSp> v_peptideIonList,
120  PrecisionPtr precision)
121  : _precision(precision)
122 {
123  qDebug() << "PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch begin";
124  if(v_peptideIsotopeList.size() != v_peptideIonList.size())
125  {
126  throw PappsoException(
127  QObject::tr(
128  "v_peptideIsotopeList.size() %1 != v_peptideIonList.size() %2")
129  .arg(v_peptideIsotopeList.size())
130  .arg(v_peptideIonList.size()));
131  }
132 
133  auto isotopeIt = v_peptideIsotopeList.begin();
134  auto ionIt = v_peptideIonList.begin();
135  std::list<DataPoint> peak_list(spectrum.begin(), spectrum.end());
136 
137  while(isotopeIt != v_peptideIsotopeList.end())
138  {
139  std::list<DataPoint>::iterator it_peak =
140  getBestPeakIterator(peak_list, *(isotopeIt->get()));
141  if(it_peak != peak_list.end())
142  {
143  _peak_ion_match_list.push_back(
144  PeakIonIsotopeMatch(*it_peak, *isotopeIt, *ionIt));
145  peak_list.erase(it_peak);
146  }
147  isotopeIt++;
148  ionIt++;
149  }
150  qDebug() << "PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch end";
151 }
152 
153 
155  const PeptideIsotopeSpectrumMatch &other)
156  : _precision(other._precision),
157  _peak_ion_match_list(other._peak_ion_match_list)
158 {
159 }
160 
162 {
163 }
164 
165 
166 std::list<DataPoint>::iterator
168  std::list<DataPoint> &peak_list,
169  const PeptideNaturalIsotopeAverage &ion) const
170 {
171  // qDebug();
172  std::list<DataPoint>::iterator itpeak = peak_list.begin();
173  std::list<DataPoint>::iterator itend = peak_list.end();
174  std::list<DataPoint>::iterator itselect = peak_list.end();
175 
176  pappso_double best_intensity = 0;
177 
178  while(itpeak != itend)
179  {
180  if(ion.matchPeak(itpeak->x))
181  {
182  if(itpeak->y > best_intensity)
183  {
184  best_intensity = itpeak->y;
185  itselect = itpeak;
186  }
187  }
188  itpeak++;
189  }
190  // qDebug();
191  return (itselect);
192 }
193 
194 const std::list<PeakIonIsotopeMatch> &
196 {
197  return _peak_ion_match_list;
198 }
199 
200 
201 } // namespace pappso
Class to represent a mass spectrum.
Definition: massspectrum.h:71
PeptideIsotopeSpectrumMatch(const MassSpectrum &spectrum, const PeptideSp &peptide_sp, unsigned int parent_charge, PrecisionPtr precision, std::list< PeptideIon > ion_list, unsigned int max_isotope_number, unsigned int max_isotope_rank)
annotate spectrum with peptide ions and isotopes
std::list< PeakIonIsotopeMatch > _peak_ion_match_list
virtual std::list< DataPoint >::iterator getBestPeakIterator(std::list< DataPoint > &peak_list, const PeptideNaturalIsotopeAverage &ion) const
const std::list< PeakIonIsotopeMatch > & getPeakIonIsotopeMatchList() const
virtual bool matchPeak(pappso_double peak_mz) const final
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
std::shared_ptr< const Peptide > PeptideSp
double pappso_double
A type definition for doubles.
Definition: types.h:48
const PrecisionBase * PrecisionPtr
Definition: precision.h:122