libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
msrunpeptidelist.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/masschroq/msrunpeptidelist.cpp
3 * \date 25/09/2024
4 * \author Olivier Langella
5 * \brief msrun model including fragmented peptides 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 "msrunpeptidelist.h"
32#include <QtConcurrent>
33
38
44
48
49void
53 std::size_t spectrum_index,
54 std::uint8_t charge)
55{
56
57 auto it = m_peptideObservationList.insert(
58 {peptide_sp.get(), std::make_shared<pappso::masschroq::PeptideObservation>(peptide_sp)});
60 msp_msRun.get()->getPrecursorSPtrBySpectrumIndex(spectrum_index);
61 it.first->second.get()->addObservation({spectrum_index, charge, precursor_sp, true, p_label});
62
63 peptide_sp.get()->addMsRunXicCoordCharge({msp_msRun.get(),
64 precursor_sp.get()->getXicCoordSPtr(),
65 charge,
66 precursor_sp.get()->getIntensity()});
67 qDebug() << "m_peptideObservationList.size()=" << m_peptideObservationList.size();
68}
69
70void
74 std::size_t scan_number,
75 std::uint8_t charge)
76{
77
78 auto it = m_peptideObservationList.insert(
79 {peptide_sp.get(), std::make_shared<pappso::masschroq::PeptideObservation>(peptide_sp)});
81 msp_msRun.get()->getPrecursorSPtrByScanNumber(scan_number);
82 it.first->second.get()->addObservation({scan_number, charge, precursor_sp, false, p_label});
83
84 peptide_sp.get()->addMsRunXicCoordCharge({msp_msRun.get(),
85 precursor_sp.get()->getXicCoordSPtr(),
86 charge,
87 precursor_sp.get()->getIntensity()});
88 qDebug() << "m_peptideObservationList.size()=" << m_peptideObservationList.size();
89}
90
91void
93 const QString &tmp_dir,
95 const QuantificationMethodSp &quantification_method)
96{
98 ui_monitor.appendText(
99 QString("Starting quantification for msrun %1")
100 .arg(msp_msRun.get()->getMsRunReaderSPtr()->getMsRunId().get()->getFileName()));
101
102 qDebug() << m_peptideObservationList.size();
104
105 qDebug();
108
109 qDebug();
110 ui_monitor.appendText(QString("Preparing extraction list"));
111 std::vector<pappso::XicCoordSPtr> xic_coord_list =
112 buildXicCoordList(msrun_group_p, quantification_method);
113
114 ui_monitor.appendText(QString("Preparing extraction list done"));
115
116 ui_monitor.appendText(QString("Building XIC extractor"));
119 msp_msRun.get()->getMsRunReaderSPtr());
120
121 qDebug();
122 extractor_pwiz->setXicExtractMethod(quantification_method.get()->getXicExtractMethod());
123
124 // qWarning() << quantification_method.get()->getXicExtractionRtRange();
125
126 extractor_pwiz.get()->setRetentionTimeAroundTarget(
127 quantification_method.get()->getXicExtractionRtRange());
128
129 qDebug();
130 pappso::FilterInterfaceCstSPtr csp_filter_suite = quantification_method.get()->getXicFilter();
131
132 qDebug();
133 extractor_pwiz.get()->setPostExtractionTraceFilterCstSPtr(csp_filter_suite);
134
135 qDebug();
136
137 ui_monitor.appendText(QString("Building XIC extractor done"));
138 ui_monitor.appendText(QString("Extracting"));
139 extractor_pwiz.get()->extractXicCoordSPtrListParallelized(ui_monitor, xic_coord_list);
140
141 // qWarning() << "size of first xic=" << xic_coord_list.at(0).get()->xicSptr.get()->size();
142 qDebug();
143
144 detectQuantifyPeaks(ui_monitor, quantification_method);
145
146
147 ui_monitor.appendText(
148 QString("Quantification for msrun %1 done")
149 .arg(msp_msRun.get()->getMsRunReaderSPtr()->getMsRunId().get()->getFileName()));
150}
151
152
153std::vector<pappso::XicCoordSPtr>
155 const pappso::masschroq::MsRunGroup *msrun_group_p,
156 const QuantificationMethodSp &quantification_method)
157{
158 std::vector<pappso::XicCoordSPtr> xic_coord_list;
159
160 for(auto pair_peptide : m_peptideObservationList)
161 {
162 pappso::masschroq::PeptideObservationSp peptide_events_sp = pair_peptide.second;
163
165 msrun_group_p, quantification_method, pair_peptide.second, xic_coord_list);
166 // peptide_events_sp.get()
167 }
168
169
170 return xic_coord_list;
171}
172
173void
175 const pappso::masschroq::MsRunGroup *msrun_group_p,
176 const QuantificationMethodSp &quantification_method,
177 const pappso::masschroq::PeptideObservationSp &peptide_events_sp,
178 std::vector<pappso::XicCoordSPtr> &xic_coord_list)
179{
180 PeptideMeasurementsSp peptide_measurements =
181 std::make_shared<pappso::masschroq::PeptideMeasurements>(peptide_events_sp);
182
183 m_peptideMeasurementsList.push_back(peptide_measurements);
184
185 peptide_measurements.get()->prepareMeasurements(
186 *(msp_msRun.get()->getMsRunReaderSPtr().get()->getMsRunId().get()),
187 msrun_group_p,
188 quantification_method);
189 peptide_measurements.get()->pushBackXicCoordList(xic_coord_list);
190}
191
192void
194 pappso::UiMonitorInterface &m_uiMonitor, const QuantificationMethodSp &quantification_method)
195{
196
197 m_uiMonitor.appendText(QString("Detect and quantify peak"));
198 /*
199 for(auto &measure : m_peptideMeasurementsList)
200 {
201 measure->detectQuantifyPeaks(quantification_method);
202 }
203 */
204
205 std::function<void(const pappso::masschroq::PeptideMeasurementsSp &)> mapdetectQuantifyPeaks =
206 [quantification_method](const pappso::masschroq::PeptideMeasurementsSp &measure) {
207 measure->detectQuantifyPeaks(quantification_method);
208 };
209
210
211 QFuture<void> res =
212 QtConcurrent::map<std::vector<pappso::masschroq::PeptideMeasurementsSp>::iterator>(
213 m_peptideMeasurementsList.begin(), m_peptideMeasurementsList.end(), mapdetectQuantifyPeaks);
214 res.waitForFinished();
215
216
217 m_uiMonitor.appendText(QString("Detect and quantify peak done"));
218}
219
220
226
227void
229{
230
231 for(auto &measure : m_peptideMeasurementsList)
232 {
233 measure.get()->flushXics();
234 }
235
236 for(auto &mbr_measure : m_mbrPeptideMeasurementsList)
237 {
238 mbr_measure.get()->flushXics();
239 }
240}
241
242std::shared_ptr<pappso::MsRunRetentionTime<QString>> &
244 const pappso::masschroq::AlignmentMethodSp &alignment_method)
245{
247 std::make_shared<pappso::MsRunRetentionTime<QString>>(msp_msRun->getRetentionTimeLine());
248
249 msp_msRunRetentionTime.get()->setMs2MedianFilter(
250 pappso::FilterMorphoMedian(alignment_method.get()->getMs2TendencyWindow()));
251 msp_msRunRetentionTime.get()->setMs2MeanFilter(
252 pappso::FilterMorphoMean(alignment_method.get()->getMs2SmoothingWindow()));
253 msp_msRunRetentionTime.get()->setMs1MeanFilter(
254 pappso::FilterMorphoMean(alignment_method.get()->getMs1SmoothingWindow()));
255
256
257 for(const auto &observation_pair : m_peptideObservationList)
258 {
259 QString peptide_id = observation_pair.first->getId();
260
261 for(std::uint8_t charge : observation_pair.second->getObservedChargeStates())
262 {
263
264 msp_msRunRetentionTime.get()->addPeptideAsSeamark(
265 QString("%1-%2").arg(peptide_id).arg(charge),
266 observation_pair.second.get()->getBestXicCoordSPtrForCharge(charge).get()->rtTarget,
267 1);
268 }
269 }
270 /*
271for(auto &one_xic_measure : measures.get()->getMeasurementList())
272{
273if((one_xic_measure.m_peakQualityCategory ==
274PeakQualityCategory::aa) ||
275(one_xic_measure.m_peakQualityCategory == PeakQualityCategory::a))
276{
277msp_msRunRetentionTime.get()->addPeptideAsSeamark(
278peptide_id,
279one_xic_measure.m_tracePeakSp.get()->getMaxXicElement().x,
280one_xic_measure.m_tracePeakSp.get()->getMaxXicElement().y);
281}
282}
283*/
284
285
286 msp_msRunRetentionTime.get()->computeSeamarks();
287
289}
290
291void
293 const pappso::MsRunRetentionTime<QString> *msrun_retention_time_reference_p) const
294{
296 {
297 try
298 {
299 pappso::masschroq::Peptide *peptide_p =
300 measures.get()->getPeptideObservationSp().get()->getPeptideSp().get();
301 peptide_p->setReferenceMsRunRetentionTimePtr(msrun_retention_time_reference_p);
302 for(auto &one_xic_measure : measures.get()->getMeasurementList())
303 {
304 peptide_p->addAlignedPeakMeasurement(one_xic_measure,
305 *(msp_msRunRetentionTime.get()));
306 }
307 }
308 catch(const pappso::PappsoException &error)
309 {
311 QObject::tr("error collecting peak retention time in msrun %1 :\n%2")
312 .arg(msp_msRun.get()->getMsRunReaderSPtr()->getMsRunId()->getXmlId())
313 .arg(error.qwhat()));
314 }
315 }
316}
317
318
319void
321 const pappso::MsRunRetentionTime<QString> *msrun_retention_time_reference_p) const
322{
323 // collect only peptides that were selected for measurement in the first pass
325 {
326 try
327 {
328
329 pappso::masschroq::Peptide *peptide_p =
330 measures.get()->getPeptideObservationSp().get()->getPeptideSp().get();
331 peptide_p->setReferenceMsRunRetentionTimePtr(msrun_retention_time_reference_p);
333 *(measures.get()->getPeptideObservationSp().get()), *(msp_msRunRetentionTime.get()));
334 }
335 catch(const pappso::PappsoException &error)
336 {
338 QObject::tr("error collecting MS2 retention time in msrun %1 :\n%2")
339 .arg(msp_msRun.get()->getMsRunReaderSPtr()->getMsRunId()->getXmlId())
340 .arg(error.qwhat()));
341 }
342 }
343}
344
345
346void
348 const pappso::masschroq::MsRunGroup *msrun_group_p,
349 const std::vector<pappso::masschroq::PeptideSp> &peptide_mbr_list,
350 const QString &tmp_dir,
351 pappso::UiMonitorInterface &ui_monitor,
352 const QuantificationMethodSp &quantification_method)
353{
354 try
355 {
357 ui_monitor.appendText(
358 QString("Starting quantification for msrun %1 (MBR)")
359 .arg(msp_msRun.get()->getMsRunReaderSPtr()->getMsRunId().get()->getFileName()));
360
361 qDebug();
363
364 qDebug();
367
368 qDebug();
369 ui_monitor.appendText(
370 QString("MBR Preparing extraction list (%1)").arg(peptide_mbr_list.size()));
371
372
373 std::vector<pappso::XicCoordSPtr> xic_coord_list;
374
375 for(auto &peptide_sp : peptide_mbr_list)
376 {
377 /*
378 pappso::masschroq::PeptideObservationSp peptide_events_sp = pair_peptide.second;
379
380 addPeptideObservation2XicCoordList(quantification_method,
381 pair_peptide.second,
382 xic_coord_list,
383 ni_minimum_abundance);
384 */
386 msrun_group_p, quantification_method, peptide_sp, xic_coord_list);
387 // peptide_events_sp.get()
388 }
389
390
391 ui_monitor.appendText(QString("MBR Preparing extraction list done (%1 %2)")
393 .arg(xic_coord_list.size()));
394
395 ui_monitor.appendText(QString("MBR Building XIC extractor"));
398 msp_msRun.get()->getMsRunReaderSPtr());
399
400 qDebug();
401 extractor_pwiz->setXicExtractMethod(quantification_method.get()->getXicExtractMethod());
402
403 qDebug();
404
405 extractor_pwiz.get()->setRetentionTimeAroundTarget(
406 quantification_method.get()->getXicExtractionRtRange());
407
408 qDebug();
409 pappso::FilterInterfaceCstSPtr csp_filter_suite = quantification_method.get()->getXicFilter();
410
411 qDebug();
412 extractor_pwiz.get()->setPostExtractionTraceFilterCstSPtr(csp_filter_suite);
413
414 qDebug();
415
416 ui_monitor.appendText(QString("MBR Building XIC extractor done"));
417 ui_monitor.appendText(QString("MBR Extracting"));
418 extractor_pwiz.get()->extractXicCoordSPtrListParallelized(ui_monitor, xic_coord_list);
419
420 qDebug();
421
422 mbrDetectQuantifyPeaks(ui_monitor, quantification_method);
423
424
425 ui_monitor.appendText(
426 QString("MBR Quantification for msrun %1 done")
427 .arg(msp_msRun.get()->getMsRunReaderSPtr()->getMsRunId().get()->getFileName()));
428 }
429 catch(const pappso::PappsoException &error)
430 {
432 QObject::tr("error in %1 :\n%2").arg(__FUNCTION__).arg(error.qwhat()));
433 }
434}
435
436
437void
439 const pappso::masschroq::MsRunGroup *msrun_group_p,
440 const pappso::masschroq::QuantificationMethodSp &quantification_method,
441 const pappso::masschroq::PeptideSp &peptide_sp,
442 std::vector<pappso::XicCoordSPtr> &xic_coord_list)
443{
444 MbrPeptideMeasurementsSp mbr_peptide_measurements =
445 std::make_shared<pappso::masschroq::MbrPeptideMeasurements>(peptide_sp);
446
447 m_mbrPeptideMeasurementsList.push_back(mbr_peptide_measurements);
448
449 mbr_peptide_measurements.get()->prepareMeasurements(
450 *(msp_msRun.get()->getMsRunReaderSPtr().get()->getMsRunId().get()),
451 msrun_group_p,
452 *(msp_msRunRetentionTime.get()),
453 quantification_method);
454 mbr_peptide_measurements.get()->pushBackXicCoordList(xic_coord_list);
455}
456
457void
459 pappso::UiMonitorInterface &m_uiMonitor,
460 const pappso::masschroq::QuantificationMethodSp &quantification_method)
461{
462
463 m_uiMonitor.appendText(QString("MBR Detect and quantify peak"));
464 /*
465 for(auto &measure : m_peptideMeasurementsList)
466 {
467 measure->detectQuantifyPeaks(quantification_method);
468 }
469 */
470
471 std::function<void(const pappso::masschroq::MbrPeptideMeasurementsSp &)> mapdetectQuantifyPeaks =
472 [quantification_method](const pappso::masschroq::MbrPeptideMeasurementsSp &measure) {
473 measure->detectQuantifyPeaks(quantification_method);
474 };
475
476
477 QFuture<void> res =
478 QtConcurrent::map<std::vector<pappso::masschroq::MbrPeptideMeasurementsSp>::iterator>(
481 mapdetectQuantifyPeaks);
482 res.waitForFinished();
483
484
485 m_uiMonitor.appendText(QString("Detect and quantify peak done"));
486}
487
488
499
500const std::vector<pappso::masschroq::PeptideMeasurementsSp> &
505
506const std::vector<pappso::masschroq::MbrPeptideMeasurementsSp> &
511
512void
514{
515
516 for(auto &measure : m_peptideMeasurementsList)
517 {
518 measure.get()->flushXics();
519 }
520
521 for(auto &mbr_measure : m_mbrPeptideMeasurementsList)
522 {
523 mbr_measure.get()->flushXics();
524 }
525}
mean filter apply mean of y values inside the window : this results in a kind of smoothing
median filter apply median of y values inside the window
void setTmpDir(const QString &dir_name)
set the temporary working directory
MsRunXicExtractorInterfaceSp buildMsRunXicExtractorSp(MsRunReaderSPtr &msrun_reader) const
build a simple XIC extractor that directly uses Proeowizard library to read and extract XICs building...
static MsRunXicExtractorFactory & getInstance()
singleton to get the only instance of the factory
void setMsRunXicExtractorFactoryType(pappso::MsRunXicExtractorFactoryType type)
sets the xic extractor type
virtual const QString & qwhat() const
virtual void appendText(const QString &text)=0
append a text to a long report
std::uint8_t getMs2SmoothingWindow() const
std::uint8_t getMs1SmoothingWindow() const
std::uint8_t getMs2TendencyWindow() const
void prepareMeasurements(const pappso::MsRunId &targeted_msrun, const MsRunGroup *msrun_group_p, const pappso::MsRunRetentionTime< QString > &msrun_retention_time, const QuantificationMethodSp &quantification_method)
std::vector< PeptideMeasurementsSp > m_peptideMeasurementsList
void addMbrPeptideMeasurementsSp2XicCoordList(const MsRunGroup *msrun_group_p, const QuantificationMethodSp &quantification_method, const PeptideSp &peptide, std::vector< pappso::XicCoordSPtr > &xic_coord_list)
void quantify(const MsRunGroup *msrun_group_p, const QString &tmp_dir, pappso::UiMonitorInterface &m_uiMonitor, const QuantificationMethodSp &quantification_method)
void detectQuantifyPeaks(pappso::UiMonitorInterface &m_uiMonitor, const QuantificationMethodSp &quantification_method)
void quantifyMatchBetweenRun(const MsRunGroup *msrun_group_p, const std::vector< PeptideSp > &peptide_mbr_list, const QString &tmp_dir, pappso::UiMonitorInterface &m_uiMonitor, const QuantificationMethodSp &quantification_method)
std::map< Peptide *, PeptideObservationSp > m_peptideObservationList
const std::vector< MbrPeptideMeasurementsSp > & getMbrPeptideMeasurementsList() const
std::shared_ptr< pappso::MsRunRetentionTime< QString > > msp_msRunRetentionTime
std::vector< MbrPeptideMeasurementsSp > m_mbrPeptideMeasurementsList
std::vector< pappso::XicCoordSPtr > buildXicCoordList(const MsRunGroup *msrun_group_p, const QuantificationMethodSp &quantification_method)
void collectPeptideMs2RetentionTime(const pappso::MsRunRetentionTime< QString > *msrun_retention_time_reference_p) const
collect ms2 retention times collect all MS2 events retention times and convert it to the reference ti...
void addPeptideScanNumberObservation(PeptideSp peptide_sp, PeptideLabel *p_label, std::size_t spectrum_index, std::uint8_t charge)
std::shared_ptr< pappso::MsRunRetentionTime< QString > > & buildMsRunRetentionTimeSpOnPeptideObservations(const AlignmentMethodSp &alignment_method)
build a retention time vector with seamarks using MS2 best intensities
void addPeptideObservation2XicCoordList(const MsRunGroup *msrun_group_p, const QuantificationMethodSp &quantification_method, const PeptideObservationSp &peptide_events_sp, std::vector< pappso::XicCoordSPtr > &xic_coord_list)
pappso::MsRunRetentionTime< QString > * getMsRunRetentionTimePtr() const
void addPeptideSpectrumIndexObservation(PeptideSp peptide_sp, PeptideLabel *p_label, std::size_t spectrum_index, std::uint8_t charge)
void mbrDetectQuantifyPeaks(pappso::UiMonitorInterface &m_uiMonitor, const QuantificationMethodSp &quantification_method)
void clearMeasurements()
clear all measurements MBR or not Clearing measurements also removes every chromatogram
const std::vector< PeptideMeasurementsSp > & getPeptideMeasurementsList() const
const pappso::MsRunRetentionTime< QString > * getMsRunRetentionTimeConstPtr() const
void collectPeptidePeakRetentionTime(const pappso::MsRunRetentionTime< QString > *msrun_retention_time_reference_p) const
collect peak retention times collect all quantified peptides retention times and convert it to the re...
virtual void pushBackXicCoordList(std::vector< pappso::XicCoordSPtr > &xic_coord_list) const final
void prepareMeasurements(const pappso::MsRunId &targeted_msrun, const MsRunGroup *msrun_group_p, const QuantificationMethodSp &quantification_method)
void addMsRunXicCoordCharge(const MsRunXicCoordCharge &msrun_xic_coord)
Definition peptide.cpp:272
void setReferenceMsRunRetentionTimePtr(const pappso::MsRunRetentionTime< QString > *msrun_retention_time_reference_p)
sets the current msrun retention time reference
Definition peptide.cpp:252
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
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::XicCoordSPtr & getXicCoordSPtr() const
Definition precursor.cpp:71
Enums::XicExtractMethod getXicExtractMethod() const
const pappso::FilterNameInterfaceSPtr getXicFilter() const
std::shared_ptr< QuantificationMethod > QuantificationMethodSp
std::shared_ptr< PeptideMeasurements > PeptideMeasurementsSp
std::shared_ptr< AlignmentMethod > AlignmentMethodSp
std::shared_ptr< MbrPeptideMeasurements > MbrPeptideMeasurementsSp
std::shared_ptr< Peptide > PeptideSp
Definition peptide.h:46
std::shared_ptr< Precursor > PrecursorSp
Definition precursor.h:39
std::shared_ptr< PeptideObservation > PeptideObservationSp
std::shared_ptr< MsRun > MsRunSp
Definition msrun.h:44
std::shared_ptr< const FilterInterface > FilterInterfaceCstSPtr
std::shared_ptr< MsRunXicExtractorInterface > MsRunXicExtractorInterfaceSp