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
28
29namespace pappso
30{
32 const MassSpectrum &spectrum,
33 const PeptideSp &peptideSp,
34 unsigned int parent_charge,
35 PrecisionPtr precision,
36 const std::list<Enums::PeptideIon> &ion_type_list_in,
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()=" << peptideSp.get()->getSequence()
46 << " max_isotope_number=" << max_isotope_number
47 << " spectrum.size=" << spectrum.size() << " parent_charge=" << parent_charge
48 << " ion_type_list.size=" << ion_type_list_in.size()
49 << " max_isotope_rank=" << max_isotope_rank;
50 PeptideFragmentIonListBase fragmentIonList(peptideSp, ion_type_list_in);
51 std::list<Enums::PeptideIon> ion_type_list(ion_type_list_in);
52
53 ion_type_list.sort([](const Enums::PeptideIon &iona, const Enums::PeptideIon &ionb) {
54 if(iona == Enums::PeptideIon::b)
55 return true;
56 if(ionb == Enums::PeptideIon::b)
57 return false;
58 if(iona == Enums::PeptideIon::y)
59 return true;
60 if(ionb == Enums::PeptideIon::y)
61 return false;
62 return iona > ionb;
63 });
64
65 qDebug() << " fragmentIonList.size()=" << fragmentIonList.size();
66 std::vector<DataPoint> peak_list(spectrum.begin(), spectrum.end());
67 for(auto ion_type : ion_type_list)
68 {
69 const std::list<PeptideFragmentIonSp> peptide_fragment_ion_list =
70 fragmentIonList.getPeptideFragmentIonSp(ion_type);
71 qDebug() << " peptide_fragment_ion_list.size()=" << peptide_fragment_ion_list.size();
72
73 for(unsigned int charge = 1; charge <= parent_charge; charge++)
74 {
75 qDebug();
76 for(auto &&peptide_fragment_ion : peptide_fragment_ion_list)
77 {
78 qDebug() << "peptide_fragment_ion.get()->getMz(charge)="
79 << peptide_fragment_ion.get()->getMz(charge);
80 PeptideNaturalIsotopeList isotope_list(peptide_fragment_ion);
81 for(unsigned int isotope_number = 0; isotope_number <= max_isotope_number;
82 isotope_number++)
83 {
84 qDebug();
85 PeptideNaturalIsotopeAverage *p_isotopeIon;
86 if(max_isotope_rank == 0)
87 {
88 // fast constructor, no need to compute isotope ratio
89 p_isotopeIon = new PeptideNaturalIsotopeAverage(
90 peptide_fragment_ion, isotope_number, charge, precision);
91 }
92 else
93 {
94 p_isotopeIon = new PeptideNaturalIsotopeAverage(
95 isotope_list, max_isotope_rank, isotope_number, charge, precision);
96 }
97
98 qDebug() << "max_isotope_rank=" << max_isotope_rank
99 << " isotope_number=" << isotope_number << " charge=" << charge
100 << " precision=" << precision
101 << " p_isotopeIon->getMz()=" << p_isotopeIon->getMz() << " "
102 << isotope_number << " " << p_isotopeIon->toString();
103
104 std::vector<DataPoint>::iterator it_peak =
105 getBestPeakIterator(peak_list, *p_isotopeIon);
106 if(it_peak != peak_list.end())
107 {
108 _peak_ion_match_list.push_back(
109 PeakIonIsotopeMatch(*it_peak,
111 peptide_fragment_ion));
112 peak_list.erase(it_peak);
113
114 qDebug()
115 << isotope_number << " " << _peak_ion_match_list.back().toString();
116 }
117 delete p_isotopeIon;
118 }
119 }
120 }
121 }
122 }
123 catch(PappsoException &exception_pappso)
124 {
125 QString errorStr =
126 QObject::tr("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("ERROR building PeptideIsotopeSpectrumMatch, std exception:\n%1")
137 .arg(exception_std.what());
138 qDebug() << "PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch "
139 "std::exception :\n"
140 << errorStr;
141 throw PappsoException(errorStr);
142 }
143
144 qDebug() << "_peak_ion_match_list.size()=" << _peak_ion_match_list.size();
145}
146
148 const MassSpectrum &spectrum,
149 std::vector<PeptideNaturalIsotopeAverageSp> v_peptideIsotopeList,
150 std::vector<PeptideFragmentIonSp> v_peptideIonList,
151 PrecisionPtr precision)
152 : _precision(precision)
153{
154 qDebug() << " begin";
155 if(v_peptideIsotopeList.size() != v_peptideIonList.size())
156 {
157 throw PappsoException(
158 QObject::tr("v_peptideIsotopeList.size() %1 != v_peptideIonList.size() %2")
159 .arg(v_peptideIsotopeList.size())
160 .arg(v_peptideIonList.size()));
161 }
162
163 auto isotopeIt = v_peptideIsotopeList.begin();
164 auto ionIt = v_peptideIonList.begin();
165 std::vector<DataPoint> peak_list(spectrum.begin(), spectrum.end());
166
167 while(isotopeIt != v_peptideIsotopeList.end())
168 {
169 std::vector<DataPoint>::iterator it_peak =
170 getBestPeakIterator(peak_list, *(isotopeIt->get()));
171 if(it_peak != peak_list.end())
172 {
173 _peak_ion_match_list.push_back(PeakIonIsotopeMatch(*it_peak, *isotopeIt, *ionIt));
174 peak_list.erase(it_peak);
175 }
176 isotopeIt++;
177 ionIt++;
178 }
179 qDebug() << "_peak_ion_match_list.size()=" << _peak_ion_match_list.size() << " end";
180}
181
182
188
192
193
194std::vector<DataPoint>::iterator
195PeptideIsotopeSpectrumMatch::getBestPeakIterator(std::vector<DataPoint> &peak_list,
196 const PeptideNaturalIsotopeAverage &ion) const
197{
198 // qDebug();
199 std::vector<DataPoint>::iterator itpeak = peak_list.begin();
200 std::vector<DataPoint>::iterator itend = peak_list.end();
201 std::vector<DataPoint>::iterator itselect = peak_list.end();
202
203 pappso_double best_intensity = 0;
204
205 while(itpeak != itend)
206 {
207 // qDebug() << itpeak->x;
208 if(ion.matchPeak(itpeak->x))
209 {
210 if(itpeak->y > best_intensity)
211 {
212 best_intensity = itpeak->y;
213 itselect = itpeak;
214 }
215 }
216 itpeak++;
217 }
218 // qDebug();
219 return (itselect);
220}
221
222const std::list<PeakIonIsotopeMatch> &
224{
225 qDebug() << "_peak_ion_match_list.size()=" << _peak_ion_match_list.size();
227}
228
229std::size_t
231{
232 return _peak_ion_match_list.size();
233}
236{
237 return _peak_ion_match_list.begin();
238}
241{
242 return _peak_ion_match_list.end();
243}
244
245void
247{
248 qDebug();
250 if(a.getPeptideIonType() < b.getPeptideIonType())
251 return true;
252 if(a.getPeptideFragmentIonSp().get()->size() < b.getPeptideFragmentIonSp().get()->size())
253 return true;
254 if(a.getCharge() < b.getCharge())
255 return true;
256 if(a.getPeptideNaturalIsotopeAverageSp().get()->getIsotopeNumber() <
257 b.getPeptideNaturalIsotopeAverageSp().get()->getIsotopeNumber())
258 return true;
259 return false;
260 });
262 std::size_t nserie = 0;
263 std::size_t isotopeserie = 0;
264 unsigned int charge = 0;
265 for(std::list<PeakIonIsotopeMatch>::iterator it = _peak_ion_match_list.begin();
266 it != _peak_ion_match_list.end();
267 it++)
268 {
269 if((nserie != it->getPeptideFragmentIonSp().get()->size()) ||
270 (ion_type != it->getPeptideIonType()) || (charge != it->getCharge()))
271 {
272 ion_type = it->getPeptideIonType();
273 isotopeserie = 0;
274 nserie = it->getPeptideFragmentIonSp().get()->size();
275 charge = it->getCharge();
276 }
277 if(isotopeserie <= it->getPeptideNaturalIsotopeAverageSp().get()->getIsotopeNumber())
278 {
279 isotopeserie = it->getPeptideNaturalIsotopeAverageSp().get()->getIsotopeNumber();
280 }
281 else
282 {
283 it = _peak_ion_match_list.erase(it);
284 }
285 }
286 qDebug();
287}
288} // namespace pappso
Class to represent a mass spectrum.
virtual const QString & qwhat() const
const std::list< PeptideFragmentIonSp > getPeptideFragmentIonSp(Enums::PeptideIon ion_type) const
PeptideIsotopeSpectrumMatch(const MassSpectrum &spectrum, const PeptideSp &peptide_sp, unsigned int parent_charge, PrecisionPtr precision, const std::list< Enums::PeptideIon > &ion_type_list, unsigned int max_isotope_number, unsigned int max_isotope_rank)
annotate spectrum with peptide ions and isotopes
std::list< PeakIonIsotopeMatch >::const_iterator const_iterator
std::list< PeakIonIsotopeMatch > _peak_ion_match_list
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
PeptideIon
Enums::PeptideIon enum defines all types of ions (Nter or Cter)
Definition types.h:286
@ y
Cter amino ions.
Definition types.h:295
@ b
Nter acylium ions.
Definition types.h:287
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:61
const PrecisionBase * PrecisionPtr
Definition precision.h:122