libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
peptidespectrummatch.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/psm/peptidespectrummatch.cpp
3 * \date 2/4/2015
4 * \author Olivier Langella
5 * \brief find peaks matching between ions and spectrum
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
31
32#include <list>
33#include <numeric>
34#include "peakionmatch.h"
39
40namespace pappso
41{
42
43
44void
46 const PeptideFragmentIonListBase &fragmentIonList,
47 unsigned int max_charge,
48 const std::list<Enums::PeptideIon> &ion_type_list_in)
49{
50
51 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
52 // << " ion_type_list.size()=" << ion_type_list.size();
53 std::list<DataPoint> peak_list(spectrum.begin(), spectrum.end());
54 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
55 // << " peak_list.size()=" << peak_list.size();
56 std::list<Enums::PeptideIon> ion_type_list(ion_type_list_in);
57
58 ion_type_list.sort([](const Enums::PeptideIon &iona, const Enums::PeptideIon &ionb) {
59 if(iona == Enums::PeptideIon::b)
60 return true;
61 if(ionb == Enums::PeptideIon::b)
62 return false;
63 if(iona == Enums::PeptideIon::y)
64 return true;
65 if(ionb == Enums::PeptideIon::y)
66 return false;
67 return iona > ionb;
68 });
69 for(auto ion_type : ion_type_list)
70 {
71 auto ion_list = fragmentIonList.getPeptideFragmentIonSp(ion_type);
72 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
73 // << " ion_list.size()=" << ion_list.size();
74 for(unsigned int charge = 1; charge <= max_charge; charge++)
75 {
76 for(auto &&ion : ion_list)
77 {
78 std::list<DataPoint>::iterator it_peak = getBestPeakIterator(peak_list, ion, charge);
79
80 if(it_peak != peak_list.end())
81 {
82
83 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " <<
84 // __LINE__
85 // << " peak FOUND";
86 _peak_ion_match_list.push_back(PeakIonMatch(*it_peak, ion, charge));
87 _ion_type_count[(std::int8_t)ion->getPeptideIonType()]++;
88 peak_list.erase(it_peak);
89 }
90 }
91 }
92 }
93}
94
96 const MassSpectrum &spectrum,
97 std::vector<PeptideFragmentIonSp> &v_peptide_fragment_ion,
98 std::vector<unsigned int> &v_peptide_fragment_ion_charge,
99 PrecisionPtr precision)
100 : _precision(precision)
101{
102 qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
103 // throw PappsoException(QObject::tr("v_peptideIsotopeList.size() %1 !=
104 // v_peptideIonList.size()
105 // %2").arg(v_peptideIsotopeList.size()).arg(v_peptideIonList.size()));
106 if(v_peptide_fragment_ion.size() != v_peptide_fragment_ion_charge.size())
107 {
108 throw PappsoException(QObject::tr("v_peptide_fragment_ion.size() != "
109 "v_peptide_fragment_ion_charge.size() %2")
110 .arg(v_peptide_fragment_ion.size())
111 .arg(v_peptide_fragment_ion_charge.size()));
112 }
113
114
115 auto ionIt = v_peptide_fragment_ion.begin();
116 auto chargeIt = v_peptide_fragment_ion_charge.begin();
117 std::list<DataPoint> peak_list(spectrum.begin(), spectrum.end());
118
119 while(ionIt != v_peptide_fragment_ion.end())
120 {
121 std::list<DataPoint>::iterator it_peak = getBestPeakIterator(peak_list, *ionIt, *chargeIt);
122 if(it_peak != peak_list.end())
123 {
124 _peak_ion_match_list.push_back(PeakIonMatch(*it_peak, *ionIt, *chargeIt));
125 _ion_type_count[(std::int8_t)ionIt->get()->getPeptideIonType()]++;
126 peak_list.erase(it_peak);
127 }
128
129 ionIt++;
130 chargeIt++;
131 }
132 qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
133 << " _ion_type_count[PeptideIon::y]=" << _ion_type_count[(std::int8_t)Enums::PeptideIon::y];
134}
135
136
138 const PeptideFragmentIonListBase &fragmentIonList,
139 unsigned int max_charge,
140 PrecisionPtr precision,
141 const std::list<Enums::PeptideIon> &ion_type_list)
142 : _precision(precision)
143{
144 privMatchIonList(spectrum, fragmentIonList, max_charge, ion_type_list);
145 qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
146 << " _ion_type_count[PeptideIon::y]=" << _ion_type_count[(std::int8_t)Enums::PeptideIon::y];
147}
148
150 const pappso::PeptideSp &peptideSp,
151 unsigned int parent_charge,
152 PrecisionPtr precision,
153 const std::list<Enums::PeptideIon> &ion_type_list)
154 : _precision(precision)
155{
156 PeptideFragmentIonListBase fragmentIonList(peptideSp, ion_type_list);
157 privMatchIonList(spectrum, fragmentIonList, parent_charge, ion_type_list);
158 qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
159 << " _ion_type_count[PeptideIon::y]=" << _ion_type_count[(std::int8_t)Enums::PeptideIon::y];
160}
161
162
167
168std::list<DataPoint>::iterator
169PeptideSpectrumMatch::getBestPeakIterator(std::list<DataPoint> &peak_list,
170 const PeptideFragmentIonSp &ion,
171 unsigned int charge) const
172{
173 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
174 // << " peak_list.size()=" << peak_list.size();
175 std::list<DataPoint>::iterator itpeak = peak_list.begin();
176 std::list<DataPoint>::iterator itend = peak_list.end();
177 std::list<DataPoint>::iterator itselect = peak_list.end();
178
179 pappso_double best_intensity = 0;
180
181 while(itpeak != itend)
182 {
183
184 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
185 // << " itpeak->x=" << itpeak->x;
186 if(ion.get()->matchPeak(_precision, itpeak->x, charge))
187 {
188 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
189 // << " ion.get()->matchPeak";
190 if(itpeak->y > best_intensity)
191 {
192 best_intensity = itpeak->y;
193 itselect = itpeak;
194 }
195 }
196 itpeak++;
197 }
198
199 return (itselect);
200}
201
205
206
207unsigned int
209{
210 return _peak_ion_match_list.size();
211}
212
215{
216 return _peak_ion_match_list.begin();
217}
220{
221 return _peak_ion_match_list.end();
222}
223
224unsigned int
226{
227 return std::accumulate(_ion_type_count.begin(), _ion_type_count.end(), 0);
228}
229
230const std::array<unsigned int, PEPTIDE_ION_TYPE_COUNT> &
235
236bool
237PeptideSpectrumMatch::contains(const PeptideFragmentIon *peptideFragmentIonSp, unsigned int z) const
238{
239 auto it = _peak_ion_match_list.begin();
240 while(it != _peak_ion_match_list.end())
241 {
242 const PeakIonMatch &ref = *it;
243 if((ref.getCharge() == z) && (ref.getPeptideFragmentIonSp().get() == peptideFragmentIonSp))
244 {
245 return true;
246 }
247 it++;
248 }
249 return false;
250}
251} // namespace pappso
Class to represent a mass spectrum.
virtual const PeptideFragmentIonSp & getPeptideFragmentIonSp() const
unsigned int getCharge() const
const std::list< PeptideFragmentIonSp > getPeptideFragmentIonSp(Enums::PeptideIon ion_type) const
virtual std::list< DataPoint >::iterator getBestPeakIterator(std::list< DataPoint > &peak_list, const PeptideFragmentIonSp &ion, unsigned int charge) const
bool contains(const PeptideFragmentIon *peptideFragmentIonSp, unsigned int z) const
std::array< unsigned int, PEPTIDE_ION_TYPE_COUNT > _ion_type_count
unsigned int countTotalMatchedIons() const
std::list< PeakIonMatch > _peak_ion_match_list
const std::array< unsigned int, PEPTIDE_ION_TYPE_COUNT > & getIonTypeCountArray() const
PeptideSpectrumMatch(const MassSpectrum &spectrum, const pappso::PeptideSp &peptideSp, unsigned int parent_charge, PrecisionPtr precision, const std::list< Enums::PeptideIon > &ion_type_list)
std::list< PeakIonMatch >::const_iterator const_iterator
void privMatchIonList(const MassSpectrum &spectrum, const PeptideFragmentIonListBase &fragmentIonList, unsigned int max_charge, const std::list< Enums::PeptideIon > &ion_type_list)
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 PeptideFragmentIon > PeptideFragmentIonSp
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