libpappsomspp
Library for mass spectrometry
xtandemhyperscorebis.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/psm/xtandem/xtandemhyperscorebis.cpp
3 * \date 8/9/2016
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
32#include <cmath>
33#include "../../peptide/peptiderawfragmentmasses.h"
34#include "../../pappsoexception.h"
35
36
37// FIXME pourquoi ici cette directive et pas le namespace habituel ?
38using namespace pappso;
39
40unsigned int
41factorial(unsigned int n)
42{
43 unsigned int retval = 1;
44 for(int i = n; i > 1; --i)
45 retval *= i;
46 return retval;
47}
48
49
50XtandemHyperscoreBis::XtandemHyperscoreBis(
51 bool refine_spectrum_synthesis,
52 PrecisionPtr precision,
53 const std::vector<PeptideIon> &ion_list)
54{
55
56 m_isRefineSpectrumSynthesis = refine_spectrum_synthesis;
57 mp_precision = precision;
58 m_ionList = ion_list;
60}
61
63{
64}
65
66unsigned int
68{
69 return m_ionCount[(std::int8_t)ion_type];
70}
71
72
73void
75{
76
78
81}
82
83
84bool
86 const Peptide &peptide,
87 unsigned int parent_charge)
88{
89 try
90 {
91
92 unsigned int max_charge = parent_charge;
93 if(parent_charge > 1)
94 {
95 max_charge = parent_charge - 1;
96 }
97 // PeptideSpectrumMatch psm (spectrum, peptideSp, max_charge, precision,
98 // ion_list);
99
100 PeptideRawFragmentMasses calc_mass_list(peptide,
102
103 std::vector<SimplePeakIonMatch> match_products;
104 unsigned int charge_i;
105 for(PeptideIon &ion : m_ionList)
106 {
107 charge_i = max_charge;
108 while(charge_i > 0)
109 {
110 calc_mass_list.pushBackMatchSpectrum(
111 match_products, spectrum, mp_precision, ion, charge_i);
112 charge_i--;
113 }
114 }
115 m_totalMatchedIons = match_products.size();
116 if(m_totalMatchedIons == 0)
117 {
119 }
120 else
121 {
122
123 unsigned int charge_ion_count[5][20] = {0};
124
125 pappso_double charge_dot_product[5] = {0};
126
127 QString sequence = peptide.getSequence();
128
129 for(SimplePeakIonMatch &peptide_ion_match : match_products)
130 {
131 charge_dot_product[peptide_ion_match.ion_charge] +=
132 peptide_ion_match.peak.y *
134 sequence,
135 peptide_ion_match.ion_type,
136 peptide_ion_match.ion_size);
137 charge_ion_count[peptide_ion_match.ion_charge]
138 [(std::int8_t)peptide_ion_match.ion_type] += 1;
139 m_ionCount[(std::int8_t)peptide_ion_match.ion_type] += 1;
140 }
141 // take the 2 best component
142 pappso_double sum_intensity = 0;
143 for(unsigned int i = 1; i <= max_charge; i++)
144 {
145 sum_intensity += charge_dot_product[i];
146 }
147 for(auto count : m_ionCount)
148 {
149 sum_intensity *= factorial(count);
150 }
151
152 m_protoHyperscore = sum_intensity;
153 }
154 return true;
155 }
156 catch(PappsoException &exception_pappso)
157 {
158 QString errorStr =
159 QObject::tr("ERROR computing hyperscore, PAPPSO exception:\n%1")
160 .arg(exception_pappso.qwhat());
161 qDebug() << "XtandemHyperscore::XtandemHyperscore PappsoException :\n"
162 << errorStr;
163 throw PappsoException(errorStr);
164 }
165 catch(std::exception &exception_std)
166 {
167 QString errorStr =
168 QObject::tr("ERROR computing hyperscore, std exception:\n%1")
169 .arg(exception_std.what());
170 qDebug() << "XtandemHyperscore::XtandemHyperscore std::exception :\n"
171 << errorStr;
172 throw PappsoException(errorStr);
173 }
174}
175
176
178 AaFactorMap ret;
179 // populate ret
180 for(long c = 64; c < 126; c++)
181 {
182 ret.insert(std::pair<char, pappso_double>(c, pappso_double(1.0)));
183 }
184 ret['P'] = pappso_double(5.0);
185 return ret;
186}();
187
188
190 AaFactorMap ret;
191 // populate ret
192 for(long c = 64; c < 126; c++)
193 {
194 ret.insert(std::pair<char, pappso_double>(c, pappso_double(1.0)));
195 }
196 ret['D'] = pappso_double(5.0);
197 ret['N'] = pappso_double(2.0);
198 ret['V'] = pappso_double(3.0);
199 ret['E'] = pappso_double(3.0);
200 ret['Q'] = pappso_double(2.0);
201 ret['I'] = pappso_double(3.0);
202 ret['L'] = pappso_double(3.0);
203 return ret;
204}();
205
206
207unsigned int
209 const QString &sequence, PeptideIon ion_type, unsigned int ion_size) const
210{
211 unsigned int Pi(1);
212
213 char last_aa_nter('_'), last_aa_cter('_');
214
215 if(peptideIonIsNter(ion_type))
216 {
217 last_aa_nter = sequence[ion_size - 1].toLatin1();
218 last_aa_cter = sequence[ion_size].toLatin1();
219 if(ion_size == 2)
220 {
221 if(last_aa_nter == 'P')
222 {
223 Pi *= 10;
224 }
225 else
226 {
227 Pi *= 3;
228 }
229 }
230 }
231 else
232 {
233 unsigned int offset(sequence.size() - ion_size);
234 last_aa_nter = sequence[offset - 1].toLatin1();
235 last_aa_cter = sequence[offset].toLatin1();
236 if((offset) == 2)
237 {
238 if(last_aa_nter == 'P')
239 {
240 Pi *= 10;
241 }
242 else
243 {
244 Pi *= 3;
245 }
246 }
247 }
248 // QDebug << " last_aa_nter=" << QChar(last_aa_nter) << "
249 // m_aaIonFactorBb[last_aa_nter]="s ;
250 // qDebug() << PeptideFragment::getPeptideIonDirectionName(ion_direction) << "
251 // last_aa_nter=" << last_aa_nter << " m_aaIonFactorBb[last_aa_nter]=" <<
252 // m_aaIonFactorBb[last_aa_nter] << " last_aa_cter=" << last_aa_cter << "
253 // m_aaIonFactorY[last_aa_cter]=" << m_aaIonFactorY[last_aa_cter];
255 {
256 Pi *= m_aaIonFactorBb[last_aa_nter] * m_aaIonFactorY[last_aa_cter];
257 }
258
259 return Pi;
260}
261
262unsigned int
264{
265 return m_totalMatchedIons;
266}
267
270{
271 try
272 {
273 if(m_protoHyperscore == 0)
274 return 0.0;
275 return (log10(m_protoHyperscore) * 4);
276 }
277 catch(PappsoException &exception_pappso)
278 {
279 QString errorStr =
280 QObject::tr("ERROR in getHyperscore, PAPPSO exception:\n%1")
281 .arg(exception_pappso.qwhat());
282 qDebug() << "XtandemHyperscore::getHyperscore PappsoException :\n"
283 << errorStr;
284 throw PappsoException(errorStr);
285 }
286 catch(std::exception &exception_std)
287 {
288 QString errorStr =
289 QObject::tr("ERROR in getHyperscore, std exception:\n%1")
290 .arg(exception_std.what());
291 qDebug() << "XtandemHyperscore::getHyperscore std::exception :\n"
292 << errorStr;
293 throw PappsoException(errorStr);
294 }
295}
Class to represent a mass spectrum.
Definition: massspectrum.h:71
virtual const QString & qwhat() const
void pushBackMatchSpectrum(std::vector< SimplePeakIonMatch > &peak_match_list, const MassSpectrum &spectrum, PrecisionPtr precision, PeptideIon ion_type, unsigned int charge) const
const QString getSequence() const override
print amino acid sequence without modifications
Definition: peptide.cpp:155
unsigned int getTotalMatchedIons() const
unsigned int getXtandemPredictedIonIntensityFactor(const QString &sequence, PeptideIon ion_type, unsigned int size) const
std::map< char, pappso_double > AaFactorMap
bool computeXtandemHyperscore(const MassSpectrum &spectrum, const Peptide &peptide, unsigned int parent_charge)
unsigned int m_ionCount[PEPTIDE_ION_TYPE_COUNT]
std::vector< PeptideIon > m_ionList
unsigned int getMatchedIons(PeptideIon ion_type) const
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
PeptideIon
PeptideIon enum defines all types of ions (Nter or Cter)
Definition: types.h:385
double pappso_double
A type definition for doubles.
Definition: types.h:48
bool peptideIonIsNter(PeptideIon ion_type)
tells if an ion is Nter
Definition: peptide.cpp:60
unsigned int factorial(unsigned int n)
#define PEPTIDE_ION_TYPE_COUNT
only usefull for inernal usefull DO not change this value : it is used to define static array size
Definition: types.h:405
unsigned int factorial(unsigned int n)
computation of the X!Tandem hyperscore