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
28namespace pappso
29{
31 const MassSpectrum &spectrum,
32 const PeptideSp &peptideSp,
33 unsigned int parent_charge,
34 PrecisionPtr precision,
35 const 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 {
44 qDebug() << "PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch "
45 "begin max_isotope_number="
46 << max_isotope_number;
47 PeptideFragmentIonListBase fragmentIonList(peptideSp, ion_type_list);
48 qDebug() << "PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch "
49 "peak_list spectrum.size="
50 << spectrum.size();
51 std::vector<DataPoint> peak_list(spectrum.begin(), spectrum.end());
52 for(auto ion_type : ion_type_list)
53 {
54 auto ion_list = fragmentIonList.getPeptideFragmentIonSp(ion_type);
55
56 for(unsigned int charge = 1; charge <= parent_charge; charge++)
57 {
58 for(auto &&ion : ion_list)
59 {
60 unsigned int askedIsotopeRank = 1;
61 for(unsigned int isotope_number = 0;
62 isotope_number <= max_isotope_number;
63 isotope_number++)
64 {
66 ion, isotope_number, charge, precision);
67
68 qDebug()
69 << isotope_number << " " << isotopeIon.toString();
70
71 std::vector<DataPoint>::iterator it_peak =
72 getBestPeakIterator(peak_list, isotopeIon);
73 if(it_peak != peak_list.end())
74 {
76 *it_peak,
78 ion));
79 peak_list.erase(it_peak);
80
81 qDebug() << isotope_number << " "
82 << _peak_ion_match_list.back().toString();
83 }
84 }
85 }
86 }
87 }
88 }
89 catch(PappsoException &exception_pappso)
90 {
91 QString errorStr =
92 QObject::tr(
93 "ERROR building PeptideIsotopeSpectrumMatch, PAPPSO exception:\n%1")
94 .arg(exception_pappso.qwhat());
95 qDebug() << "PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch "
96 "PappsoException :\n"
97 << errorStr;
98 throw PappsoException(errorStr);
99 }
100 catch(std::exception &exception_std)
101 {
102 QString errorStr =
103 QObject::tr(
104 "ERROR building PeptideIsotopeSpectrumMatch, std exception:\n%1")
105 .arg(exception_std.what());
106 qDebug() << "PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch "
107 "std::exception :\n"
108 << errorStr;
109 throw PappsoException(errorStr);
110 }
111}
112
114 const MassSpectrum &spectrum,
115 std::vector<PeptideNaturalIsotopeAverageSp> v_peptideIsotopeList,
116 std::vector<PeptideFragmentIonSp> v_peptideIonList,
117 PrecisionPtr precision)
118 : _precision(precision)
119{
120 qDebug() << " begin";
121 if(v_peptideIsotopeList.size() != v_peptideIonList.size())
122 {
123 throw PappsoException(
124 QObject::tr(
125 "v_peptideIsotopeList.size() %1 != v_peptideIonList.size() %2")
126 .arg(v_peptideIsotopeList.size())
127 .arg(v_peptideIonList.size()));
128 }
129
130 auto isotopeIt = v_peptideIsotopeList.begin();
131 auto ionIt = v_peptideIonList.begin();
132 std::vector<DataPoint> peak_list(spectrum.begin(), spectrum.end());
133
134 while(isotopeIt != v_peptideIsotopeList.end())
135 {
136 std::vector<DataPoint>::iterator it_peak =
137 getBestPeakIterator(peak_list, *(isotopeIt->get()));
138 if(it_peak != peak_list.end())
139 {
140 _peak_ion_match_list.push_back(
141 PeakIonIsotopeMatch(*it_peak, *isotopeIt, *ionIt));
142 peak_list.erase(it_peak);
143 }
144 isotopeIt++;
145 ionIt++;
146 }
147 qDebug() << " end";
148}
149
150
152 const PeptideIsotopeSpectrumMatch &other)
153 : _precision(other._precision),
154 _peak_ion_match_list(other._peak_ion_match_list)
155{
156 qDebug();
157}
158
160{
161}
162
163
164std::vector<DataPoint>::iterator
166 std::vector<DataPoint> &peak_list,
167 const PeptideNaturalIsotopeAverage &ion) const
168{
169 // qDebug();
170 std::vector<DataPoint>::iterator itpeak = peak_list.begin();
171 std::vector<DataPoint>::iterator itend = peak_list.end();
172 std::vector<DataPoint>::iterator itselect = peak_list.end();
173
174 pappso_double best_intensity = 0;
175
176 while(itpeak != itend)
177 {
178 if(ion.matchPeak(itpeak->x))
179 {
180 if(itpeak->y > best_intensity)
181 {
182 best_intensity = itpeak->y;
183 itselect = itpeak;
184 }
185 }
186 itpeak++;
187 }
188 // qDebug();
189 return (itselect);
190}
191
192const std::list<PeakIonIsotopeMatch> &
194{
196}
197
198std::size_t
200{
201 return _peak_ion_match_list.size();
202}
205{
206 return _peak_ion_match_list.begin();
207}
210{
211 return _peak_ion_match_list.end();
212}
213
214void
216{
217 qDebug();
219 [](const PeakIonIsotopeMatch &a, const PeakIonIsotopeMatch &b) {
220 if(a.getPeptideIonType() < b.getPeptideIonType())
221 return true;
222 if(a.getPeptideFragmentIonSp().get()->size() <
223 b.getPeptideFragmentIonSp().get()->size())
224 return true;
225 if(a.getCharge() < b.getCharge())
226 return true;
227 if(a.getPeptideNaturalIsotopeAverageSp().get()->getIsotopeNumber() <
228 b.getPeptideNaturalIsotopeAverageSp().get()->getIsotopeNumber())
229 return true;
230 return false;
231 });
232 PeptideIon ion_type = PeptideIon::b;
233 std::size_t nserie = 0;
234 std::size_t isotopeserie = 0;
235 unsigned int charge = 0;
236 for(std::list<PeakIonIsotopeMatch>::iterator it =
237 _peak_ion_match_list.begin();
238 it != _peak_ion_match_list.end();
239 it++)
240 {
241 if((nserie != it->getPeptideFragmentIonSp().get()->size()) ||
242 (ion_type != it->getPeptideIonType()) || (charge != it->getCharge()))
243 {
244 ion_type = it->getPeptideIonType();
245 isotopeserie = 0;
246 nserie = it->getPeptideFragmentIonSp().get()->size();
247 charge = it->getCharge();
248 }
249 if(isotopeserie <=
250 it->getPeptideNaturalIsotopeAverageSp().get()->getIsotopeNumber())
251 {
252 isotopeserie =
253 it->getPeptideNaturalIsotopeAverageSp().get()->getIsotopeNumber();
254 }
255 else
256 {
257 it = _peak_ion_match_list.erase(it);
258 }
259 }
260 qDebug();
261}
262} // namespace pappso
Class to represent a mass spectrum.
Definition: massspectrum.h:71
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:385
@ b
Nter acylium ions.
std::shared_ptr< const Peptide > PeptideSp
double pappso_double
A type definition for doubles.
Definition: types.h:48