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 = std::find_if(m_observedInMsRunSpList.begin(),
244 [msrun_p](const pappso::masschroq::MsRunSp &a) { return (a.get() == msrun_p); });
245 if(it == m_observedInMsRunSpList.end())
246 return false;
247 return true;
248}
249
250void
252 const pappso::MsRunRetentionTime<QString> *msrun_retention_time_reference_p)
253{
254 mp_referenceMsRunRetentionTime = msrun_retention_time_reference_p;
255}
256
257double
262
263double
268
269
270void
275
276
279 std::uint8_t charge) const
280{
281 // get XIC coordinates of the most intense precursor
282 pappso::pappso_double intensity = -1;
283 pappso::XicCoordSPtr best_xic_coord;
284
285 for(auto &xic_coord_charge : m_msRunXicCoordChargeList)
286 {
287 if(msrun_group_p->contains(xic_coord_charge.msrun_p))
288 {
289 if(xic_coord_charge.charge == charge)
290 {
291 if(xic_coord_charge.intensity > intensity)
292 {
293 intensity = xic_coord_charge.intensity;
294 best_xic_coord = xic_coord_charge.xic_coord_sp;
295 qDebug();
296 }
297 }
298 }
299 }
300
301 return best_xic_coord;
302}
303
304
305void
307{
308
309 for(auto &xic_coord_charge_a : m_msRunXicCoordChargeList)
310 {
311 // qInfo() << " observed_in_a";
312 const pappso::MsRunId &msrun_id_a =
313 *(xic_coord_charge_a.msrun_p->getMsRunReaderSPtr().get()->getMsRunId().get());
314 pappso::XicCoordSPtr xic_coord_a = xic_coord_charge_a.xic_coord_sp;
315
316 for(auto &xic_coord_charge_b : m_msRunXicCoordChargeList)
317 {
318 if(&xic_coord_charge_a == &xic_coord_charge_b)
319 {
320 break;
321 }
322 else
323 {
324
325 // qInfo() << " observed_in_b";
326 const pappso::MsRunId &msrun_id_b =
327 *(xic_coord_charge_b.msrun_p->getMsRunReaderSPtr().get()->getMsRunId().get());
328 if(msrun_id_b == msrun_id_a)
329 {
330 }
331 else
332 {
333 pappso::XicCoordSPtr xic_coord_b = xic_coord_charge_b.xic_coord_sp;
334
335 if(xic_coord_charge_a.charge == xic_coord_charge_b.charge)
336 {
337 ion_mobility_grid_p->storeObservedIdentityBetween(
338 msrun_id_a, xic_coord_a.get(), msrun_id_b, xic_coord_b.get());
339 }
340 }
341 }
342 }
343 }
344}
345
346
349 const pappso::masschroq::MsRunGroup &msrun_group,
350 const pappso::MsRunId &targeted_msrun,
351 std::uint8_t charge) const
352{
353 pappso::XicCoordSPtr xic_coord_mean;
354 std::size_t count = 0;
355 pappso::IonMobilityGrid *ion_mobility_grid_p = msrun_group.getIonMobilityGridSp().get();
356
357 for(auto &msrun_xic_coord_charge : m_msRunXicCoordChargeList)
358 {
359 if(msrun_group.contains(msrun_xic_coord_charge.msrun_p))
360 {
361
362 if(msrun_xic_coord_charge.charge == charge)
363 {
364 // compute the mean coordinate :
365 pappso::XicCoordSPtr xic_coord_to_add = msrun_xic_coord_charge.xic_coord_sp;
366
367 if(ion_mobility_grid_p != nullptr)
368 {
369 // ion mobility coordinate translation for the targeted msrun
370 xic_coord_to_add = ion_mobility_grid_p->translateXicCoordFromTo(
371 *xic_coord_to_add.get(),
372 *(msrun_xic_coord_charge.msrun_p->getMsRunReaderSPtr()
373 .get()
374 ->getMsRunId()
375 .get()),
376 targeted_msrun);
377 }
378
379 if(xic_coord_mean.get() == nullptr)
380 {
381 xic_coord_mean = xic_coord_to_add.get()->initializeAndClone();
382 }
383 else
384 {
385 xic_coord_mean = xic_coord_mean.get()->addition(xic_coord_to_add);
386 }
387 count++;
388 qDebug() << " xic_coord_mean.get()->toString=" << xic_coord_mean.get()->toString();
389 }
390 }
391 }
392 if(xic_coord_mean.get() != nullptr)
393 {
394 xic_coord_mean = xic_coord_mean.get()->divideBy(count);
395 }
396
397
398 return xic_coord_mean;
399}
400
401void
402pappso::masschroq::Peptide::setJsonLabelList(const QJsonObject &json_label_list)
403{
404 auto it = json_label_list.begin();
405
406 while(it != json_label_list.end())
407 {
408 QString label = it.key();
409
410 QString proforma = it.value().toObject().value("proforma").toString();
411
412 pappso::masschroq::PeptideLabelSp peptide_label_sp;
413
414 if(proforma.isEmpty())
415 {
417 QObject::tr("ERROR: label %1 %2 must contain proforma sequence").arg(label).arg(m_id));
418 }
419 else
420 {
421 peptide_label_sp = std::make_shared<pappso::masschroq::PeptideLabel>(
422 pappso::PeptideProFormaParser::parseString(proforma), this, label);
423 }
424 m_peptideLabelMap.insert({label, peptide_label_sp});
425 it++;
426 }
427}
428
431{
432 auto it = m_peptideLabelMap.find(label);
433 if(it == m_peptideLabelMap.end())
434 {
436 QObject::tr("ERROR: label %1 not found in peptide %2").arg(label).arg(m_id));
437 }
438 return it->second.get();
439}
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:306
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:271
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:402
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:430
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:264
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:278
void setReferenceMsRunRetentionTimePtr(const pappso::MsRunRetentionTime< QString > *msrun_retention_time_reference_p)
sets the current msrun retention time reference
Definition peptide.cpp:251
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:258
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:348
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:61
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