libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
peptide.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/masschroq/peptide.cpp
3 * \date 24/09/2024
4 * \author Olivier Langella
5 * \brief peptide model in masschroqlite
6 */
7
8/*******************************************************************************
9 * Copyright (c) 2024 Olivier Langella
10 *<Olivier.Langella@universite-paris-saclay.fr>.
11 *
12 * This file is part of MassChroQ.
13 *
14 * MassChroQ is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * MassChroQ is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with MassChroQ. If not, see <http://www.gnu.org/licenses/>.
26 *
27 ******************************************************************************/
28
29#include "peptide.h"
33#include "msrungroup.h"
34#include "peptidelabel.h"
35
37 const pappso::PeptideSp &peptide_sp,
38 const std::vector<ProteinSp> &protein_list)
39 : PeptideBase(peptide_sp), m_id(id), m_proteinSpList(protein_list)
40{
41}
42
48
54
55void
57{
58 qDebug();
59 if(ni_min_abundance > 0)
60 {
61 if(m_peptideLabelMap.size() > 0)
62 {
63 qDebug();
64 for(auto &pair_label : m_peptideLabelMap)
65 {
66 qDebug() << pair_label.second.get();
67 pair_label.second->computeIsotopologues(ni_min_abundance);
68 qDebug();
69 }
70 qDebug();
71 }
72 else
73 {
74 qDebug();
75 PeptideBase::computeIsotopologues(ni_min_abundance);
76 }
77 }
78 qDebug();
79}
80
81const QString &
83{
84 return m_id;
85}
86
87void
89{
90 m_mods = mods;
91}
92
93const QString &
98
99const std::map<QString, pappso::masschroq::PeptideLabelSp> &
104
105void
107{
109 std::find(m_allObservedChargeStateList.begin(), m_allObservedChargeStateList.end(), charge))
110 {
111 m_allObservedChargeStateList.push_back(charge);
112 }
113}
114
115const std::vector<std::uint8_t> &
120
121
122void
124{
125 auto it = std::find(m_observedInMsRunSpList.begin(), m_observedInMsRunSpList.end(), msrun_sp);
126 if(it == m_observedInMsRunSpList.end())
127 {
128 m_observedInMsRunSpList.push_back(msrun_sp);
129 }
130}
131
132
133const std::vector<pappso::masschroq::ProteinSp> &
138
139void
141 const PeptideMeasurements::Measurement &one_xic_measure,
142 const pappso::MsRunRetentionTime<QString> &msrun_retention_time)
143{
144 if(one_xic_measure.m_tracePeakSp.get() != nullptr)
145 {
147 position.intensity = one_xic_measure.m_tracePeakSp.get()->getMaxXicElement().y;
148 if(msrun_retention_time.isAligned())
149 {
150 position.alignedRetentionTime =
151 msrun_retention_time.translateOriginal2AlignedRetentionTime(
152 one_xic_measure.m_tracePeakSp.get()->getMaxXicElement().x);
154 msrun_retention_time.translateOriginal2AlignedRetentionTime(
155 (one_xic_measure.m_tracePeakSp.get()->getLeftBoundary().x +
156 one_xic_measure.m_tracePeakSp.get()->getRightBoundary().x) /
157 2);
158 }
159 else
160 {
161 position.alignedRetentionTime = one_xic_measure.m_tracePeakSp.get()->getMaxXicElement().x;
163 ((one_xic_measure.m_tracePeakSp.get()->getLeftBoundary().x +
164 one_xic_measure.m_tracePeakSp.get()->getRightBoundary().x) /
165 2);
166 }
167 /*
168 position.alignedRetentionTime =
169 position.alignedRetentionTime +
170 ((position.alignedRetentionTimeCenter - position.alignedRetentionTime) /
171 4);*/
172 position.wide = one_xic_measure.m_tracePeakSp.get()->getArea();
173 // one_xic_measure.m_tracePeakSp.get()->getRightBoundary().x -
174 // one_xic_measure.m_tracePeakSp.get()->getLeftBoundary().x;
175 m_alignedPeakPositionElementList.push_back(position);
176 }
177}
178
179void
181 const pappso::masschroq::PeptideObservation &peptide_observation,
182 const pappso::MsRunRetentionTime<QString> &msrun_retention_time)
183{
184 double best_rt = peptide_observation.getBestXicCoord().get()->rtTarget;
185 if(msrun_retention_time.isAligned())
186 {
187 best_rt = msrun_retention_time.translateOriginal2AlignedRetentionTime(best_rt);
188 }
189
190 m_referenceMs2ObservationList.push_back(best_rt);
191}
192
193void
195{
197
199 {
200 std::sort(m_alignedPeakPositionElementList.begin(),
203 return a.wide > b.wide;
204 });
205
206 // take only the 90% best measures
207 std::size_t limit = m_alignedPeakPositionElementList.size() * 0.9;
208 if(limit < 5)
209 {
211 // throw pappso::PappsoException("limit < 3");
212 }
213 double total_intensity = std::accumulate(m_alignedPeakPositionElementList.begin(),
214 m_alignedPeakPositionElementList.begin() + limit,
215 (double)0.0,
216 [](double sum, AlignedPeakPositionElement &element) {
217 sum += element.intensity;
218 return (sum);
219 });
220 double sum_rt = std::accumulate(m_alignedPeakPositionElementList.begin(),
221 m_alignedPeakPositionElementList.begin() + limit,
222 (double)0.0,
223 [](double sum, AlignedPeakPositionElement &element) {
224 sum += element.intensity * element.alignedRetentionTime;
225 return (sum);
226 });
227
228 m_consensusAlignedPeakRetentionTime = sum_rt / total_intensity;
229 }
231
232 double sum_rt = std::accumulate(
235
237}
238
239bool
241{
242 auto it =
243 std::find_if(m_observedInMsRunSpList.begin(),
245 [msrun_p](const pappso::masschroq::MsRunSp &a) { return (a.get() == msrun_p); });
246 if(it == m_observedInMsRunSpList.end())
247 return false;
248 return true;
249}
250
251void
253 const pappso::MsRunRetentionTime<QString> *msrun_retention_time_reference_p)
254{
255 mp_referenceMsRunRetentionTime = msrun_retention_time_reference_p;
256}
257
258double
263
264double
269
270
271void
277
278
281 const pappso::masschroq::MsRunGroup *msrun_group_p, std::uint8_t charge) const
282{
283 // get XIC coordinates of the most intense precursor
284 pappso::pappso_double intensity = -1;
285 pappso::XicCoordSPtr best_xic_coord;
286
287 for(auto &xic_coord_charge : m_msRunXicCoordChargeList)
288 {
289 if(msrun_group_p->contains(xic_coord_charge.msrun_p))
290 {
291 if(xic_coord_charge.charge == charge)
292 {
293 if(xic_coord_charge.intensity > intensity)
294 {
295 intensity = xic_coord_charge.intensity;
296 best_xic_coord = xic_coord_charge.xic_coord_sp;
297 qDebug();
298 }
299 }
300 }
301 }
302
303 return best_xic_coord;
304}
305
306
307void
309 pappso::IonMobilityGrid *ion_mobility_grid_p) const
310{
311
312 for(auto &xic_coord_charge_a : m_msRunXicCoordChargeList)
313 {
314 // qInfo() << " observed_in_a";
315 const pappso::MsRunId &msrun_id_a =
316 *(xic_coord_charge_a.msrun_p->getMsRunReaderSPtr().get()->getMsRunId().get());
317 pappso::XicCoordSPtr xic_coord_a = xic_coord_charge_a.xic_coord_sp;
318
319 for(auto &xic_coord_charge_b : m_msRunXicCoordChargeList)
320 {
321 if(&xic_coord_charge_a == &xic_coord_charge_b)
322 {
323 break;
324 }
325 else
326 {
327
328 // qInfo() << " observed_in_b";
329 const pappso::MsRunId &msrun_id_b =
330 *(xic_coord_charge_b.msrun_p->getMsRunReaderSPtr().get()->getMsRunId().get());
331 if(msrun_id_b == msrun_id_a)
332 {
333 }
334 else
335 {
336 pappso::XicCoordSPtr xic_coord_b = xic_coord_charge_b.xic_coord_sp;
337
338 if(xic_coord_charge_a.charge == xic_coord_charge_b.charge)
339 {
340 ion_mobility_grid_p->storeObservedIdentityBetween(
341 msrun_id_a, xic_coord_a.get(), msrun_id_b, xic_coord_b.get());
342 }
343 }
344 }
345 }
346 }
347}
348
349
352 const pappso::masschroq::MsRunGroup &msrun_group,
353 const pappso::MsRunId &targeted_msrun,
354 std::uint8_t charge) const
355{
356 pappso::XicCoordSPtr xic_coord_mean;
357 std::size_t count = 0;
358 pappso::IonMobilityGrid *ion_mobility_grid_p = msrun_group.getIonMobilityGridSp().get();
359
360 for(auto &msrun_xic_coord_charge : m_msRunXicCoordChargeList)
361 {
362 if(msrun_group.contains(msrun_xic_coord_charge.msrun_p))
363 {
364
365 if(msrun_xic_coord_charge.charge == charge)
366 {
367 // compute the mean coordinate :
368 pappso::XicCoordSPtr xic_coord_to_add = msrun_xic_coord_charge.xic_coord_sp;
369
370 if(ion_mobility_grid_p != nullptr)
371 {
372 // ion mobility coordinate translation for the targeted msrun
373 xic_coord_to_add = ion_mobility_grid_p->translateXicCoordFromTo(
374 *xic_coord_to_add.get(),
375 *(msrun_xic_coord_charge.msrun_p->getMsRunReaderSPtr()
376 .get()
377 ->getMsRunId()
378 .get()),
379 targeted_msrun);
380 }
381
382 if(xic_coord_mean.get() == nullptr)
383 {
384 xic_coord_mean = xic_coord_to_add.get()->initializeAndClone();
385 }
386 else
387 {
388 xic_coord_mean = xic_coord_mean.get()->addition(xic_coord_to_add);
389 }
390 count++;
391 qDebug() << " xic_coord_mean.get()->toString=" << xic_coord_mean.get()->toString();
392 }
393 }
394 }
395 if(xic_coord_mean.get() != nullptr)
396 {
397 xic_coord_mean = xic_coord_mean.get()->divideBy(count);
398 }
399
400
401 return xic_coord_mean;
402}
403
404void
405pappso::masschroq::Peptide::setJsonLabelList(const QJsonObject &json_label_list)
406{
407 auto it = json_label_list.begin();
408
409 while(it != json_label_list.end())
410 {
411 QString label = it.key();
412
413 QString proforma = it.value().toObject().value("proforma").toString();
414
415 pappso::masschroq::PeptideLabelSp peptide_label_sp;
416
417 if(proforma.isEmpty())
418 {
420 QObject::tr("ERROR: label %1 %2 must contain proforma sequence").arg(label).arg(m_id));
421 }
422 else
423 {
424 peptide_label_sp = std::make_shared<pappso::masschroq::PeptideLabel>(
425 pappso::PeptideProFormaParser::parseString(proforma), this, label);
426 }
427 m_peptideLabelMap.insert({label, peptide_label_sp});
428 it++;
429 }
430}
431
434{
435 auto it = m_peptideLabelMap.find(label);
436 if(it == m_peptideLabelMap.end())
437 {
439 QObject::tr("ERROR: label %1 not found in peptide %2").arg(label).arg(m_id));
440 }
441 return it->second.get();
442}
pappso::XicCoordSPtr translateXicCoordFromTo(const pappso::XicCoord &source_xic_coord, const MsRunId &source_msrunid, const MsRunId &target_msrunid) const
void storeObservedIdentityBetween(const MsRunId &msrun_ida, const XicCoord *xic_coorda, const MsRunId &msrun_idb, const XicCoord *xic_coordb)
MS run identity MsRunId identifies an MS run with a unique ID (XmlId) and contains eventually informa...
Definition msrunid.h:54
double translateOriginal2AlignedRetentionTime(double original_retention_time) const
static PeptideSp parseString(const QString &pepstr)
bool contains(const MsRun *msrun_p) const
const std::shared_ptr< pappso::IonMobilityGrid > & getIonMobilityGridSp() const
const pappso::PeptideSp msp_peptide
Definition peptidebase.h:88
virtual void computeIsotopologues(double ni_min_abundance)
compute possible isotopes for this molecule
PeptideBase(const pappso::PeptideSp &peptide_sp)
pappso::PeptideNaturalIsotopeList * mpa_peptideNaturalIsotopeList
Definition peptidebase.h:89
pappso::XicCoordSPtr getBestXicCoord() const
double m_consensusAlignedPeakRetentionTime
Definition peptide.h:245
void computeConsensusRetentionTime()
compute consensus retention time (on MS2 observations and MS1 peak measurements) the computation is b...
Definition peptide.cpp:194
const QString & getMods() const
get optional information as text
Definition peptide.cpp:94
void addObservedChargeState(std::uint8_t charge)
Definition peptide.cpp:106
std::vector< std::uint8_t > m_allObservedChargeStateList
Definition peptide.h:240
void populateIonMobilityGrid(pappso::IonMobilityGrid *ion_mobility_grid_p) const
Populate ion mobility grid with observed XIC coordinates for this peptide on all MSruns The ion mobil...
Definition peptide.cpp:308
Peptide(const QString &id, const pappso::PeptideSp &peptide_sp, const std::vector< ProteinSp > &protein_list)
constructor
Definition peptide.cpp:36
std::vector< MsRunXicCoordCharge > m_msRunXicCoordChargeList
Definition peptide.h:251
virtual void computeIsotopologues(double ni_min_abundance) override
compute possible isotopes for this molecule
Definition peptide.cpp:56
void addMsRunXicCoordCharge(const MsRunXicCoordCharge &msrun_xic_coord)
Definition peptide.cpp:272
std::vector< double > m_referenceMs2ObservationList
Definition peptide.h:249
bool isObservedInMsRunSp(const MsRun *msrun_p)
tell if this peptide is observed (MS2 fragmentation and identification) in this msrun
Definition peptide.cpp:240
const std::vector< ProteinSp > m_proteinSpList
Definition peptide.h:238
void setJsonLabelList(const QJsonObject &json_label_list)
build peptide label map from JSON label_list object
Definition peptide.cpp:405
void setMods(const QString &mods)
set optional information as text to this peptide
Definition peptide.cpp:88
const std::vector< std::uint8_t > & getAllObservedChargeStateList() const
Definition peptide.cpp:116
PeptideLabel * getPeptideLabelPtr(const QString &label) const
get a peptide label pointer with the corresponding label identifier
Definition peptide.cpp:433
const std::vector< ProteinSp > & getProteinSpList() const
Definition peptide.cpp:134
const QString & getId() const
get peptide unique identifier
Definition peptide.cpp:82
double getConsensusMs2RetentionTime() const
get consensus retention time based on MS2 fragmenation and identification events
Definition peptide.cpp:265
std::vector< AlignedPeakPositionElement > m_alignedPeakPositionElementList
Definition peptide.h:243
pappso::XicCoordSPtr getBestXicCoordSPtrForChargeInMsRunGroup(const MsRunGroup *msrun_group_p, std::uint8_t charge) const
get the XIC coordinates of the higher observed intensity for this peptide and charge in other MS run ...
Definition peptide.cpp:280
void setReferenceMsRunRetentionTimePtr(const pappso::MsRunRetentionTime< QString > *msrun_retention_time_reference_p)
sets the current msrun retention time reference
Definition peptide.cpp:252
const std::map< QString, PeptideLabelSp > & getPeptideLabelMap() const
get the peptide label label_list
Definition peptide.cpp:100
double m_consensusAlignedMs2RetentionTime
Definition peptide.h:246
std::vector< MsRunSp > m_observedInMsRunSpList
Definition peptide.h:241
double getConsensusPeakRetentionTime() const
get consensus retention time based on XIC peak measurements
Definition peptide.cpp:259
void addAlignedPeptideObservation(const PeptideObservation &peptide_observation, const pappso::MsRunRetentionTime< QString > &msrun_retention_time)
accumulate retention time information for MS2 observation convenient function used while collecting d...
Definition peptide.cpp:180
std::map< QString, PeptideLabelSp > m_peptideLabelMap
Definition peptide.h:253
void addAlignedPeakMeasurement(const PeptideMeasurements::Measurement &one_xic_measure, const pappso::MsRunRetentionTime< QString > &msrun_retention_time)
accumulate retention time information for MS1 peak measurement
Definition peptide.cpp:140
const pappso::MsRunRetentionTime< QString > * mp_referenceMsRunRetentionTime
Definition peptide.h:248
pappso::XicCoordSPtr getBestIonMobilityXicCoordToExtractOverallMsRunGroup(const MsRunGroup &msrun_group, const pappso::MsRunId &targeted_msrun, std::uint8_t charge) const
get ion mobility coordinates corrected against other MSruns in the group
Definition peptide.cpp:351
void addObservedInMsRunSp(const MsRunSp &msrun_sp)
Definition peptide.cpp:123
std::shared_ptr< PeptideLabel > PeptideLabelSp
Definition peptide.h:52
@ a
peak detected using a single direct MS2 observation
Definition types.h:46
std::shared_ptr< MsRun > MsRunSp
Definition msrun.h:44
std::shared_ptr< const Peptide > PeptideSp
double pappso_double
A type definition for doubles.
Definition types.h:60
std::shared_ptr< XicCoord > XicCoordSPtr
Definition xiccoord.h:44
internal structure to compute consensus retention times
Definition peptide.h:145
internal structure to store msrun + charge + intensity + xic coordinate
Definition peptide.h:207