libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
experimentalspectrum.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/processing/specglob/experimentalspectrum.cpp
3 * \date 08/11/2023
4 * \author Olivier Langella
5 * \brief transform a spectrum to SpecGlob spectra
6 *
7 * C++ implementation of the SpecGlob algorithm described in :
8 * 1. Prunier, G. et al. Fast alignment of mass spectra in large proteomics
9 * datasets, capturing dissimilarities arising from multiple complex
10 * modifications of peptides. BMC Bioinformatics 24, 421 (2023).
11 *
12 * HAL Id : hal-04296170 , version 1
13 * Mot de passe : hxo20cl
14 * DOI : 10.1186/s12859-023-05555-y
15 */
16
17/*
18 * SpecGlobTool, Spectra to peptide alignment tool
19 * Copyright (C) 2023 Olivier Langella
20 * <olivier.langella@universite-paris-saclay.fr>
21 *
22 * This program is free software: you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation, either version 3 of the License, or
25 * (at your option) any later version.
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
31 *
32 * You should have received a copy of the GNU General Public License
33 * along with this program. If not, see <http://www.gnu.org/licenses/>.
34 *
35 */
37#include <QDebug>
39#include <QObject>
40
41namespace pappso
42{
43namespace specglob
44{
46 pappso::PrecisionPtr precision_ptr)
47 : std::vector<ExperimentalSpectrumDataPoint>()
48{
49 m_qualifiedMassSpectrum = qmass_spectrum;
50 m_precisionPtr = precision_ptr;
52}
53
55 pappso::PrecisionPtr precision_ptr,
56 double precursor_mass_error)
57 : std::vector<ExperimentalSpectrumDataPoint>()
58{
59 m_qualifiedMassSpectrum = qmass_spectrum;
60 m_precisionPtr = precision_ptr;
61 createSymetricPeakList(precursor_mass_error);
62}
63
71
75
76void
81
82void
84{
85
86 bool ok;
87 auto charge = m_qualifiedMassSpectrum.getPrecursorCharge(&ok);
88 if(!ok)
89 {
91 QObject::tr("precursor charge is not defined in spectrum %1")
92 .arg(m_qualifiedMassSpectrum.getMassSpectrumId().getNativeId()));
93 }
94
95 double mz_prec = m_qualifiedMassSpectrum.getPrecursorMz(&ok);
96 if(!ok)
97 {
99 QObject::tr("precursor m/z is not defined in spectrum %1")
100 .arg(m_qualifiedMassSpectrum.getMassSpectrumId().getNativeId()));
101 }
102
103 // compute precursor mass given the charge state
104 m_precursorMass = mz_prec * (double)charge - precursor_mass_error;
105 m_precursorMass -= pappso::MHPLUS * (double)charge;
107
108 std::vector<double> mz_list = m_qualifiedMassSpectrum.getMassSpectrumCstSPtr().get()->xValues();
109
110 std::size_t mz_current_indice = 0;
111 auto itend = m_qualifiedMassSpectrum.getMassSpectrumCstSPtr().get()->end();
112 for(std::vector<pappso::DataPoint>::const_iterator it =
113 m_qualifiedMassSpectrum.getMassSpectrumCstSPtr().get()->begin();
114 it != itend;
115 it++)
116 {
117 double current_mz = it->x;
118
119 double symmetric_current_mz = getSymetricMz(current_mz);
120
121 auto itpair_symmetric = findMz(symmetric_current_mz);
122 if(itpair_symmetric != itend)
123 {
124 // there is a counterpart
125 push_back({ExperimentalSpectrumDataPointType::both, it->x, 0});
126 qDebug() << "current_mz=" << current_mz << " both";
127 }
128 else
129 {
130 // there is no counterpart
131 push_back({ExperimentalSpectrumDataPointType::native, it->x, 0});
132 push_back({ExperimentalSpectrumDataPointType::symmetric, symmetric_current_mz, 0});
133 qDebug() << "current_mz=" << current_mz << " symmetrics";
134 }
135
136 mz_current_indice++;
137 }
138
139 // we add a peak with NT mass (1.0078) if it is not detected, to give better
140 // chance to align the first amino acid in b if it is present
141 if(findMz(pappso::MPROTIUM) == itend)
142 {
144 }
145
146 // We add the B peak corresponding to the precursor (complete peptide)
147 double precusorBion = m_targetMzSum - pappso::MASSH2O - pappso::MPROTIUM;
148
149 if(findMz(precusorBion) == itend)
150 {
151 push_back({ExperimentalSpectrumDataPointType::synthetic, precusorBion, 0});
152 }
153
154 std::sort(begin(),
155 end(),
157 return (a.peak_mz < b.peak_mz);
158 });
159
160 std::size_t i = 0;
161 for(auto &data_point : *this)
162 {
163 data_point.indice = i;
164 i++;
165 }
166}
167
168std::vector<pappso::DataPoint>::const_iterator
170{
171 pappso::MzRange mz_range(mz, m_precisionPtr);
172 auto itend = m_qualifiedMassSpectrum.getMassSpectrumCstSPtr().get()->end();
173 auto it =
174 findFirstEqualOrGreaterX(m_qualifiedMassSpectrum.getMassSpectrumCstSPtr().get()->begin(),
175 m_qualifiedMassSpectrum.getMassSpectrumCstSPtr().get()->end(),
176 mz_range.lower());
177
178 if(it != itend)
179 {
180 if(it->x <= mz_range.upper())
181 {
182 return it;
183 }
184 }
185 return itend;
186}
187
188double
193
194std::vector<double>
196{
197 std::vector<double> mass_list;
198 for(const ExperimentalSpectrumDataPoint &n : *this)
199 {
200 mass_list.push_back(n.peak_mz);
201 }
202
203 return mass_list;
204}
205
206double
208{
209 return m_targetMzSum - mz;
210}
211
212std::vector<double>
214{
215 std::vector<double> mass_list;
216 for(const ExperimentalSpectrumDataPoint &n : *this)
217 {
218 if(n.type == type)
219 mass_list.push_back(n.peak_mz);
220 }
221
222 return mass_list;
223}
224
225QString
227{
228 QStringList all_element;
229 for(const ExperimentalSpectrumDataPoint &n : *this)
230 {
231 all_element << QString("%1 %2").arg(n.peak_mz).arg((std::uint8_t)n.type);
232 }
233 return QString("[%1]").arg(all_element.join("] ["));
234}
235
236double
241
242std::vector<ExperimentalSpectrumDataPoint>::const_reverse_iterator
244 const pappso::MzRange &aaTheoMzRange) const
245{
246
247 qDebug() << "start_position" << start_position << " lookfor=" << aaTheoMzRange.getMz();
248 std::vector<ExperimentalSpectrumDataPoint>::const_reverse_iterator itrbegin =
249 rbegin() + (size() - 1 - start_position);
250
251 qDebug() << itrbegin->indice << "mz=" << itrbegin->peak_mz;
252 double eperimentalMzReference = itrbegin->peak_mz;
253 auto itrend = this->rend();
254 // We check all row from j to 0
255 qDebug();
256 for(auto itr = itrbegin + 1; itr != itrend; ++itr)
257 {
258 qDebug() << itr->indice;
259 double experimentalMzDifference = eperimentalMzReference - itr->peak_mz;
260
261 if(experimentalMzDifference > aaTheoMzRange.upper())
262 {
263 // if we pass the mass of the theoretical amino acid, we stop to not
264 // over
265 // calculate
266 qDebug() << experimentalMzDifference << ">" << aaTheoMzRange.upper();
267 return itrend;
268 }
269 else if(experimentalMzDifference < aaTheoMzRange.lower())
270 {
271 continue;
272 }
273
274 qDebug() << itr->indice << " diff=" << experimentalMzDifference;
275 // if we found that j-k give an amino acid, we keep k value
276 return itr;
277 }
278 qDebug() << "rend";
279 return itrend; // a value of -1 to show that
280 // there is no k value
281}
282
288} // namespace specglob
289} // namespace pappso
pappso_double getMz() const
Definition mzrange.cpp:114
pappso_double lower() const
Definition mzrange.h:71
pappso_double upper() const
Definition mzrange.h:77
Class representing a fully specified mass spectrum.
double getSymetricMz(double mz) const
compute the symmetric mass for debuggin purpose
const pappso::QualifiedMassSpectrum & getQualifiedMassSpectrum() const
std::vector< ExperimentalSpectrumDataPoint >::const_reverse_iterator reverseFindDiffMz(std::size_t start_position, const pappso::MzRange &targeted_mass_range) const
find the peak for wich mass difference from rbegin corresponds to aaTheoMass Find if a peak back in t...
ExperimentalSpectrum(const pappso::QualifiedMassSpectrum &qmass_spectrum, pappso::PrecisionPtr precision_ptr)
void createSymetricPeakList()
add symmetric peaks to the spectrum Create a SymetricPeakList that contain symmetric peaks and the in...
std::vector< pappso::DataPoint >::const_iterator findMz(double mz)
find the correspondin mz in the mass spectrum (given the precision)
pappso::QualifiedMassSpectrum m_qualifiedMassSpectrum
ExperimentalSpectrumDataPointType
Definition types.h:78
@ synthetic
does not correspond to existing peak, for computational purpose
Definition types.h:85
@ both
both, the ion and the complement exists in the original spectrum
Definition types.h:83
@ symmetric
new peak : computed symmetric mass from a corresponding native peak
Definition types.h:81
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
std::vector< DataPoint >::iterator findFirstEqualOrGreaterX(std::vector< DataPoint >::iterator begin, std::vector< DataPoint >::iterator end, const double &value)
find the first element in which X is equal or greater than the value searched important : it implies ...
Definition trace.cpp:70
const pappso_double MHPLUS(1.007276466879)
const pappso_double MPROTIUM(1.007825032241)
const pappso_double MASSH2O((MPROTIUM *2)+MASSOXYGEN)
const PrecisionBase * PrecisionPtr
Definition precision.h:122