libpappsomspp
Library for mass spectrometry
Toggle main menu visibility
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
"
35
#include "
peptidespectrummatch.h
"
36
#include "
pappsomspp/core/pappsoexception.h
"
37
#include "
pappsomspp/core/peptide/peptidefragment.h
"
38
#include "
pappsomspp/core/peptide/peptidefragmentionlistbase.h
"
39
40
namespace
pappso
41
{
42
43
44
void
45
PeptideSpectrumMatch::privMatchIonList
(
const
MassSpectrum
&spectrum,
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
95
PeptideSpectrumMatch::PeptideSpectrumMatch
(
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]="
134
<<
_ion_type_count
[(std::int8_t)
Enums::PeptideIon::y
];
135
}
136
137
138
PeptideSpectrumMatch::PeptideSpectrumMatch
(
const
MassSpectrum
&spectrum,
139
const
PeptideFragmentIonListBase
&fragmentIonList,
140
unsigned
int
max_charge,
141
PrecisionPtr
precision,
142
const
std::list<Enums::PeptideIon> &ion_type_list)
143
:
_precision
(precision)
144
{
145
privMatchIonList
(spectrum, fragmentIonList, max_charge, ion_type_list);
146
qDebug() << __FILE__ <<
" "
<< __FUNCTION__ <<
" "
<< __LINE__
147
<<
" _ion_type_count[PeptideIon::y]="
148
<<
_ion_type_count
[(std::int8_t)
Enums::PeptideIon::y
];
149
}
150
151
PeptideSpectrumMatch::PeptideSpectrumMatch
(
const
MassSpectrum
&spectrum,
152
const
pappso::PeptideSp
&peptideSp,
153
unsigned
int
parent_charge,
154
PrecisionPtr
precision,
155
const
std::list<Enums::PeptideIon> &ion_type_list)
156
:
_precision
(precision)
157
{
158
PeptideFragmentIonListBase
fragmentIonList(peptideSp, ion_type_list);
159
privMatchIonList
(spectrum, fragmentIonList, parent_charge, ion_type_list);
160
qDebug() << __FILE__ <<
" "
<< __FUNCTION__ <<
" "
<< __LINE__
161
<<
" _ion_type_count[PeptideIon::y]="
162
<<
_ion_type_count
[(std::int8_t)
Enums::PeptideIon::y
];
163
}
164
165
166
PeptideSpectrumMatch::PeptideSpectrumMatch
(
const
PeptideSpectrumMatch
&other)
167
:
_precision
(other.
_precision
),
_peak_ion_match_list
(other.
_peak_ion_match_list
)
168
{
169
}
170
171
std::list<DataPoint>::iterator
172
PeptideSpectrumMatch::getBestPeakIterator
(std::list<DataPoint> &peak_list,
173
const
PeptideFragmentIonSp
&ion,
174
unsigned
int
charge)
const
175
{
176
// qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
177
// << " peak_list.size()=" << peak_list.size();
178
std::list<DataPoint>::iterator itpeak = peak_list.begin();
179
std::list<DataPoint>::iterator itend = peak_list.end();
180
std::list<DataPoint>::iterator itselect = peak_list.end();
181
182
pappso_double
best_intensity = 0;
183
184
while
(itpeak != itend)
185
{
186
187
// qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
188
// << " itpeak->x=" << itpeak->x;
189
if
(ion.get()->matchPeak(
_precision
, itpeak->x, charge))
190
{
191
// qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
192
// << " ion.get()->matchPeak";
193
if
(itpeak->y > best_intensity)
194
{
195
best_intensity = itpeak->y;
196
itselect = itpeak;
197
}
198
}
199
itpeak++;
200
}
201
202
return
(itselect);
203
}
204
205
PeptideSpectrumMatch::~PeptideSpectrumMatch
()
206
{
207
}
208
209
210
unsigned
int
211
PeptideSpectrumMatch::size
()
const
212
{
213
return
_peak_ion_match_list
.size();
214
}
215
216
PeptideSpectrumMatch::const_iterator
217
PeptideSpectrumMatch::begin
()
const
218
{
219
return
_peak_ion_match_list
.begin();
220
}
221
PeptideSpectrumMatch::const_iterator
222
PeptideSpectrumMatch::end
()
const
223
{
224
return
_peak_ion_match_list
.end();
225
}
226
227
unsigned
int
228
PeptideSpectrumMatch::countTotalMatchedIons
()
const
229
{
230
return
std::accumulate(
_ion_type_count
.begin(),
_ion_type_count
.end(), 0);
231
}
232
233
const
std::array<unsigned int, PEPTIDE_ION_TYPE_COUNT> &
234
PeptideSpectrumMatch::getIonTypeCountArray
()
const
235
{
236
return
_ion_type_count
;
237
}
238
239
bool
240
PeptideSpectrumMatch::contains
(
const
PeptideFragmentIon
*peptideFragmentIonSp,
unsigned
int
z
)
const
241
{
242
auto
it =
_peak_ion_match_list
.begin();
243
while
(it !=
_peak_ion_match_list
.end())
244
{
245
const
PeakIonMatch
&ref = *it;
246
if
((ref.
getCharge
() ==
z
) && (ref.
getPeptideFragmentIonSp
().get() == peptideFragmentIonSp))
247
{
248
return
true
;
249
}
250
it++;
251
}
252
return
false
;
253
}
254
}
// namespace pappso
pappso::MassSpectrum
Class to represent a mass spectrum.
Definition
massspectrum.h:70
pappso::PappsoException
Definition
pappsoexception.h:41
pappso::PeakIonMatch
Definition
peakionmatch.h:40
pappso::PeakIonMatch::getPeptideFragmentIonSp
virtual const PeptideFragmentIonSp & getPeptideFragmentIonSp() const
Definition
peakionmatch.cpp:68
pappso::PeakIonMatch::getCharge
unsigned int getCharge() const
Definition
peakionmatch.cpp:80
pappso::PeptideFragmentIonListBase
Definition
peptidefragmentionlistbase.h:45
pappso::PeptideFragmentIonListBase::getPeptideFragmentIonSp
const std::list< PeptideFragmentIonSp > getPeptideFragmentIonSp(Enums::PeptideIon ion_type) const
Definition
peptidefragmentionlistbase.cpp:226
pappso::PeptideFragmentIon
Definition
peptidefragmention.h:50
pappso::PeptideSpectrumMatch::getBestPeakIterator
virtual std::list< DataPoint >::iterator getBestPeakIterator(std::list< DataPoint > &peak_list, const PeptideFragmentIonSp &ion, unsigned int charge) const
Definition
peptidespectrummatch.cpp:172
pappso::PeptideSpectrumMatch::contains
bool contains(const PeptideFragmentIon *peptideFragmentIonSp, unsigned int z) const
Definition
peptidespectrummatch.cpp:240
pappso::PeptideSpectrumMatch::_ion_type_count
std::array< unsigned int, PEPTIDE_ION_TYPE_COUNT > _ion_type_count
Definition
peptidespectrummatch.h:96
pappso::PeptideSpectrumMatch::countTotalMatchedIons
unsigned int countTotalMatchedIons() const
Definition
peptidespectrummatch.cpp:228
pappso::PeptideSpectrumMatch::end
const_iterator end() const
Definition
peptidespectrummatch.cpp:222
pappso::PeptideSpectrumMatch::size
unsigned int size() const
Definition
peptidespectrummatch.cpp:211
pappso::PeptideSpectrumMatch::~PeptideSpectrumMatch
virtual ~PeptideSpectrumMatch()
Definition
peptidespectrummatch.cpp:205
pappso::PeptideSpectrumMatch::_peak_ion_match_list
std::list< PeakIonMatch > _peak_ion_match_list
Definition
peptidespectrummatch.h:94
pappso::PeptideSpectrumMatch::getIonTypeCountArray
const std::array< unsigned int, PEPTIDE_ION_TYPE_COUNT > & getIonTypeCountArray() const
Definition
peptidespectrummatch.cpp:234
pappso::PeptideSpectrumMatch::PeptideSpectrumMatch
PeptideSpectrumMatch(const MassSpectrum &spectrum, const pappso::PeptideSp &peptideSp, unsigned int parent_charge, PrecisionPtr precision, const std::list< Enums::PeptideIon > &ion_type_list)
Definition
peptidespectrummatch.cpp:151
pappso::PeptideSpectrumMatch::_precision
PrecisionPtr _precision
Definition
peptidespectrummatch.h:92
pappso::PeptideSpectrumMatch::const_iterator
std::list< PeakIonMatch >::const_iterator const_iterator
Definition
peptidespectrummatch.h:69
pappso::PeptideSpectrumMatch::begin
const_iterator begin() const
Definition
peptidespectrummatch.cpp:217
pappso::PeptideSpectrumMatch::privMatchIonList
void privMatchIonList(const MassSpectrum &spectrum, const PeptideFragmentIonListBase &fragmentIonList, unsigned int max_charge, const std::list< Enums::PeptideIon > &ion_type_list)
Definition
peptidespectrummatch.cpp:45
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::PeptideFragmentIonSp
std::shared_ptr< const PeptideFragmentIon > PeptideFragmentIonSp
Definition
peptidefragmention.h:46
pappso::PeptideSp
std::shared_ptr< const Peptide > PeptideSp
Definition
aamodification.h:48
pappso::PeptideIonCter::z
@ z
Definition
peptide.h:90
pappso::pappso_double
double pappso_double
A type definition for doubles.
Definition
types.h:60
pappso::PrecisionPtr
const PrecisionBase * PrecisionPtr
Definition
precision.h:122
pappsoexception.h
peakionmatch.h
peptidefragment.h
peptidefragmentionlistbase.h
peptidespectrummatch.h
pappsomspp
core
psm
peptidespectrummatch.cpp
Generated on
for libpappsomspp by
1.17.0