libpappsomspp
Library for mass spectrometry
Toggle main menu visibility
Loading...
Searching...
No Matches
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
26
#include "
peptideisotopespectrummatch.h
"
27
#include "
../peptide/peptidenaturalisotopelist.h
"
28
29
namespace
pappso
30
{
31
PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch
(
32
const
MassSpectrum
&spectrum,
33
const
PeptideSp
&peptideSp,
34
unsigned
int
parent_charge,
35
PrecisionPtr
precision,
36
const
std::list<Enums::PeptideIon> &ion_type_list_in,
37
unsigned
int
max_isotope_number,
38
[[maybe_unused]]
unsigned
int
max_isotope_rank)
39
:
_precision
(precision)
40
{
41
42
try
43
{
44
_peak_ion_match_list
.clear();
45
qDebug() <<
"peptideSp.get()->getSequence()="
<< peptideSp.get()->getSequence()
46
<<
" max_isotope_number="
<< max_isotope_number
47
<<
" spectrum.size="
<< spectrum.size() <<
" parent_charge="
<< parent_charge
48
<<
" ion_type_list.size="
<< ion_type_list_in.size()
49
<<
" max_isotope_rank="
<< max_isotope_rank;
50
PeptideFragmentIonListBase
fragmentIonList(peptideSp, ion_type_list_in);
51
std::list<Enums::PeptideIon> ion_type_list(ion_type_list_in);
52
53
ion_type_list.sort([](
const
Enums::PeptideIon
&iona,
const
Enums::PeptideIon
&ionb) {
54
if
(iona ==
Enums::PeptideIon::b
)
55
return
true
;
56
if
(ionb ==
Enums::PeptideIon::b
)
57
return
false
;
58
if
(iona ==
Enums::PeptideIon::y
)
59
return
true
;
60
if
(ionb ==
Enums::PeptideIon::y
)
61
return
false
;
62
return
iona > ionb;
63
});
64
65
qDebug() <<
" fragmentIonList.size()="
<< fragmentIonList.
size
();
66
std::vector<DataPoint> peak_list(spectrum.begin(), spectrum.end());
67
for
(
auto
ion_type : ion_type_list)
68
{
69
const
std::list<PeptideFragmentIonSp> peptide_fragment_ion_list =
70
fragmentIonList.
getPeptideFragmentIonSp
(ion_type);
71
qDebug() <<
" peptide_fragment_ion_list.size()="
<< peptide_fragment_ion_list.size();
72
73
for
(
unsigned
int
charge = 1; charge <= parent_charge; charge++)
74
{
75
qDebug();
76
for
(
auto
&&peptide_fragment_ion : peptide_fragment_ion_list)
77
{
78
qDebug() <<
"peptide_fragment_ion.get()->getMz(charge)="
79
<< peptide_fragment_ion.get()->getMz(charge);
80
PeptideNaturalIsotopeList
isotope_list(peptide_fragment_ion);
81
for
(
unsigned
int
isotope_number = 0; isotope_number <= max_isotope_number;
82
isotope_number++)
83
{
84
qDebug();
85
PeptideNaturalIsotopeAverage
*p_isotopeIon;
86
if
(max_isotope_rank == 0)
87
{
88
// fast constructor, no need to compute isotope ratio
89
p_isotopeIon =
new
PeptideNaturalIsotopeAverage
(
90
peptide_fragment_ion, isotope_number, charge, precision);
91
}
92
else
93
{
94
p_isotopeIon =
new
PeptideNaturalIsotopeAverage
(
95
isotope_list, max_isotope_rank, isotope_number, charge, precision);
96
}
97
98
qDebug() <<
"max_isotope_rank="
<< max_isotope_rank
99
<<
" isotope_number="
<< isotope_number <<
" charge="
<< charge
100
<<
" precision="
<< precision
101
<<
" p_isotopeIon->getMz()="
<< p_isotopeIon->
getMz
() <<
" "
102
<< isotope_number <<
" "
<< p_isotopeIon->
toString
();
103
104
std::vector<DataPoint>::iterator it_peak =
105
getBestPeakIterator
(peak_list, *p_isotopeIon);
106
if
(it_peak != peak_list.end())
107
{
108
_peak_ion_match_list
.push_back(
109
PeakIonIsotopeMatch
(*it_peak,
110
p_isotopeIon->
makePeptideNaturalIsotopeAverageSp
(),
111
peptide_fragment_ion));
112
peak_list.erase(it_peak);
113
114
qDebug()
115
<< isotope_number <<
" "
<<
_peak_ion_match_list
.back().toString();
116
}
117
delete
p_isotopeIon;
118
}
119
}
120
}
121
}
122
}
123
catch
(
PappsoException
&exception_pappso)
124
{
125
QString errorStr =
126
QObject::tr(
"ERROR building PeptideIsotopeSpectrumMatch, PAPPSO exception:\n%1"
)
127
.arg(exception_pappso.
qwhat
());
128
qDebug() <<
"PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch "
129
"PappsoException :\n"
130
<< errorStr;
131
throw
PappsoException
(errorStr);
132
}
133
catch
(std::exception &exception_std)
134
{
135
QString errorStr =
136
QObject::tr(
"ERROR building PeptideIsotopeSpectrumMatch, std exception:\n%1"
)
137
.arg(exception_std.what());
138
qDebug() <<
"PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch "
139
"std::exception :\n"
140
<< errorStr;
141
throw
PappsoException
(errorStr);
142
}
143
144
qDebug() <<
"_peak_ion_match_list.size()="
<<
_peak_ion_match_list
.size();
145
}
146
147
PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch
(
148
const
MassSpectrum
&spectrum,
149
std::vector<PeptideNaturalIsotopeAverageSp> v_peptideIsotopeList,
150
std::vector<PeptideFragmentIonSp> v_peptideIonList,
151
PrecisionPtr
precision)
152
:
_precision
(precision)
153
{
154
qDebug() <<
" begin"
;
155
if
(v_peptideIsotopeList.size() != v_peptideIonList.size())
156
{
157
throw
PappsoException
(
158
QObject::tr(
"v_peptideIsotopeList.size() %1 != v_peptideIonList.size() %2"
)
159
.arg(v_peptideIsotopeList.size())
160
.arg(v_peptideIonList.size()));
161
}
162
163
auto
isotopeIt = v_peptideIsotopeList.begin();
164
auto
ionIt = v_peptideIonList.begin();
165
std::vector<DataPoint> peak_list(spectrum.begin(), spectrum.end());
166
167
while
(isotopeIt != v_peptideIsotopeList.end())
168
{
169
std::vector<DataPoint>::iterator it_peak =
170
getBestPeakIterator
(peak_list, *(isotopeIt->get()));
171
if
(it_peak != peak_list.end())
172
{
173
_peak_ion_match_list
.push_back(
PeakIonIsotopeMatch
(*it_peak, *isotopeIt, *ionIt));
174
peak_list.erase(it_peak);
175
}
176
isotopeIt++;
177
ionIt++;
178
}
179
qDebug() <<
"_peak_ion_match_list.size()="
<<
_peak_ion_match_list
.size() <<
" end"
;
180
}
181
182
183
PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch
(
const
PeptideIsotopeSpectrumMatch
&other)
184
:
_precision
(other.
_precision
),
_peak_ion_match_list
(other.
_peak_ion_match_list
)
185
{
186
qDebug();
187
}
188
189
PeptideIsotopeSpectrumMatch::~PeptideIsotopeSpectrumMatch
()
190
{
191
}
192
193
194
std::vector<DataPoint>::iterator
195
PeptideIsotopeSpectrumMatch::getBestPeakIterator
(std::vector<DataPoint> &peak_list,
196
const
PeptideNaturalIsotopeAverage
&ion)
const
197
{
198
// qDebug();
199
std::vector<DataPoint>::iterator itpeak = peak_list.begin();
200
std::vector<DataPoint>::iterator itend = peak_list.end();
201
std::vector<DataPoint>::iterator itselect = peak_list.end();
202
203
pappso_double
best_intensity = 0;
204
205
while
(itpeak != itend)
206
{
207
// qDebug() << itpeak->x;
208
if
(ion.
matchPeak
(itpeak->x))
209
{
210
if
(itpeak->y > best_intensity)
211
{
212
best_intensity = itpeak->y;
213
itselect = itpeak;
214
}
215
}
216
itpeak++;
217
}
218
// qDebug();
219
return
(itselect);
220
}
221
222
const
std::list<PeakIonIsotopeMatch> &
223
PeptideIsotopeSpectrumMatch::getPeakIonIsotopeMatchList
()
const
224
{
225
qDebug() <<
"_peak_ion_match_list.size()="
<<
_peak_ion_match_list
.size();
226
return
_peak_ion_match_list
;
227
}
228
229
std::size_t
230
PeptideIsotopeSpectrumMatch::size
()
const
231
{
232
return
_peak_ion_match_list
.size();
233
}
234
PeptideIsotopeSpectrumMatch::const_iterator
235
PeptideIsotopeSpectrumMatch::begin
()
const
236
{
237
return
_peak_ion_match_list
.begin();
238
}
239
PeptideIsotopeSpectrumMatch::const_iterator
240
PeptideIsotopeSpectrumMatch::end
()
const
241
{
242
return
_peak_ion_match_list
.end();
243
}
244
245
void
246
PeptideIsotopeSpectrumMatch::dropPeaksLackingMonoisotope
()
247
{
248
qDebug();
249
_peak_ion_match_list
.sort([](
const
PeakIonIsotopeMatch
&
a
,
const
PeakIonIsotopeMatch
&
b
) {
250
if
(
a
.getPeptideIonType() <
b
.getPeptideIonType())
251
return
true
;
252
if
(
a
.getPeptideFragmentIonSp().get()->size() <
b
.getPeptideFragmentIonSp().get()->size())
253
return
true
;
254
if
(
a
.getCharge() <
b
.getCharge())
255
return
true
;
256
if
(
a
.getPeptideNaturalIsotopeAverageSp().get()->getIsotopeNumber() <
257
b
.getPeptideNaturalIsotopeAverageSp().get()->getIsotopeNumber())
258
return
true
;
259
return
false
;
260
});
261
Enums::PeptideIon
ion_type =
Enums::PeptideIon::b
;
262
std::size_t nserie = 0;
263
std::size_t isotopeserie = 0;
264
unsigned
int
charge = 0;
265
for
(std::list<PeakIonIsotopeMatch>::iterator it =
_peak_ion_match_list
.begin();
266
it !=
_peak_ion_match_list
.end();
267
it++)
268
{
269
if
((nserie != it->getPeptideFragmentIonSp().get()->size()) ||
270
(ion_type != it->getPeptideIonType()) || (charge != it->getCharge()))
271
{
272
ion_type = it->getPeptideIonType();
273
isotopeserie = 0;
274
nserie = it->getPeptideFragmentIonSp().get()->size();
275
charge = it->getCharge();
276
}
277
if
(isotopeserie <= it->getPeptideNaturalIsotopeAverageSp().get()->getIsotopeNumber())
278
{
279
isotopeserie = it->getPeptideNaturalIsotopeAverageSp().get()->getIsotopeNumber();
280
}
281
else
282
{
283
it =
_peak_ion_match_list
.erase(it);
284
}
285
}
286
qDebug();
287
}
288
}
// namespace pappso
pappso::MassSpectrum
Class to represent a mass spectrum.
Definition
massspectrum.h:70
pappso::PappsoException
Definition
pappsoexception.h:41
pappso::PappsoException::qwhat
virtual const QString & qwhat() const
Definition
pappsoexception.h:66
pappso::PeakIonIsotopeMatch
Definition
peakionisotopematch.h:47
pappso::PeptideFragmentIonListBase
Definition
peptidefragmentionlistbase.h:45
pappso::PeptideFragmentIonListBase::getPeptideFragmentIonSp
const std::list< PeptideFragmentIonSp > getPeptideFragmentIonSp(Enums::PeptideIon ion_type) const
Definition
peptidefragmentionlistbase.cpp:226
pappso::PeptideFragmentIonListBase::size
std::size_t size() const
Definition
peptidefragmentionlistbase.cpp:274
pappso::PeptideIsotopeSpectrumMatch::~PeptideIsotopeSpectrumMatch
virtual ~PeptideIsotopeSpectrumMatch()
Definition
peptideisotopespectrummatch.cpp:189
pappso::PeptideIsotopeSpectrumMatch::_precision
PrecisionPtr _precision
Definition
peptideisotopespectrummatch.h:84
pappso::PeptideIsotopeSpectrumMatch::PeptideIsotopeSpectrumMatch
PeptideIsotopeSpectrumMatch(const MassSpectrum &spectrum, const PeptideSp &peptide_sp, unsigned int parent_charge, PrecisionPtr precision, const std::list< Enums::PeptideIon > &ion_type_list, unsigned int max_isotope_number, unsigned int max_isotope_rank)
annotate spectrum with peptide ions and isotopes
Definition
peptideisotopespectrummatch.cpp:31
pappso::PeptideIsotopeSpectrumMatch::const_iterator
std::list< PeakIonIsotopeMatch >::const_iterator const_iterator
Definition
peptideisotopespectrummatch.h:71
pappso::PeptideIsotopeSpectrumMatch::_peak_ion_match_list
std::list< PeakIonIsotopeMatch > _peak_ion_match_list
Definition
peptideisotopespectrummatch.h:85
pappso::PeptideIsotopeSpectrumMatch::getPeakIonIsotopeMatchList
const std::list< PeakIonIsotopeMatch > & getPeakIonIsotopeMatchList() const
Definition
peptideisotopespectrummatch.cpp:223
pappso::PeptideIsotopeSpectrumMatch::begin
const_iterator begin() const
Definition
peptideisotopespectrummatch.cpp:235
pappso::PeptideIsotopeSpectrumMatch::dropPeaksLackingMonoisotope
void dropPeaksLackingMonoisotope()
Definition
peptideisotopespectrummatch.cpp:246
pappso::PeptideIsotopeSpectrumMatch::size
std::size_t size() const
Definition
peptideisotopespectrummatch.cpp:230
pappso::PeptideIsotopeSpectrumMatch::end
const_iterator end() const
Definition
peptideisotopespectrummatch.cpp:240
pappso::PeptideIsotopeSpectrumMatch::getBestPeakIterator
virtual std::vector< DataPoint >::iterator getBestPeakIterator(std::vector< DataPoint > &peak_list, const PeptideNaturalIsotopeAverage &ion) const
Definition
peptideisotopespectrummatch.cpp:195
pappso::PeptideNaturalIsotopeAverage
Definition
peptidenaturalisotopeaverage.h:43
pappso::PeptideNaturalIsotopeAverage::toString
virtual QString toString() const
Definition
peptidenaturalisotopeaverage.cpp:255
pappso::PeptideNaturalIsotopeAverage::getMz
pappso_double getMz() const
Definition
peptidenaturalisotopeaverage.cpp:192
pappso::PeptideNaturalIsotopeAverage::matchPeak
virtual bool matchPeak(pappso_double peak_mz) const final
Definition
peptidenaturalisotopeaverage.cpp:240
pappso::PeptideNaturalIsotopeAverage::makePeptideNaturalIsotopeAverageSp
PeptideNaturalIsotopeAverageSp makePeptideNaturalIsotopeAverageSp() const
Definition
peptidenaturalisotopeaverage.cpp:166
pappso::PeptideNaturalIsotopeList
Definition
peptidenaturalisotopelist.h:49
pappso::Enums::PeptideIon
PeptideIon
Enums::PeptideIon enum defines all types of ions (Nter or Cter).
Definition
types.h:272
pappso::Enums::PeptideIon::y
@ y
Cter amino ions.
Definition
types.h:281
pappso::Enums::PeptideIon::b
@ b
Nter acylium ions.
Definition
types.h:273
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition
aa.cpp:39
pappso::PeptideIonNter::a
@ a
Definition
peptide.h:77
pappso::PeptideIonNter::b
@ b
Definition
peptide.h:74
pappso::PeptideSp
std::shared_ptr< const Peptide > PeptideSp
Definition
aamodification.h:48
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition
types.h:60
pappso::PrecisionPtr
const PrecisionBase * PrecisionPtr
Definition
precision.h:122
peptideisotopespectrummatch.h
peptidenaturalisotopelist.h
pappsomspp
core
psm
peptideisotopespectrummatch.cpp
Generated on
for libpappsomspp by
1.17.0