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