libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
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>
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(bool refine_spectrum_synthesis,
51 PrecisionPtr precision,
52 const std::vector<Enums::PeptideIon> &ion_list)
53{
54
55 m_isRefineSpectrumSynthesis = refine_spectrum_synthesis;
56 mp_precision = precision;
57 m_ionList = ion_list;
59}
60
64
65unsigned int
67{
68 return m_ionCount[(std::int8_t)ion_type];
69}
70
71
72void
81
82
83bool
85 const Peptide &peptide,
86 unsigned int parent_charge)
87{
88 try
89 {
90
91 unsigned int max_charge = parent_charge;
92 if(parent_charge > 1)
93 {
94 max_charge = parent_charge - 1;
95 }
96 // PeptideSpectrumMatch psm (spectrum, peptideSp, max_charge, precision,
97 // ion_list);
98
100
101 std::vector<SimplePeakIonMatch> match_products;
102 unsigned int charge_i;
103 for(Enums::PeptideIon &ion : m_ionList)
104 {
105 charge_i = max_charge;
106 while(charge_i > 0)
107 {
108 calc_mass_list.pushBackMatchSpectrum(
109 match_products, spectrum, mp_precision, ion, charge_i);
110 charge_i--;
111 }
112 }
113 m_totalMatchedIons = match_products.size();
114 if(m_totalMatchedIons == 0)
115 {
117 }
118 else
119 {
120
121 unsigned int charge_ion_count[5][20] = {0};
122
123 pappso_double charge_dot_product[5] = {0};
124
125 QString sequence = peptide.getSequence();
126
127 for(SimplePeakIonMatch &peptide_ion_match : match_products)
128 {
129 charge_dot_product[peptide_ion_match.ion_charge] +=
130 peptide_ion_match.peak.y *
132 sequence, peptide_ion_match.ion_type, peptide_ion_match.ion_size);
133 charge_ion_count[peptide_ion_match.ion_charge]
134 [(std::int8_t)peptide_ion_match.ion_type] += 1;
135 m_ionCount[(std::int8_t)peptide_ion_match.ion_type] += 1;
136 }
137 // take the 2 best component
138 pappso_double sum_intensity = 0;
139 for(unsigned int i = 1; i <= max_charge; i++)
140 {
141 sum_intensity += charge_dot_product[i];
142 }
143 for(auto count : m_ionCount)
144 {
145 sum_intensity *= factorial(count);
146 }
147
148 m_protoHyperscore = sum_intensity;
149 }
150 return true;
151 }
152 catch(PappsoException &exception_pappso)
153 {
154 QString errorStr = QObject::tr("ERROR computing hyperscore, PAPPSO exception:\n%1")
155 .arg(exception_pappso.qwhat());
156 qDebug() << "XtandemHyperscore::XtandemHyperscore PappsoException :\n" << errorStr;
157 throw PappsoException(errorStr);
158 }
159 catch(std::exception &exception_std)
160 {
161 QString errorStr =
162 QObject::tr("ERROR computing hyperscore, std exception:\n%1").arg(exception_std.what());
163 qDebug() << "XtandemHyperscore::XtandemHyperscore std::exception :\n" << errorStr;
164 throw PappsoException(errorStr);
165 }
166}
167
168
170 AaFactorMap ret;
171 // populate ret
172 for(long c = 64; c < 126; c++)
173 {
174 ret.insert(std::pair<char, pappso_double>(c, pappso_double(1.0)));
175 }
176 ret['P'] = pappso_double(5.0);
177 return ret;
178}();
179
180
182 AaFactorMap ret;
183 // populate ret
184 for(long c = 64; c < 126; c++)
185 {
186 ret.insert(std::pair<char, pappso_double>(c, pappso_double(1.0)));
187 }
188 ret['D'] = pappso_double(5.0);
189 ret['N'] = pappso_double(2.0);
190 ret['V'] = pappso_double(3.0);
191 ret['E'] = pappso_double(3.0);
192 ret['Q'] = pappso_double(2.0);
193 ret['I'] = pappso_double(3.0);
194 ret['L'] = pappso_double(3.0);
195 return ret;
196}();
197
198
199unsigned int
201 Enums::PeptideIon ion_type,
202 unsigned int ion_size) const
203{
204 unsigned int Pi(1);
205
206 char last_aa_nter('_'), last_aa_cter('_');
207
208 if(peptideIonIsNter(ion_type))
209 {
210 last_aa_nter = sequence[ion_size - 1].toLatin1();
211 last_aa_cter = sequence[ion_size].toLatin1();
212 if(ion_size == 2)
213 {
214 if(last_aa_nter == 'P')
215 {
216 Pi *= 10;
217 }
218 else
219 {
220 Pi *= 3;
221 }
222 }
223 }
224 else
225 {
226 unsigned int offset(sequence.size() - ion_size);
227 last_aa_nter = sequence[offset - 1].toLatin1();
228 last_aa_cter = sequence[offset].toLatin1();
229 if((offset) == 2)
230 {
231 if(last_aa_nter == 'P')
232 {
233 Pi *= 10;
234 }
235 else
236 {
237 Pi *= 3;
238 }
239 }
240 }
241 // QDebug << " last_aa_nter=" << QChar(last_aa_nter) << "
242 // m_aaIonFactorBb[last_aa_nter]="s ;
243 // qDebug() << PeptideFragment::getPeptideIonDirectionName(ion_direction) << "
244 // last_aa_nter=" << last_aa_nter << " m_aaIonFactorBb[last_aa_nter]=" <<
245 // m_aaIonFactorBb[last_aa_nter] << " last_aa_cter=" << last_aa_cter << "
246 // m_aaIonFactorY[last_aa_cter]=" << m_aaIonFactorY[last_aa_cter];
248 {
249 Pi *= m_aaIonFactorBb[last_aa_nter] * m_aaIonFactorY[last_aa_cter];
250 }
251
252 return Pi;
253}
254
255unsigned int
260
263{
264 try
265 {
266 if(m_protoHyperscore == 0)
267 return 0.0;
268 return (log10(m_protoHyperscore) * 4);
269 }
270 catch(PappsoException &exception_pappso)
271 {
272 QString errorStr =
273 QObject::tr("ERROR in getHyperscore, PAPPSO exception:\n%1").arg(exception_pappso.qwhat());
274 qDebug() << "XtandemHyperscore::getHyperscore PappsoException :\n" << errorStr;
275 throw PappsoException(errorStr);
276 }
277 catch(std::exception &exception_std)
278 {
279 QString errorStr =
280 QObject::tr("ERROR in getHyperscore, std exception:\n%1").arg(exception_std.what());
281 qDebug() << "XtandemHyperscore::getHyperscore std::exception :\n" << errorStr;
282 throw PappsoException(errorStr);
283 }
284}
Class to represent a mass spectrum.
virtual const QString & qwhat() const
void pushBackMatchSpectrum(std::vector< SimplePeakIonMatch > &peak_match_list, const MassSpectrum &spectrum, PrecisionPtr precision, Enums::PeptideIon ion_type, unsigned int charge) const
const QString getSequence() const override
print amino acid sequence without modifications
Definition peptide.cpp:255
std::map< char, pappso_double > AaFactorMap
std::vector< Enums::PeptideIon > m_ionList
unsigned int getMatchedIons(Enums::PeptideIon ion_type) const
bool computeXtandemHyperscore(const MassSpectrum &spectrum, const Peptide &peptide, unsigned int parent_charge)
unsigned int m_ionCount[PEPTIDE_ION_TYPE_COUNT]
unsigned int getXtandemPredictedIonIntensityFactor(const QString &sequence, Enums::PeptideIon ion_type, unsigned int size) const
XtandemHyperscoreBis(bool refine_spectrum_synthesis, PrecisionPtr precision, const std::vector< Enums::PeptideIon > &ion_list)
PeptideIon
Enums::PeptideIon enum defines all types of ions (Nter or Cter).
Definition types.h:286
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
double pappso_double
A type definition for doubles.
Definition types.h:60
bool peptideIonIsNter(Enums::PeptideIon ion_type)
tells if an ion is Nter
Definition peptide.cpp:87
const PrecisionBase * PrecisionPtr
Definition precision.h:122
unsigned int factorial(unsigned int n)
#define PEPTIDE_ION_TYPE_COUNT
only useful for internal use DO not change this value : it is used to define static array size
Definition types.h:478