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>
34
39
45
49
50void
54 std::size_t spectrum_index,
55 std::uint8_t charge)
56{
57
58 auto it = m_peptideObservationList.insert(
59 {peptide_sp.get(), std::make_shared<pappso::masschroq::PeptideObservation>(peptide_sp)});
61 msp_msRun.get()->getPrecursorSPtrBySpectrumIndex(spectrum_index);
62 it.first->second.get()->addObservation({spectrum_index, charge, precursor_sp, true, p_label});
63
64 peptide_sp.get()->addMsRunXicCoordCharge({msp_msRun.get(),
65 precursor_sp.get()->getXicCoordSPtr(),
66 charge,
67 precursor_sp.get()->getIntensity()});
68 qDebug() << "m_peptideObservationList.size()=" << m_peptideObservationList.size();
69}
70
71void
75 std::size_t scan_number,
76 std::uint8_t charge)
77{
78
79 auto it = m_peptideObservationList.insert(
80 {peptide_sp.get(), std::make_shared<pappso::masschroq::PeptideObservation>(peptide_sp)});
82 msp_msRun.get()->getPrecursorSPtrByScanNumber(scan_number);
83 it.first->second.get()->addObservation({scan_number, charge, precursor_sp, false, p_label});
84
85 peptide_sp.get()->addMsRunXicCoordCharge({msp_msRun.get(),
86 precursor_sp.get()->getXicCoordSPtr(),
87 charge,
88 precursor_sp.get()->getIntensity()});
89 qDebug() << "m_peptideObservationList.size()=" << m_peptideObservationList.size();
90}
91
92void
94 const QString &tmp_dir,
96 const QuantificationMethodSp &quantification_method)
97{
99 ui_monitor.appendText(
100 QString("Starting quantification for msrun %1")
101 .arg(msp_msRun.get()->getMsRunReaderSPtr()->getMsRunId().get()->getFileName()));
102
103 qDebug() << m_peptideObservationList.size();
105
106 qDebug();
109
110 qDebug();
111 ui_monitor.appendText(QString("Preparing extraction list"));
112 std::vector<pappso::XicCoordSPtr> xic_coord_list =
113 buildXicCoordList(msrun_group_p, quantification_method);
114
115 ui_monitor.appendText(QString("Preparing extraction list done"));
116
117 ui_monitor.appendText(QString("Building XIC extractor"));
120 msp_msRun.get()->getMsRunReaderSPtr());
121
122 qDebug();
123 extractor_pwiz->setXicExtractMethod(quantification_method.get()->getXicExtractMethod());
124
125 // qWarning() << quantification_method.get()->getXicExtractionRtRange();
126
127 extractor_pwiz.get()->setRetentionTimeAroundTarget(
128 quantification_method.get()->getXicExtractionRtRange());
129
130 qDebug();
131 pappso::FilterInterfaceCstSPtr csp_filter_suite = quantification_method.get()->getXicFilter();
132
133 qDebug();
134 extractor_pwiz.get()->setPostExtractionTraceFilterCstSPtr(csp_filter_suite);
135
136 qDebug();
137
138 ui_monitor.appendText(QString("Building XIC extractor done"));
139 ui_monitor.appendText(QString("Extracting"));
140 extractor_pwiz.get()->extractXicCoordSPtrListParallelized(ui_monitor, xic_coord_list);
141
142 // qWarning() << "size of first xic=" << xic_coord_list.at(0).get()->xicSptr.get()->size();
143 qDebug();
144
145 detectQuantifyPeaks(ui_monitor, quantification_method);
146
147
148 ui_monitor.appendText(
149 QString("Quantification for msrun %1 done")
150 .arg(msp_msRun.get()->getMsRunReaderSPtr()->getMsRunId().get()->getFileName()));
151}
152
153
154std::vector<pappso::XicCoordSPtr>
156 const pappso::masschroq::MsRunGroup *msrun_group_p,
157 const QuantificationMethodSp &quantification_method)
158{
159 std::vector<pappso::XicCoordSPtr> xic_coord_list;
160
161 for(auto pair_peptide : m_peptideObservationList)
162 {
163 pappso::masschroq::PeptideObservationSp peptide_events_sp = pair_peptide.second;
164
166 msrun_group_p, quantification_method, pair_peptide.second, xic_coord_list);
167 // peptide_events_sp.get()
168 }
169
170
171 return xic_coord_list;
172}
173
174void
176 const pappso::masschroq::MsRunGroup *msrun_group_p,
177 const QuantificationMethodSp &quantification_method,
178 const pappso::masschroq::PeptideObservationSp &peptide_events_sp,
179 std::vector<pappso::XicCoordSPtr> &xic_coord_list)
180{
181 PeptideMeasurementsSp peptide_measurements =
182 std::make_shared<pappso::masschroq::PeptideMeasurements>(peptide_events_sp);
183
184 m_peptideMeasurementsList.push_back(peptide_measurements);
185
186 peptide_measurements.get()->prepareMeasurements(
187 *(msp_msRun.get()->getMsRunReaderSPtr().get()->getMsRunId().get()),
188 msrun_group_p,
189 quantification_method);
190 peptide_measurements.get()->pushBackXicCoordList(xic_coord_list);
191}
192
193void
195 pappso::UiMonitorInterface &m_uiMonitor, const QuantificationMethodSp &quantification_method)
196{
197
198 m_uiMonitor.appendText(QString("Detect and quantify peak"));
199 /*
200 for(auto &measure : m_peptideMeasurementsList)
201 {
202 measure->detectQuantifyPeaks(quantification_method);
203 }
204 */
205
206 std::function<void(const pappso::masschroq::PeptideMeasurementsSp &)> mapdetectQuantifyPeaks =
207 [quantification_method](const pappso::masschroq::PeptideMeasurementsSp &measure) {
208 measure->detectQuantifyPeaks(quantification_method);
209 };
210
211
212 QFuture<void> res =
213 QtConcurrent::map<std::vector<pappso::masschroq::PeptideMeasurementsSp>::iterator>(
214 m_peptideMeasurementsList.begin(), m_peptideMeasurementsList.end(), mapdetectQuantifyPeaks);
215 res.waitForFinished();
216
217
218 m_uiMonitor.appendText(QString("Detect and quantify peak done"));
219}
220
221
227
228void
230{
231
232 for(auto &measure : m_peptideMeasurementsList)
233 {
234 measure.get()->flushXics();
235 }
236
237 for(auto &mbr_measure : m_mbrPeptideMeasurementsList)
238 {
239 mbr_measure.get()->flushXics();
240 }
241}
242
243std::shared_ptr<pappso::MsRunRetentionTime<QString>> &
245 const pappso::masschroq::AlignmentMethodSp &alignment_method)
246{
248 std::make_shared<pappso::MsRunRetentionTime<QString>>(msp_msRun->getRetentionTimeLine());
249
250 msp_msRunRetentionTime.get()->setMs2MedianFilter(
251 pappso::FilterMorphoMedian(alignment_method.get()->getMs2TendencyWindow()));
252 msp_msRunRetentionTime.get()->setMs2MeanFilter(
253 pappso::FilterMorphoMean(alignment_method.get()->getMs2SmoothingWindow()));
254 msp_msRunRetentionTime.get()->setMs1MeanFilter(
255 pappso::FilterMorphoMean(alignment_method.get()->getMs1SmoothingWindow()));
256
257
258 for(const auto &observation_pair : m_peptideObservationList)
259 {
260 QString peptide_id = observation_pair.first->getId();
261
262 for(std::uint8_t charge : observation_pair.second->getObservedChargeStates())
263 {
264
265 msp_msRunRetentionTime.get()->addPeptideAsSeamark(
266 QString("%1-%2").arg(peptide_id).arg(charge),
267 observation_pair.second.get()->getBestXicCoordSPtrForCharge(charge).get()->rtTarget,
268 1);
269 }
270 }
271 /*
272for(auto &one_xic_measure : measures.get()->getMeasurementList())
273{
274if((one_xic_measure.m_peakQualityCategory ==
275PeakQualityCategory::aa) ||
276(one_xic_measure.m_peakQualityCategory == PeakQualityCategory::a))
277{
278msp_msRunRetentionTime.get()->addPeptideAsSeamark(
279peptide_id,
280one_xic_measure.m_tracePeakSp.get()->getMaxXicElement().x,
281one_xic_measure.m_tracePeakSp.get()->getMaxXicElement().y);
282}
283}
284*/
285
286
287 msp_msRunRetentionTime.get()->computeSeamarks();
288
290}
291
292void
294 const pappso::MsRunRetentionTime<QString> *msrun_retention_time_reference_p) const
295{
297 {
298 try
299 {
300 pappso::masschroq::Peptide *peptide_p =
301 measures.get()->getPeptideObservationSp().get()->getPeptideSp().get();
302 peptide_p->setReferenceMsRunRetentionTimePtr(msrun_retention_time_reference_p);
303 for(auto &one_xic_measure : measures.get()->getMeasurementList())
304 {
305 peptide_p->addAlignedPeakMeasurement(one_xic_measure,
306 *(msp_msRunRetentionTime.get()));
307 }
308 }
309 catch(const pappso::PappsoException &error)
310 {
312 QObject::tr("error collecting peak retention time in msrun %1 :\n%2")
313 .arg(msp_msRun.get()->getMsRunReaderSPtr()->getMsRunId()->getXmlId())
314 .arg(error.qwhat()));
315 }
316 }
317}
318
319
320void
322 const pappso::MsRunRetentionTime<QString> *msrun_retention_time_reference_p) const
323{
324 // collect only peptides that were selected for measurement in the first pass
326 {
327 try
328 {
329
330 pappso::masschroq::Peptide *peptide_p =
331 measures.get()->getPeptideObservationSp().get()->getPeptideSp().get();
332 peptide_p->setReferenceMsRunRetentionTimePtr(msrun_retention_time_reference_p);
334 *(measures.get()->getPeptideObservationSp().get()), *(msp_msRunRetentionTime.get()));
335 }
336 catch(const pappso::PappsoException &error)
337 {
339 QObject::tr("error collecting MS2 retention time in msrun %1 :\n%2")
340 .arg(msp_msRun.get()->getMsRunReaderSPtr()->getMsRunId()->getXmlId())
341 .arg(error.qwhat()));
342 }
343 }
344}
345
346
347void
349 const pappso::masschroq::MsRunGroup *msrun_group_p,
350 const std::vector<pappso::masschroq::PeptideSp> &peptide_mbr_list,
351 const QString &tmp_dir,
352 pappso::UiMonitorInterface &ui_monitor,
353 const QuantificationMethodSp &quantification_method)
354{
355 try
356 {
358 ui_monitor.appendText(
359 QString("Starting quantification for msrun %1 (MBR)")
360 .arg(msp_msRun.get()->getMsRunReaderSPtr()->getMsRunId().get()->getFileName()));
361
362 qDebug();
364
365 qDebug();
368
369 qDebug();
370 ui_monitor.appendText(
371 QString("MBR Preparing extraction list (%1)").arg(peptide_mbr_list.size()));
372
373
374 std::vector<pappso::XicCoordSPtr> xic_coord_list;
375
376 for(auto &peptide_sp : peptide_mbr_list)
377 {
378 /*
379 pappso::masschroq::PeptideObservationSp peptide_events_sp = pair_peptide.second;
380
381 addPeptideObservation2XicCoordList(quantification_method,
382 pair_peptide.second,
383 xic_coord_list,
384 ni_minimum_abundance);
385 */
387 msrun_group_p, quantification_method, peptide_sp, xic_coord_list);
388 // peptide_events_sp.get()
389 }
390
391
392 ui_monitor.appendText(QString("MBR Preparing extraction list done (%1 %2)")
394 .arg(xic_coord_list.size()));
395
396 ui_monitor.appendText(QString("MBR Building XIC extractor"));
399 msp_msRun.get()->getMsRunReaderSPtr());
400
401 qDebug();
402 extractor_pwiz->setXicExtractMethod(quantification_method.get()->getXicExtractMethod());
403
404 qDebug();
405
406 extractor_pwiz.get()->setRetentionTimeAroundTarget(
407 quantification_method.get()->getXicExtractionRtRange());
408
409 qDebug();
410 pappso::FilterInterfaceCstSPtr csp_filter_suite = quantification_method.get()->getXicFilter();
411
412 qDebug();
413 extractor_pwiz.get()->setPostExtractionTraceFilterCstSPtr(csp_filter_suite);
414
415 qDebug();
416
417 ui_monitor.appendText(QString("MBR Building XIC extractor done"));
418 ui_monitor.appendText(QString("MBR Extracting"));
419 extractor_pwiz.get()->extractXicCoordSPtrListParallelized(ui_monitor, xic_coord_list);
420
421 qDebug();
422
423 mbrDetectQuantifyPeaks(ui_monitor, quantification_method);
424
425
426 ui_monitor.appendText(
427 QString("MBR Quantification for msrun %1 done")
428 .arg(msp_msRun.get()->getMsRunReaderSPtr()->getMsRunId().get()->getFileName()));
429 }
430 catch(const pappso::PappsoException &error)
431 {
433 QObject::tr("error in %1 :\n%2").arg(__FUNCTION__).arg(error.qwhat()));
434 }
435}
436
437
438void
440 const pappso::masschroq::MsRunGroup *msrun_group_p,
441 const pappso::masschroq::QuantificationMethodSp &quantification_method,
442 const pappso::masschroq::PeptideSp &peptide_sp,
443 std::vector<pappso::XicCoordSPtr> &xic_coord_list)
444{
445 MbrPeptideMeasurementsSp mbr_peptide_measurements =
446 std::make_shared<pappso::masschroq::MbrPeptideMeasurements>(peptide_sp);
447
448 m_mbrPeptideMeasurementsList.push_back(mbr_peptide_measurements);
449
450 mbr_peptide_measurements.get()->prepareMeasurements(
451 *(msp_msRun.get()->getMsRunReaderSPtr().get()->getMsRunId().get()),
452 msrun_group_p,
453 *(msp_msRunRetentionTime.get()),
454 quantification_method);
455 mbr_peptide_measurements.get()->pushBackXicCoordList(xic_coord_list);
456}
457
458void
460 pappso::UiMonitorInterface &m_uiMonitor,
461 const pappso::masschroq::QuantificationMethodSp &quantification_method)
462{
463
464 m_uiMonitor.appendText(QString("MBR Detect and quantify peak"));
465 /*
466 for(auto &measure : m_peptideMeasurementsList)
467 {
468 measure->detectQuantifyPeaks(quantification_method);
469 }
470 */
471
472 std::function<void(const pappso::masschroq::MbrPeptideMeasurementsSp &)> mapdetectQuantifyPeaks =
473 [quantification_method](const pappso::masschroq::MbrPeptideMeasurementsSp &measure) {
474 measure->detectQuantifyPeaks(quantification_method);
475 };
476
477
478 QFuture<void> res =
479 QtConcurrent::map<std::vector<pappso::masschroq::MbrPeptideMeasurementsSp>::iterator>(
482 mapdetectQuantifyPeaks);
483 res.waitForFinished();
484
485
486 m_uiMonitor.appendText(QString("Detect and quantify peak done"));
487}
488
489
500
501const std::vector<pappso::masschroq::PeptideMeasurementsSp> &
506
507const std::vector<pappso::masschroq::MbrPeptideMeasurementsSp> &
512
513void
515{
516
517 for(auto &measure : m_peptideMeasurementsList)
518 {
519 measure.get()->flushXics();
520 }
521
522 for(auto &mbr_measure : m_mbrPeptideMeasurementsList)
523 {
524 mbr_measure.get()->flushXics();
525 }
526}
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:271
void setReferenceMsRunRetentionTimePtr(const pappso::MsRunRetentionTime< QString > *msrun_retention_time_reference_p)
sets the current msrun retention time reference
Definition peptide.cpp:251
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:72
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