libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
xtandemhyperscore.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/psm/xtandemhyperscore.cpp
3 * \date 19/3/2015
4 * \author Olivier Langella
5 * \brief computation of the X!Tandem hyperscore
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#include <QDebug>
32#include <cmath>
36#include "xtandemhyperscore.h"
38
39namespace pappso
40{
41
42unsigned int
43factorial(unsigned int n)
44{
45 unsigned int retval = 1;
46 for(int i = n; i > 1; --i)
47 retval *= i;
48 return retval;
49}
50
52 pappso::PeptideSp peptideSp,
53 unsigned int parent_charge,
54 PrecisionPtr precision,
55 std::list<Enums::PeptideIon> ion_list,
56 bool refine_spectrum_synthesis)
57 : _refine_spectrum_synthesis(refine_spectrum_synthesis)
58{
59 try
60 {
61 /*
62 if ((peptide_ion_sp.get()->getPeptideIonType() == Enums::PeptideIon::c) ||
63 (peptide_ion_sp.get()->getPeptideIonType() == Enums::PeptideIon::z)) {
64 if(current_max_charge > 2) {
65 current_max_charge--;
66 }
67 }*/
68 unsigned int max_charge = parent_charge;
69 if(parent_charge > 1)
70 {
71 max_charge = parent_charge - 1;
72 }
73 PeptideSpectrumMatch psm(spectrum, peptideSp, max_charge, precision, ion_list);
74
84
85 std::map<Enums::PeptideIon, unsigned int> ion_count;
86 for(auto &&ion_type : ion_list)
87 {
88 ion_count.insert(std::pair<Enums::PeptideIon, unsigned int>(ion_type, 0));
89 }
90
91 std::map<unsigned int, pappso_double> charge_dot_product;
92 std::map<unsigned int, std::map<Enums::PeptideIon, unsigned int>> charge_ion_count;
93 for(unsigned int i = 1; i <= max_charge; i++)
94 {
95 charge_dot_product.insert(std::pair<unsigned int, pappso_double>(i, 0));
96 charge_ion_count.insert(
97 std::pair<unsigned int, std::map<Enums::PeptideIon, unsigned int>>(i, ion_count));
98 }
99 QString sequence = peptideSp.get()->getSequence();
100 for(auto &&peptide_ion_match : psm)
101 {
102 Enums::PeptideIon ion_type = peptide_ion_match.getPeptideIonType();
103 unsigned int charge = peptide_ion_match.getCharge();
104 charge_dot_product[charge] +=
105 peptide_ion_match.getPeak().y *
107 sequence,
108 peptide_ion_match.getPeptideIonDirection(),
109 peptide_ion_match.getPeptideFragmentIonSp().get()->size());
110 charge_ion_count[charge][ion_type] += 1;
111 _ion_count[ion_type] += 1;
112 }
113
114 qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__
115 << " _ion_count[Enums::PeptideIon::y]=" << _ion_count[Enums::PeptideIon::y];
116 // take the 2 best component
117 pappso_double sum_intensity = 0;
118 for(unsigned int i = 1; i <= max_charge; i++)
119 {
120 sum_intensity += charge_dot_product[i];
121 }
122 for(auto count : _ion_count)
123 {
124 sum_intensity *= factorial(count.second);
125 }
126
127 _proto_hyperscore = sum_intensity;
128 }
129 catch(PappsoException &exception_pappso)
130 {
131 QString errorStr = QObject::tr("ERROR computing hyperscore, PAPPSO exception:\n%1")
132 .arg(exception_pappso.qwhat());
133 qDebug() << "XtandemHyperscore::XtandemHyperscore PappsoException :\n" << errorStr;
134 throw PappsoException(errorStr);
135 }
136 catch(std::exception &exception_std)
137 {
138 QString errorStr =
139 QObject::tr("ERROR computing hyperscore, std exception:\n%1").arg(exception_std.what());
140 qDebug() << "XtandemHyperscore::XtandemHyperscore std::exception :\n" << errorStr;
141 throw PappsoException(errorStr);
142 }
143}
144
151
152unsigned int
154{
155 return _ion_count.at(ion_type);
156}
160
161
163 AaFactorMap ret;
164 // populate ret
165 for(long c = 64; c < 126; c++)
166 {
167 ret.insert(std::pair<char, pappso_double>(c, pappso_double(1.0)));
168 }
169 ret['P'] = pappso_double(5.0);
170 return ret;
171}();
172
173
175 AaFactorMap ret;
176 // populate ret
177 for(long c = 64; c < 126; c++)
178 {
179 ret.insert(std::pair<char, pappso_double>(c, pappso_double(1.0)));
180 }
181 ret['D'] = pappso_double(5.0);
182 ret['N'] = pappso_double(2.0);
183 ret['V'] = pappso_double(3.0);
184 ret['E'] = pappso_double(3.0);
185 ret['Q'] = pappso_double(2.0);
186 ret['I'] = pappso_double(3.0);
187 ret['L'] = pappso_double(3.0);
188 return ret;
189}();
190
191
192unsigned int
194 PeptideDirection ion_direction,
195 unsigned int ion_size) const
196{
197 unsigned int Pi(1);
198
199 char last_aa_nter('_'), last_aa_cter('_');
200
201 if(ion_direction == PeptideDirection::Nter)
202 {
203 last_aa_nter = sequence[ion_size - 1].toLatin1();
204 last_aa_cter = sequence[ion_size].toLatin1();
205 if(ion_size == 2)
206 {
207 if(last_aa_nter == 'P')
208 {
209 Pi *= 10;
210 }
211 else
212 {
213 Pi *= 3;
214 }
215 }
216 }
217 else
218 {
219 unsigned int offset(sequence.size() - ion_size);
220 last_aa_nter = sequence[offset - 1].toLatin1();
221 last_aa_cter = sequence[offset].toLatin1();
222 if((offset) == 2)
223 {
224 if(last_aa_nter == 'P')
225 {
226 Pi *= 10;
227 }
228 else
229 {
230 Pi *= 3;
231 }
232 }
233 }
234 // QDebug << " last_aa_nter=" << QChar(last_aa_nter) << "
235 // _aa_ion_factor_b[last_aa_nter]="s ;
236 qDebug() << PeptideFragment::getPeptideIonDirectionName(ion_direction)
237 << " last_aa_nter=" << last_aa_nter
238 << " _aa_ion_factor_b[last_aa_nter]=" << _aa_ion_factor_b[last_aa_nter]
239 << " last_aa_cter=" << last_aa_cter
240 << " _aa_ion_factor_y[last_aa_cter]=" << _aa_ion_factor_y[last_aa_cter];
242 {
243 Pi *= _aa_ion_factor_b[last_aa_nter] * _aa_ion_factor_y[last_aa_cter];
244 }
245
246 return Pi;
247}
248
249
252{
253 try
254 {
255 qDebug() << " _proto_hyperscore=" << _proto_hyperscore;
256 double hyperscore = (log10(_proto_hyperscore) * 4);
257 if(hyperscore < 0)
258 return 0;
259 return hyperscore;
260 }
261 catch(PappsoException &exception_pappso)
262 {
263 QString errorStr =
264 QObject::tr("ERROR in getHyperscore, PAPPSO exception:\n%1").arg(exception_pappso.qwhat());
265 qDebug() << "XtandemHyperscore::getHyperscore PappsoException :\n" << errorStr;
266 throw PappsoException(errorStr);
267 }
268 catch(std::exception &exception_std)
269 {
270 QString errorStr =
271 QObject::tr("ERROR in getHyperscore, std exception:\n%1").arg(exception_std.what());
272 qDebug() << "XtandemHyperscore::getHyperscore std::exception :\n" << errorStr;
273 throw PappsoException(errorStr);
274 }
275}
276
277
278} // namespace pappso
Class to represent a mass spectrum.
virtual const QString & qwhat() const
static const QString getPeptideIonDirectionName(PeptideDirection direction)
unsigned int getMatchedIons(Enums::PeptideIon ion_type) const
unsigned int getXtandemPredictedIonIntensityFactor(const QString &sequence, PeptideDirection ion_direction, unsigned int ion_size) const
pappso_double getHyperscore() const
static AaFactorMap _aa_ion_factor_y
std::map< Enums::PeptideIon, unsigned int > _ion_count
XtandemHyperscore(const MassSpectrum &spectrum, pappso::PeptideSp peptideSp, unsigned int parent_charge, PrecisionPtr precision, std::list< Enums::PeptideIon > ion_list, bool refine_spectrum_synthesis)
std::map< char, pappso_double > AaFactorMap
static AaFactorMap _aa_ion_factor_b
PeptideIon
Enums::PeptideIon enum defines all types of ions (Nter or Cter).
Definition types.h:286
@ a
Nter aldimine ions.
Definition types.h:290
@ y
Cter amino ions.
Definition types.h:295
@ c
Nter amino ions.
Definition types.h:294
@ ystar
Cter amino ions + NH3 loss.
Definition types.h:296
@ yo
Cter amino ions + H2O loss.
Definition types.h:297
@ bstar
Nter acylium ions + NH3 loss.
Definition types.h:288
@ b
Nter acylium ions.
Definition types.h:287
@ bo
Nter acylium ions + H2O loss.
Definition types.h:289
@ z
Cter carbocations.
Definition types.h:298
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
std::shared_ptr< const Peptide > PeptideSp
PeptideDirection
Definition peptide.h:47
double pappso_double
A type definition for doubles.
Definition types.h:60
const PrecisionBase * PrecisionPtr
Definition precision.h:122
unsigned int factorial(unsigned int n)