libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
peptidenaturalisotopelist.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/peptide/peptidenaturalisotopelist.cpp
3 * \date 8/3/2015
4 * \author Olivier Langella
5 * \brief peptide natural isotope model
6 */
7
8/*******************************************************************************
9 * Copyright (c) 2015 Olivier Langella <Olivier.Langella@moulon.inra.fr>.
10 *
11 * This file is part of the PAPPSOms++ library.
12 *
13 * PAPPSOms++ is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * PAPPSOms++ is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
25 *
26 * Contributors:
27 * Olivier Langella <Olivier.Langella@moulon.inra.fr> - initial API and
28 *implementation
29 ******************************************************************************/
30// make test ARGS="-V -I 7,7"
31#include <QDebug>
34
35namespace pappso
36{
37
39 pappso_double minimum_ratio_to_compute)
40 : msp_peptide(peptide)
41{
42 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ << " "
43 // << minimum_ratio_to_compute;
44 int number_of_fixed_oxygen = msp_peptide.get()->getNumberOfIsotope(Enums::Isotope::O18) +
45 msp_peptide.get()->getNumberOfIsotope(Enums::Isotope::O17);
46 int number_of_fixed_sulfur = msp_peptide.get()->getNumberOfIsotope(Enums::Isotope::S33) +
47 msp_peptide.get()->getNumberOfIsotope(Enums::Isotope::S34) +
48 msp_peptide.get()->getNumberOfIsotope(Enums::Isotope::S36);
49 int number_of_fixed_nitrogen = msp_peptide.get()->getNumberOfIsotope(Enums::Isotope::N15);
50 int number_of_fixed_hydrogen = msp_peptide.get()->getNumberOfIsotope(Enums::Isotope::H2);
51
52 int total_carbon(msp_peptide.get()->getNumberOfAtom(Enums::AtomIsotopeSurvey::C) -
53 msp_peptide.get()->getNumberOfIsotope(Enums::Isotope::C13));
54
55 // qDebug() << "total_carbon " << total_carbon;
56 // qDebug() << "total_sulfur " << total_sulfur;
57 std::map<Enums::Isotope, int> map_isotope;
58 map_isotope.insert(std::pair<Enums::Isotope, int>(Enums::Isotope::C13, 0));
59 map_isotope.insert(std::pair<Enums::Isotope, int>(Enums::Isotope::H2, 0));
60 map_isotope.insert(std::pair<Enums::Isotope, int>(Enums::Isotope::N15, 0));
61 map_isotope.insert(std::pair<Enums::Isotope, int>(Enums::Isotope::O17, 0));
62 map_isotope.insert(std::pair<Enums::Isotope, int>(Enums::Isotope::O18, 0));
63 map_isotope.insert(std::pair<Enums::Isotope, int>(Enums::Isotope::S33, 0));
64 map_isotope.insert(std::pair<Enums::Isotope, int>(Enums::Isotope::S34, 0));
65 map_isotope.insert(std::pair<Enums::Isotope, int>(Enums::Isotope::S36, 0));
66
67 for(int nbc13 = 0; nbc13 <= total_carbon; nbc13++)
68 {
69 map_isotope[Enums::Isotope::C13] = nbc13;
70 PeptideNaturalIsotopeSp pepIsotope =
71 std::make_shared<PeptideNaturalIsotope>(msp_peptide, map_isotope);
72 this->msp_peptide_natural_isotope_list.push_back(pepIsotope);
73 if(pepIsotope.get()->getIntensityRatio(1) < minimum_ratio_to_compute)
74 {
75 break;
76 }
77 }
78 std::list<PeptideNaturalIsotopeSp> temp_list;
79
80 // ******************************************************************
81 // Sulfur isotope list
82 int total_sulfur(msp_peptide.get()->getNumberOfAtom(Enums::AtomIsotopeSurvey::S) -
83 number_of_fixed_sulfur);
84 std::list<PeptideNaturalIsotopeSp>::iterator it = msp_peptide_natural_isotope_list.begin();
85 while(it != msp_peptide_natural_isotope_list.end())
86 {
87 map_isotope = it->get()->getIsotopeMap();
88 for(int nbS34 = 1; nbS34 <= total_sulfur; nbS34++)
89 {
90 map_isotope[Enums::Isotope::S34] = nbS34;
91 PeptideNaturalIsotopeSp pepIsotope =
92 std::make_shared<PeptideNaturalIsotope>(msp_peptide, map_isotope);
93 temp_list.push_back(pepIsotope);
94 if(pepIsotope.get()->getIntensityRatio(1) < minimum_ratio_to_compute)
95 {
96 // qDebug() << "peptide " << pepIsotope.get()->getFormula(1) << "
97 // " << pepIsotope.get()->getIntensityRatio(1); it++;
98 break;
99 }
100 }
101 it++;
102 }
103 msp_peptide_natural_isotope_list.insert(it, temp_list.begin(), temp_list.end());
104
105 // compute S33 abundance
106 temp_list.resize(0);
107 it = msp_peptide_natural_isotope_list.begin();
108 while(it != msp_peptide_natural_isotope_list.end())
109 {
110 // qDebug() << "peptide S33 " << it->get()->getFormula(1) << " "
111 // <<it->get()->getIntensityRatio(1);
112 map_isotope = it->get()->getIsotopeMap();
113 for(int nbS33 = 1; nbS33 <= (total_sulfur - map_isotope[Enums::Isotope::S34]); nbS33++)
114 {
115 map_isotope[Enums::Isotope::S33] = nbS33;
116 PeptideNaturalIsotopeSp pepIsotopeS33 =
117 std::make_shared<PeptideNaturalIsotope>(msp_peptide, map_isotope);
118 temp_list.push_back(pepIsotopeS33);
119 if(pepIsotopeS33.get()->getIntensityRatio(1) < minimum_ratio_to_compute)
120 {
121 // it++;
122 break;
123 }
124 }
125 it++;
126 }
127 msp_peptide_natural_isotope_list.insert(it, temp_list.begin(), temp_list.end());
128
129 // compute S36 abundance
130 temp_list.resize(0);
131 it = msp_peptide_natural_isotope_list.begin();
132 while(it != msp_peptide_natural_isotope_list.end())
133 {
134 map_isotope = it->get()->getIsotopeMap();
135 for(int nbS36 = 1; nbS36 <= (total_sulfur - map_isotope[Enums::Isotope::S34] -
136 map_isotope[Enums::Isotope::S33]);
137 nbS36++)
138 {
139 map_isotope[Enums::Isotope::S36] = nbS36;
140 PeptideNaturalIsotopeSp pepIsotopeS36 =
141 std::make_shared<PeptideNaturalIsotope>(msp_peptide, map_isotope);
142 temp_list.push_back(pepIsotopeS36);
143 if(pepIsotopeS36.get()->getIntensityRatio(1) < minimum_ratio_to_compute)
144 {
145 // it++;
146 break;
147 }
148 }
149 it++;
150 }
151 msp_peptide_natural_isotope_list.insert(it, temp_list.begin(), temp_list.end());
152
153 // ******************************************************************
154
155
156 // ******************************************************************
157 // Hydrogen isotope list
158 temp_list.resize(0);
159 // qDebug() << "PeptideNaturalIsotopeList::PeptideNaturalIsotopeList
160 // total_hydrogen";
161 int total_hydrogen(msp_peptide.get()->getNumberOfAtom(Enums::AtomIsotopeSurvey::H) -
162 number_of_fixed_hydrogen);
163 it = msp_peptide_natural_isotope_list.begin();
164 while(it != msp_peptide_natural_isotope_list.end())
165 {
166 // qDebug() << "PeptideNaturalIsotopeList::PeptideNaturalIsotopeList
167 // getIsotopeMap " << it->getFormula(1) << " " <<
168 // msp_peptide_natural_isotope_list.size();
169 map_isotope = it->get()->getIsotopeMap();
170 for(int nbH2 = 1; nbH2 <= total_hydrogen; nbH2++)
171 {
172 map_isotope[Enums::Isotope::H2] = nbH2;
173 PeptideNaturalIsotopeSp pepIsotope =
174 std::make_shared<PeptideNaturalIsotope>(msp_peptide, map_isotope);
175 temp_list.push_back(pepIsotope);
176 if(pepIsotope.get()->getIntensityRatio(1) < minimum_ratio_to_compute)
177 {
178 // it++;
179 break;
180 }
181 }
182 it++;
183 }
184 msp_peptide_natural_isotope_list.insert(it, temp_list.begin(), temp_list.end());
185 // ******************************************************************
186
187
188 // ******************************************************************
189 // Oxygen isotope list
190 temp_list.resize(0);
191 // qDebug() << "PeptideNaturalIsotopeList::PeptideNaturalIsotopeList
192 // total_oxygen";
193 unsigned int total_oxygen(msp_peptide.get()->getNumberOfAtom(Enums::AtomIsotopeSurvey::O) -
194 number_of_fixed_oxygen);
195 it = msp_peptide_natural_isotope_list.begin();
196 while(it != msp_peptide_natural_isotope_list.end())
197 {
198 // qDebug() << "PeptideNaturalIsotopeList::PeptideNaturalIsotopeList
199 // getIsotopeMap " << it->getFormula(1) << " " <<
200 // msp_peptide_natural_isotope_list.size();
201 map_isotope = it->get()->getIsotopeMap();
202 for(unsigned int nbO18 = 1; nbO18 <= total_oxygen; nbO18++)
203 {
204 // qDebug() << "PeptideNaturalIsotopeList::PeptideNaturalIsotopeList
205 // nbO18 " << nbO18;
206 map_isotope[Enums::Isotope::O18] = nbO18;
207 PeptideNaturalIsotopeSp pepIsotope =
208 std::make_shared<PeptideNaturalIsotope>(msp_peptide, map_isotope);
209 temp_list.push_back(pepIsotope);
210 if(pepIsotope.get()->getIntensityRatio(1) < minimum_ratio_to_compute)
211 {
212 // it++;
213 break;
214 }
215 }
216 it++;
217 }
218 msp_peptide_natural_isotope_list.insert(it, temp_list.begin(), temp_list.end());
219 // ******************************************************************
220
221
222 // ******************************************************************
223 // Nitrogen isotope list
224 temp_list.resize(0);
225 // qDebug() << "PeptideNaturalIsotopeList::PeptideNaturalIsotopeList
226 // total_nitrogen";
227 unsigned int total_nitrogen(msp_peptide.get()->getNumberOfAtom(Enums::AtomIsotopeSurvey::N) -
228 number_of_fixed_nitrogen);
229 it = msp_peptide_natural_isotope_list.begin();
230 while(it != msp_peptide_natural_isotope_list.end())
231 {
232 // qDebug() << "PeptideNaturalIsotopeList::PeptideNaturalIsotopeList
233 // getIsotopeMap " << it->getFormula(1) << " " <<
234 // msp_peptide_natural_isotope_list.size();
235 map_isotope = it->get()->getIsotopeMap();
236 for(unsigned int nbN15 = 1; nbN15 <= total_nitrogen; nbN15++)
237 {
238 // qDebug() << "PeptideNaturalIsotopeList::PeptideNaturalIsotopeList
239 // nbN15 " << nbN15;
240 map_isotope[Enums::Isotope::N15] = nbN15;
241 PeptideNaturalIsotopeSp pepIsotope =
242 std::make_shared<PeptideNaturalIsotope>(msp_peptide, map_isotope);
243 temp_list.push_back(pepIsotope);
244 if(pepIsotope.get()->getIntensityRatio(1) < minimum_ratio_to_compute)
245 {
246 // it++;
247 break;
248 }
249 }
250 it++;
251 }
252 msp_peptide_natural_isotope_list.insert(it, temp_list.begin(), temp_list.end());
253 // ******************************************************************
254
255 // qDebug() << "PeptideNaturalIsotopeList::PeptideNaturalIsotopeList end
256 // size="<<msp_peptide_natural_isotope_list.size();
257}
258
261{
262 return std::make_shared<PeptideNaturalIsotopeList>(*this);
263}
264
270
274
275const std::map<unsigned int, pappso_double>
277{
278 std::list<PeptideNaturalIsotopeSp>::const_iterator it = msp_peptide_natural_isotope_list.begin();
279 std::map<unsigned int, pappso_double> map_isotope_number;
280
281 while(it != msp_peptide_natural_isotope_list.end())
282 {
283 unsigned int number = it->get()->getIsotopeNumber();
284 std::pair<std::map<unsigned int, pappso_double>::iterator, bool> mapnew =
285 map_isotope_number.insert(std::pair<unsigned int, pappso_double>(number, 0));
286 if(mapnew.second == false)
287 {
288 // mapit = map_isotope_number.insert(std::pair<unsigned
289 // int,pappso_double>(number, 0));
290 }
291 mapnew.first->second += it->get()->getIntensityRatio(1);
292 it++;
293 }
294 return map_isotope_number;
295}
296
297
298/** /brief get a sorted (by expected intensity) vector of isotopes of the same
299 * level
300 *
301 * */
302
303std::vector<PeptideNaturalIsotopeSp>
305 unsigned int charge) const
306{
307 std::vector<PeptideNaturalIsotopeSp> v_isotope_list;
308
309 for(auto &&isotopeSp : msp_peptide_natural_isotope_list)
310 {
311 if(isotopeSp.get()->getIsotopeNumber() == isotope_number)
312 {
313 v_isotope_list.push_back(isotopeSp);
314 }
315 }
316 std::sort(v_isotope_list.begin(),
317 v_isotope_list.end(),
318 [charge](const PeptideNaturalIsotopeSp &m, const PeptideNaturalIsotopeSp &n) {
319 return (m.get()->getIntensityRatio(charge) > n.get()->getIntensityRatio(charge));
320 });
321 return v_isotope_list;
322}
323
324
325/** /brief get a sorted (by expected intensity) vector of natural isotope
326 * average by isotope number
327 *
328 * */
329std::vector<PeptideNaturalIsotopeAverageSp>
331 unsigned int charge,
332 PrecisionPtr precision,
333 unsigned int isotopeNumber,
334 pappso_double minimumIntensity)
335{
336
337 // qDebug() << "getByIntensityRatioByIsotopeNumber begin";
338 unsigned int askedIsotopeRank;
339 unsigned int maxAskedIsotopeRank = 10;
340 pappso_double cumulativeRatio = 0;
341 std::vector<PeptideNaturalIsotopeAverageSp> v_isotopeAverageList;
342 std::vector<PeptideNaturalIsotopeAverageSp> v_isotopeAverageListResult;
343
344 std::vector<unsigned int> previousIsotopeRank;
345 bool isEmpty = false;
346 for(askedIsotopeRank = 1; (askedIsotopeRank < maxAskedIsotopeRank) && (!isEmpty);
347 askedIsotopeRank++)
348 {
349 PeptideNaturalIsotopeAverage isotopeAverage(
350 peptide, askedIsotopeRank, isotopeNumber, charge, precision);
351 isEmpty = isotopeAverage.isEmpty();
352 if(isEmpty)
353 {
354 }
355 else
356 {
357 if(std::find(previousIsotopeRank.begin(),
358 previousIsotopeRank.end(),
359 isotopeAverage.getIsotopeRank()) == previousIsotopeRank.end())
360 { // not Found
361 previousIsotopeRank.push_back(isotopeAverage.getIsotopeRank());
362 v_isotopeAverageList.push_back(isotopeAverage.makePeptideNaturalIsotopeAverageSp());
363 }
364 }
365 }
366 if(v_isotopeAverageList.size() == 0)
367 return v_isotopeAverageListResult;
368
369 // qDebug() << "getByIntensityRatioByIsotopeNumber comp";
370 std::sort(v_isotopeAverageList.begin(),
371 v_isotopeAverageList.end(),
373 return (m.get()->getIntensityRatio() > n.get()->getIntensityRatio());
374 });
375
376 cumulativeRatio = 0;
377 auto it = v_isotopeAverageList.begin();
378 v_isotopeAverageListResult.clear();
379 // qDebug() << "getByIntensityRatioByIsotopeNumber cumul";
380 while((it != v_isotopeAverageList.end()) && (cumulativeRatio < minimumIntensity))
381 {
382 cumulativeRatio += it->get()->getIntensityRatio();
383 v_isotopeAverageListResult.push_back(*it);
384 it++;
385 }
386
387 // qDebug() << "getByIntensityRatioByIsotopeNumber end";
388
389 return v_isotopeAverageListResult;
390}
391
392
393/** /brief get a sorted (by expected intensity) vector of natural isotope
394 * average
395 *
396 * */
397std::vector<PeptideNaturalIsotopeAverageSp>
399 PrecisionPtr precision,
400 pappso_double minimumIntensityRatio) const
401{
402
403 // qDebug() << "PeptideNaturalIsotopeList::getByIntensityRatio begin";
404 std::vector<PeptideNaturalIsotopeAverageSp> peptide_natural_isotope_average_list;
405
406 std::map<unsigned int, pappso::pappso_double> map_isotope_number =
408 std::vector<std::pair<unsigned int, pappso::pappso_double>> sorted_number_ratio;
409
410 for(unsigned int i = 0; i < map_isotope_number.size(); i++)
411 {
412 sorted_number_ratio.push_back(
413 std::pair<unsigned int, pappso::pappso_double>(i, map_isotope_number[i]));
414 unsigned int asked_rank = 0;
415 unsigned int given_rank = 0;
416 bool more_rank = true;
417 while(more_rank)
418 {
419 asked_rank++;
420 pappso::PeptideNaturalIsotopeAverage isotopeAverageMono(
421 *this, asked_rank, i, charge, precision);
422 given_rank = isotopeAverageMono.getIsotopeRank();
423 if(given_rank < asked_rank)
424 {
425 more_rank = false;
426 }
427 else if(isotopeAverageMono.getIntensityRatio() == 0)
428 {
429 more_rank = false;
430 }
431 else
432 {
433 // isotopeAverageMono.makePeptideNaturalIsotopeAverageSp();
434 peptide_natural_isotope_average_list.push_back(
435 isotopeAverageMono.makePeptideNaturalIsotopeAverageSp());
436 }
437 }
438 }
439
440
441 // sort by intensity ratio
442 std::sort(
443 sorted_number_ratio.begin(),
444 sorted_number_ratio.end(),
445 [](const std::pair<unsigned int, pappso::pappso_double> &m,
446 const std::pair<unsigned int, pappso::pappso_double> &n) { return (m.second > n.second); });
447
448
449 double cumulativeRatio = 0;
450 std::vector<unsigned int> selected_isotope_number_list;
451 for(auto &pair_isotope_number : sorted_number_ratio)
452 {
453 if(cumulativeRatio <= minimumIntensityRatio)
454 {
455 selected_isotope_number_list.push_back(pair_isotope_number.first);
456 }
457 else
458 {
459 break;
460 }
461 cumulativeRatio += pair_isotope_number.second;
462 }
463
464 auto it_remove =
465 std::remove_if(peptide_natural_isotope_average_list.begin(),
466 peptide_natural_isotope_average_list.end(),
467 [selected_isotope_number_list](const PeptideNaturalIsotopeAverageSp &average) {
468 auto it = std::find(selected_isotope_number_list.begin(),
469 selected_isotope_number_list.end(),
470 average.get()->getIsotopeNumber());
471 return (it == selected_isotope_number_list.end());
472 });
473 peptide_natural_isotope_average_list.erase(it_remove, peptide_natural_isotope_average_list.end());
474 return peptide_natural_isotope_average_list;
475}
476
477
483
489
490unsigned int
495
496const PeptideInterfaceSp &
501} // namespace pappso
PeptideNaturalIsotopeAverageSp makePeptideNaturalIsotopeAverageSp() const
const PeptideInterfaceSp & getPeptideInterfaceSp() const
PeptideNaturalIsotopeList(const PeptideInterfaceSp &peptide, pappso_double minimum_ratio_to_compute=0.001)
compute the list of possible isotopes for a peptide
std::list< PeptideNaturalIsotopeSp >::const_iterator const_iterator
PeptideNaturalIsotopeListSp makePeptideNaturalIsotopeListSp() const
std::vector< PeptideNaturalIsotopeAverageSp > getByIntensityRatio(unsigned int charge, PrecisionPtr precision, pappso_double minimum_isotope_pattern_ratio) const
get the list of natural isotopes representing at least a minimum ratio of the whole isotope pattern
std::list< PeptideNaturalIsotopeSp > msp_peptide_natural_isotope_list
const std::map< unsigned int, pappso_double > getIntensityRatioPerIsotopeNumber() const
std::vector< PeptideNaturalIsotopeSp > getByIsotopeNumber(unsigned int isotopeLevel, unsigned int charge) const
pappso_double getIntensityRatio(unsigned int charge) const
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
std::shared_ptr< const PeptideNaturalIsotope > PeptideNaturalIsotopeSp
std::vector< PeptideNaturalIsotopeAverageSp > getByIntensityRatioByIsotopeNumber(const PeptideInterfaceSp &peptide, unsigned int charge, PrecisionPtr precision, unsigned int isotopeNumber, pappso_double minimumIntensity)
std::shared_ptr< const PeptideInterface > PeptideInterfaceSp
double pappso_double
A type definition for doubles.
Definition types.h:60
std::shared_ptr< const PeptideNaturalIsotopeAverage > PeptideNaturalIsotopeAverageSp
const PrecisionBase * PrecisionPtr
Definition precision.h:122
std::shared_ptr< const PeptideNaturalIsotopeList > PeptideNaturalIsotopeListSp