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"
36#include "../pappsoexception.h"
37#include "../peptide/peptidefragment.h"
38#include "../peptide/peptidefragmentionlistbase.h"
39
40namespace pappso
41{
42
43
44void
46 const MassSpectrum &spectrum,
47 const PeptideFragmentIonListBase &fragmentIonList,
48 unsigned int max_charge,
49 const std::list<PeptideIon> &ion_type_list)
50{
51
52 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
53 // << " ion_type_list.size()=" << ion_type_list.size();
54 std::list<DataPoint> peak_list(spectrum.begin(), spectrum.end());
55 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
56 // << " peak_list.size()=" << peak_list.size();
57
58 for(auto ion_type : ion_type_list)
59 {
60 auto ion_list = fragmentIonList.getPeptideFragmentIonSp(ion_type);
61 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
62 // << " ion_list.size()=" << ion_list.size();
63 for(unsigned int charge = 1; charge <= max_charge; charge++)
64 {
65 for(auto &&ion : ion_list)
66 {
67 std::list<DataPoint>::iterator it_peak =
68 getBestPeakIterator(peak_list, ion, charge);
69
70 if(it_peak != peak_list.end())
71 {
72
73 // qDebug() << __FILE__ << " " << __FUNCTION__ << " " <<
74 // __LINE__
75 // << " peak FOUND";
76 _peak_ion_match_list.push_back(
77 PeakIonMatch(*it_peak, ion, charge));
78 _ion_type_count[(std::int8_t)ion->getPeptideIonType()]++;
79 peak_list.erase(it_peak);
80 }
81 }
82 }
83 }
84}
85
87 const MassSpectrum &spectrum,
88 std::vector<PeptideFragmentIonSp> &v_peptide_fragment_ion,
89 std::vector<unsigned int> &v_peptide_fragment_ion_charge,
90 PrecisionPtr precision)
91 : _precision(precision)
92{
93 qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
94 // throw PappsoException(QObject::tr("v_peptideIsotopeList.size() %1 !=
95 // v_peptideIonList.size()
96 // %2").arg(v_peptideIsotopeList.size()).arg(v_peptideIonList.size()));
97 if(v_peptide_fragment_ion.size() != v_peptide_fragment_ion_charge.size())
98 {
99 throw PappsoException(
100 QObject::tr("v_peptide_fragment_ion.size() != "
101 "v_peptide_fragment_ion_charge.size() %2")
102 .arg(v_peptide_fragment_ion.size())
103 .arg(v_peptide_fragment_ion_charge.size()));
104 }
105
106
107 auto ionIt = v_peptide_fragment_ion.begin();
108 auto chargeIt = v_peptide_fragment_ion_charge.begin();
109 std::list<DataPoint> peak_list(spectrum.begin(), spectrum.end());
110
111 while(ionIt != v_peptide_fragment_ion.end())
112 {
113 std::list<DataPoint>::iterator it_peak =
114 getBestPeakIterator(peak_list, *ionIt, *chargeIt);
115 if(it_peak != peak_list.end())
116 {
117 _peak_ion_match_list.push_back(
118 PeakIonMatch(*it_peak, *ionIt, *chargeIt));
119 _ion_type_count[(std::int8_t)ionIt->get()->getPeptideIonType()]++;
120 peak_list.erase(it_peak);
121 }
122
123 ionIt++;
124 chargeIt++;
125 }
126 qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
127 << " _ion_type_count[PeptideIon::y]="
128 << _ion_type_count[(std::int8_t)PeptideIon::y];
129}
130
131
133 const MassSpectrum &spectrum,
134 const PeptideFragmentIonListBase &fragmentIonList,
135 unsigned int max_charge,
136 PrecisionPtr precision,
137 const std::list<PeptideIon> &ion_type_list)
138 : _precision(precision)
139{
140 privMatchIonList(spectrum, fragmentIonList, max_charge, ion_type_list);
141 qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
142 << " _ion_type_count[PeptideIon::y]="
143 << _ion_type_count[(std::int8_t)PeptideIon::y];
144}
145
147 const MassSpectrum &spectrum,
148 const pappso::PeptideSp &peptideSp,
149 unsigned int parent_charge,
150 PrecisionPtr precision,
151 const std::list<PeptideIon> &ion_type_list)
152 : _precision(precision)
153{
154 PeptideFragmentIonListBase fragmentIonList(peptideSp, ion_type_list);
155 privMatchIonList(spectrum, fragmentIonList, parent_charge, ion_type_list);
156 qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
157 << " _ion_type_count[PeptideIon::y]="
158 << _ion_type_count[(std::int8_t)PeptideIon::y];
159}
160
161
163 : _precision(other._precision),
164 _peak_ion_match_list(other._peak_ion_match_list)
165{
166}
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
238 unsigned int z) const
239{
240 auto it = _peak_ion_match_list.begin();
241 while(it != _peak_ion_match_list.end())
242 {
243 const PeakIonMatch &ref = *it;
244 if((ref.getCharge() == z) &&
245 (ref.getPeptideFragmentIonSp().get() == peptideFragmentIonSp))
246 {
247 return true;
248 }
249 it++;
250 }
251 return false;
252}
253} // namespace pappso
Class to represent a mass spectrum.
virtual const PeptideFragmentIonSp & getPeptideFragmentIonSp() const
unsigned int getCharge() const
const std::list< PeptideFragmentIonSp > getPeptideFragmentIonSp(PeptideIon ion_type) const
virtual std::list< DataPoint >::iterator getBestPeakIterator(std::list< DataPoint > &peak_list, const PeptideFragmentIonSp &ion, unsigned int charge) const
void privMatchIonList(const MassSpectrum &spectrum, const PeptideFragmentIonListBase &fragmentIonList, unsigned int max_charge, const std::list< PeptideIon > &ion_type_list)
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
PeptideSpectrumMatch(const MassSpectrum &spectrum, const pappso::PeptideSp &peptideSp, unsigned int parent_charge, PrecisionPtr precision, const std::list< PeptideIon > &ion_type_list)
const std::array< unsigned int, PEPTIDE_ION_TYPE_COUNT > & getIonTypeCountArray() const
std::list< PeakIonMatch >::const_iterator const_iterator
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
@ y
Cter amino ions.
std::shared_ptr< const PeptideFragmentIon > PeptideFragmentIonSp
std::shared_ptr< const Peptide > PeptideSp
double pappso_double
A type definition for doubles.
Definition types.h:50
associate a peak and a peptide + charge
find peaks matching between ions and spectrum