libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
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#include "../peptide/peptidenaturalisotopelist.h"
28
29namespace pappso
30{
32 const MassSpectrum &spectrum,
33 const PeptideSp &peptideSp,
34 unsigned int parent_charge,
35 PrecisionPtr precision,
36 const std::list<PeptideIon> &ion_type_list,
37 unsigned int max_isotope_number,
38 [[maybe_unused]] unsigned int max_isotope_rank)
39 : _precision(precision)
40{
41
42 try
43 {
45 qDebug() << "peptideSp.get()->getSequence()="
46 << peptideSp.get()->getSequence()
47 << " max_isotope_number=" << max_isotope_number
48 << " spectrum.size=" << spectrum.size()
49 << " parent_charge=" << parent_charge
50 << " ion_type_list.size=" << ion_type_list.size()
51 << " max_isotope_rank=" << max_isotope_rank;
52 PeptideFragmentIonListBase fragmentIonList(peptideSp, ion_type_list);
53 qDebug() << " fragmentIonList.size()=" << fragmentIonList.size();
54 std::vector<DataPoint> peak_list(spectrum.begin(), spectrum.end());
55 for(auto ion_type : ion_type_list)
56 {
57 const std::list<PeptideFragmentIonSp> peptide_fragment_ion_list =
58 fragmentIonList.getPeptideFragmentIonSp(ion_type);
59 qDebug() << " peptide_fragment_ion_list.size()="
60 << peptide_fragment_ion_list.size();
61
62 for(unsigned int charge = 1; charge <= parent_charge; charge++)
63 {
64 qDebug();
65 for(auto &&peptide_fragment_ion : peptide_fragment_ion_list)
66 {
67 qDebug() << "peptide_fragment_ion.get()->getMz(charge)="
68 << peptide_fragment_ion.get()->getMz(charge);
69 PeptideNaturalIsotopeList isotope_list(peptide_fragment_ion);
70 for(unsigned int isotope_number = 0;
71 isotope_number <= max_isotope_number;
72 isotope_number++)
73 {
74 qDebug();
75 PeptideNaturalIsotopeAverage *p_isotopeIon;
76 if(max_isotope_rank == 0)
77 {
78 // fast constructor, no need to compute isotope ratio
79 p_isotopeIon = new PeptideNaturalIsotopeAverage(
80 peptide_fragment_ion,
81 isotope_number,
82 charge,
83 precision);
84 }
85 else
86 {
87 p_isotopeIon =
88 new PeptideNaturalIsotopeAverage(isotope_list,
89 max_isotope_rank,
90 isotope_number,
91 charge,
92 precision);
93 }
94
95 qDebug()
96 << "max_isotope_rank=" << max_isotope_rank
97 << " isotope_number=" << isotope_number
98 << " charge=" << charge << " precision=" << precision
99 << " p_isotopeIon->getMz()=" << p_isotopeIon->getMz()
100 << " " << isotope_number << " "
101 << p_isotopeIon->toString();
102
103 std::vector<DataPoint>::iterator it_peak =
104 getBestPeakIterator(peak_list, *p_isotopeIon);
105 if(it_peak != peak_list.end())
106 {
108 *it_peak,
110 peptide_fragment_ion));
111 peak_list.erase(it_peak);
112
113 qDebug() << isotope_number << " "
114 << _peak_ion_match_list.back().toString();
115 }
116 delete p_isotopeIon;
117 }
118 }
119 }
120 }
121 }
122 catch(PappsoException &exception_pappso)
123 {
124 QString errorStr =
125 QObject::tr(
126 "ERROR building PeptideIsotopeSpectrumMatch, PAPPSO exception:\n%1")
127 .arg(exception_pappso.qwhat());
128 qDebug() << "PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch "
129 "PappsoException :\n"
130 << errorStr;
131 throw PappsoException(errorStr);
132 }
133 catch(std::exception &exception_std)
134 {
135 QString errorStr =
136 QObject::tr(
137 "ERROR building PeptideIsotopeSpectrumMatch, std exception:\n%1")
138 .arg(exception_std.what());
139 qDebug() << "PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch "
140 "std::exception :\n"
141 << errorStr;
142 throw PappsoException(errorStr);
143 }
144
145 qDebug() << "_peak_ion_match_list.size()=" << _peak_ion_match_list.size();
146}
147
149 const MassSpectrum &spectrum,
150 std::vector<PeptideNaturalIsotopeAverageSp> v_peptideIsotopeList,
151 std::vector<PeptideFragmentIonSp> v_peptideIonList,
152 PrecisionPtr precision)
153 : _precision(precision)
154{
155 qDebug() << " begin";
156 if(v_peptideIsotopeList.size() != v_peptideIonList.size())
157 {
158 throw PappsoException(
159 QObject::tr(
160 "v_peptideIsotopeList.size() %1 != v_peptideIonList.size() %2")
161 .arg(v_peptideIsotopeList.size())
162 .arg(v_peptideIonList.size()));
163 }
164
165 auto isotopeIt = v_peptideIsotopeList.begin();
166 auto ionIt = v_peptideIonList.begin();
167 std::vector<DataPoint> peak_list(spectrum.begin(), spectrum.end());
168
169 while(isotopeIt != v_peptideIsotopeList.end())
170 {
171 std::vector<DataPoint>::iterator it_peak =
172 getBestPeakIterator(peak_list, *(isotopeIt->get()));
173 if(it_peak != peak_list.end())
174 {
175 _peak_ion_match_list.push_back(
176 PeakIonIsotopeMatch(*it_peak, *isotopeIt, *ionIt));
177 peak_list.erase(it_peak);
178 }
179 isotopeIt++;
180 ionIt++;
181 }
182 qDebug() << "_peak_ion_match_list.size()=" << _peak_ion_match_list.size()
183 << " end";
184}
185
186
188 const PeptideIsotopeSpectrumMatch &other)
189 : _precision(other._precision),
190 _peak_ion_match_list(other._peak_ion_match_list)
191{
192 qDebug();
193}
194
198
199
200std::vector<DataPoint>::iterator
202 std::vector<DataPoint> &peak_list,
203 const PeptideNaturalIsotopeAverage &ion) const
204{
205 // qDebug();
206 std::vector<DataPoint>::iterator itpeak = peak_list.begin();
207 std::vector<DataPoint>::iterator itend = peak_list.end();
208 std::vector<DataPoint>::iterator itselect = peak_list.end();
209
210 pappso_double best_intensity = 0;
211
212 while(itpeak != itend)
213 {
214 // qDebug() << itpeak->x;
215 if(ion.matchPeak(itpeak->x))
216 {
217 if(itpeak->y > best_intensity)
218 {
219 best_intensity = itpeak->y;
220 itselect = itpeak;
221 }
222 }
223 itpeak++;
224 }
225 // qDebug();
226 return (itselect);
227}
228
229const std::list<PeakIonIsotopeMatch> &
231{
232 qDebug() << "_peak_ion_match_list.size()=" << _peak_ion_match_list.size();
234}
235
236std::size_t
238{
239 return _peak_ion_match_list.size();
240}
243{
244 return _peak_ion_match_list.begin();
245}
248{
249 return _peak_ion_match_list.end();
250}
251
252void
254{
255 qDebug();
257 [](const PeakIonIsotopeMatch &a, const PeakIonIsotopeMatch &b) {
258 if(a.getPeptideIonType() < b.getPeptideIonType())
259 return true;
260 if(a.getPeptideFragmentIonSp().get()->size() <
261 b.getPeptideFragmentIonSp().get()->size())
262 return true;
263 if(a.getCharge() < b.getCharge())
264 return true;
265 if(a.getPeptideNaturalIsotopeAverageSp().get()->getIsotopeNumber() <
266 b.getPeptideNaturalIsotopeAverageSp().get()->getIsotopeNumber())
267 return true;
268 return false;
269 });
270 PeptideIon ion_type = PeptideIon::b;
271 std::size_t nserie = 0;
272 std::size_t isotopeserie = 0;
273 unsigned int charge = 0;
274 for(std::list<PeakIonIsotopeMatch>::iterator it =
275 _peak_ion_match_list.begin();
276 it != _peak_ion_match_list.end();
277 it++)
278 {
279 if((nserie != it->getPeptideFragmentIonSp().get()->size()) ||
280 (ion_type != it->getPeptideIonType()) || (charge != it->getCharge()))
281 {
282 ion_type = it->getPeptideIonType();
283 isotopeserie = 0;
284 nserie = it->getPeptideFragmentIonSp().get()->size();
285 charge = it->getCharge();
286 }
287 if(isotopeserie <=
288 it->getPeptideNaturalIsotopeAverageSp().get()->getIsotopeNumber())
289 {
290 isotopeserie =
291 it->getPeptideNaturalIsotopeAverageSp().get()->getIsotopeNumber();
292 }
293 else
294 {
295 it = _peak_ion_match_list.erase(it);
296 }
297 }
298 qDebug();
299}
300} // namespace pappso
Class to represent a mass spectrum.
virtual const QString & qwhat() const
const std::list< PeptideFragmentIonSp > getPeptideFragmentIonSp(PeptideIon ion_type) const
std::list< PeakIonIsotopeMatch >::const_iterator const_iterator
std::list< PeakIonIsotopeMatch > _peak_ion_match_list
PeptideIsotopeSpectrumMatch(const MassSpectrum &spectrum, const PeptideSp &peptide_sp, unsigned int parent_charge, PrecisionPtr precision, const std::list< PeptideIon > &ion_type_list, unsigned int max_isotope_number, unsigned int max_isotope_rank)
annotate spectrum with peptide ions and isotopes
const std::list< PeakIonIsotopeMatch > & getPeakIonIsotopeMatchList() const
virtual std::vector< DataPoint >::iterator getBestPeakIterator(std::vector< DataPoint > &peak_list, const PeptideNaturalIsotopeAverage &ion) const
virtual bool matchPeak(pappso_double peak_mz) const final
PeptideNaturalIsotopeAverageSp makePeptideNaturalIsotopeAverageSp() const
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
PeptideIon
PeptideIon enum defines all types of ions (Nter or Cter)
Definition types.h:432
@ b
Nter acylium ions.
std::shared_ptr< const Peptide > PeptideSp
double pappso_double
A type definition for doubles.
Definition types.h:50