libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
msrungroup.cpp
Go to the documentation of this file.
1/**
2 * \file mcql/core/msrungroup.cpp
3 * \date 10/10/2024
4 * \author Olivier Langella
5 * \brief group msrun together 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 "msrungroup.h"
31
33 const std::vector<MsRunPeptideListSp> &msrun_list)
34 : m_id(id), m_msRunPeptideListSpList(msrun_list)
35{
36 if(m_msRunPeptideListSpList.size() > 0)
37 {
38 m_hasTimsTofMobilityIndex =
39 m_msRunPeptideListSpList.front().get()->getMsRunSp().get()->hasTimsTofMobilityIndex();
40 }
41}
42
48
52
53void
56 [[maybe_unused]] pappso::UiMonitorInterface &m_uiMonitor) const
57{
59 {
60 throw pappso::PappsoException(QObject::tr("match between run requires an MSrun reference"));
61 }
62 cbor_output.getCborStreamWriter().append(QLatin1String("alignment"));
63 cbor_output.getCborStreamWriter().startMap();
64 cbor_output.getCborStreamWriter().append(QLatin1String("msrun_ref"));
66 ->getMsRunSp()
67 .get()
68 ->getMsRunReaderSPtr()
69 .get()
70 ->getMsRunId()
71 .get()
72 ->getXmlId());
73 // "alignment": {
74 // "msrun_ref": "msruna2",
75
77 {
78 msrun_peptide_list.get()->buildMsRunRetentionTimeSpOnPeptideObservations(msp_alignmentMethod);
79 }
80 const pappso::MsRunRetentionTime<QString> *reference_msrun_retetiontime_p =
81 msp_msRunPeptideListAlignmentReference.get()->getMsRunRetentionTimeConstPtr();
82
83 cbor_output.getCborStreamWriter().append(QLatin1String("corrections"));
84
85 cbor_output.getCborStreamWriter().startMap();
86 // "corrections": {
88 {
89
90 if(msrun_peptide_list.get() == msp_msRunPeptideListAlignmentReference.get())
91 continue;
92
93
94 /*
95 "msruna1": {
96 "original": [1,2,3,4.5],
97 "aligned":[1,2,3,4.5]
98 },
99 "msruna2": {
100 "original": [1,2,3,4.5],
101 "aligned":[1,2,3,4.5]
102 }*/
103 msrun_peptide_list.get()->getMsRunRetentionTimePtr()->align(*reference_msrun_retetiontime_p);
104
105 pappso::Trace report_common_MS2_delta_rt =
106 msrun_peptide_list.get()->getMsRunRetentionTimePtr()->getCommonDeltaRt(
107 reference_msrun_retetiontime_p->getSeamarks());
108
109 cbor_output.getCborStreamWriter().append(msrun_peptide_list.get()
110 ->getMsRunSp()
111 .get()
112 ->getMsRunReaderSPtr()
113 .get()
114 ->getMsRunId()
115 .get()
116 ->getXmlId());
117 cbor_output.writeMsRunRetentionTime(report_common_MS2_delta_rt,
118 *msrun_peptide_list.get()->getMsRunRetentionTimePtr());
119 }
120
121
122 cbor_output.getCborStreamWriter().endMap();
123 cbor_output.getCborStreamWriter().endMap();
124}
125
126
127void
129 const QString &align_id,
130 pappso::UiMonitorInterface &m_uiMonitor) const
131{
132
133 cbor_output.getCborStreamWriter().startMap();
134 cbor_output.getCborStreamWriter().append(QLatin1String("alignment_id"));
135 cbor_output.getCborStreamWriter().append(align_id);
136 cbor_output.getCborStreamWriter().append(QLatin1String("group_id"));
137 cbor_output.getCborStreamWriter().append(getId());
138 cbor_output.getCborStreamWriter().append(QLatin1String("timestamp1"));
139 cbor_output.getCborStreamWriter().append(QDateTime::currentDateTime().toString(Qt::ISODate));
140
141 // std::shared_ptr<pappso::MsRunRetentionTime<QString>>
142 // retention_time_reference_sp = nullptr;
143 m_uiMonitor.appendText("Starting retention time alignment");
144 alignRetentionTimeBetweenMsRuns(cbor_output, m_uiMonitor);
145 m_uiMonitor.appendText("retention time alignment done");
146
147
148 cbor_output.getCborStreamWriter().append(QLatin1String("timestamp2"));
149 cbor_output.getCborStreamWriter().append(QDateTime::currentDateTime().toString(Qt::ISODate));
150 cbor_output.getCborStreamWriter().endMap();
151}
152
153
154void
157 const QString &quantify_id,
158 const QString &tmp_dir,
159 pappso::UiMonitorInterface &m_uiMonitor,
160 const pappso::masschroq::QuantificationMethodSp &quantification_method,
161 const std::vector<pappso::masschroq::PeptideSp> &peptide_sp_list) const
162{
163
164 bool match_between_run = quantification_method.get()->getMatchBetweenRun();
165
166 cbor_output.getCborStreamWriter().startMap();
167 cbor_output.getCborStreamWriter().append("quantify_id");
168 cbor_output.getCborStreamWriter().append(quantify_id);
169 cbor_output.getCborStreamWriter().append("group_id");
170 cbor_output.getCborStreamWriter().append(getId());
171 cbor_output.getCborStreamWriter().append(QLatin1String("timestamp1"));
172 cbor_output.getCborStreamWriter().append(QDateTime::currentDateTime().toString(Qt::ISODate));
173
174 cbor_output.getCborStreamWriter().append("first_pass");
175 cbor_output.getCborStreamWriter().startMap(m_msRunPeptideListSpList.size());
176
177
178 const pappso::MsRunRetentionTime<QString> *msrun_rt_reference_p = nullptr;
179 if(match_between_run)
180 {
181
182 if(msp_msRunPeptideListAlignmentReference.get() == nullptr)
183 {
185 QObject::tr("group %1 is not aligned, match between run is not possible").arg(getId()));
186 }
187 msrun_rt_reference_p =
188 msp_msRunPeptideListAlignmentReference.get()->getMsRunRetentionTimeConstPtr();
189 }
190
191
193 {
194 msrun_peptide_list.get()->quantify(this, tmp_dir, m_uiMonitor, quantification_method);
195
196
197 if(match_between_run)
198 {
199
200
201 const pappso::MsRunRetentionTime<QString> *msrun_rt_p =
202 msrun_peptide_list.get()->getMsRunRetentionTimeConstPtr();
203
204
205 if((msrun_rt_reference_p == nullptr) || (msrun_rt_p == nullptr) ||
206 ((!msrun_rt_p->isAligned()) && (msrun_rt_reference_p != msrun_rt_p)))
207 {
209 QObject::tr("msrun %1 is not aligned, match between run is not possible")
210 .arg(msrun_peptide_list.get()
211 ->getMsRunSp()
212 .get()
213 ->getMsRunReaderSPtr()
214 .get()
215 ->getMsRunId()
216 .get()
217 ->getXmlId()));
218 }
219 m_uiMonitor.appendText("Collecting peak apex");
220 msrun_peptide_list.get()->collectPeptidePeakRetentionTime(msrun_rt_reference_p);
221 msrun_peptide_list.get()->collectPeptideMs2RetentionTime(msrun_rt_reference_p);
222 }
223
224 cbor_output.writeQrDataBlock(m_uiMonitor, *msrun_peptide_list.get(), false);
225
226
227 msrun_peptide_list.get()->clearMeasurements();
228 }
229
230 cbor_output.getCborStreamWriter().endMap();
231
232 cbor_output.getCborStreamWriter().append(QLatin1String("timestamp2"));
233 cbor_output.getCborStreamWriter().append(QDateTime::currentDateTime().toString(Qt::ISODate));
234 if(match_between_run)
235 {
236 if(msrun_rt_reference_p != nullptr)
237 { // second pass
238
239 m_uiMonitor.appendText(
240 QObject::tr("Computing consensus retention time (%1)").arg(peptide_sp_list.size()));
241 for(const pappso::masschroq::PeptideSp &peptide_sp : peptide_sp_list)
242 {
243 peptide_sp.get()->computeConsensusRetentionTime();
244 }
245
246 cbor_output.getCborStreamWriter().append("second_pass");
247 cbor_output.getCborStreamWriter().startMap(m_msRunPeptideListSpList.size());
248 for(const pappso::masschroq::MsRunPeptideListSp &msrun_peptide_list :
250 {
251 const pappso::masschroq::MsRun *msrun_p =
252 msrun_peptide_list.get()->getMsRunSp().get();
253 std::vector<pappso::masschroq::PeptideSp> peptide_mbr_list;
254 for(const pappso::masschroq::PeptideSp &peptide_sp : peptide_sp_list)
255 {
256 if(!peptide_sp.get()->isObservedInMsRunSp(msrun_p))
257 {
258 peptide_mbr_list.push_back(peptide_sp);
259 }
260 }
261 msrun_peptide_list.get()->quantifyMatchBetweenRun(
262 this, peptide_mbr_list, tmp_dir, m_uiMonitor, quantification_method);
263
264
265 cbor_output.writeQrDataBlock(m_uiMonitor, *msrun_peptide_list.get(), true);
266
267 msrun_peptide_list.get()->clearMeasurements();
268 }
269
270 cbor_output.getCborStreamWriter().endMap();
271 }
272 }
273
274 cbor_output.getCborStreamWriter().append(QLatin1String("timestamp3"));
275 cbor_output.getCborStreamWriter().append(QDateTime::currentDateTime().toString(Qt::ISODate));
276 cbor_output.getCborStreamWriter().endMap();
277}
278
279void
281 const pappso::masschroq::AlignmentMethodSp &alignment_method_sp, const QString &msrun_ref_id)
282{
283 auto it = find_if(m_msRunPeptideListSpList.begin(),
285 [msrun_ref_id](const pappso::masschroq::MsRunPeptideListSp &msrun) {
286 if(msrun.get()
287 ->getMsRunSp()
288 .get()
289 ->getMsRunReaderSPtr()
290 .get()
291 ->getMsRunId()
292 .get()
293 ->getXmlId() == msrun_ref_id)
294 return true;
295 return false;
296 });
297 if(it != m_msRunPeptideListSpList.end())
298 {
299 msp_alignmentMethod = alignment_method_sp;
301 }
302 else
303 {
305 QObject::tr("msrun_id %1 not found in group %2").arg(msrun_ref_id).arg(m_id));
306 }
307}
308
309bool
311{
312 auto it = find_if(m_msRunPeptideListSpList.begin(),
314 [msrun_p](const pappso::masschroq::MsRunPeptideListSp &msrun) {
315 return (msrun.get()->getMsRunSp().get() == msrun_p);
316 });
317 return (it != m_msRunPeptideListSpList.end());
318}
319
320void
322 const std::shared_ptr<pappso::IonMobilityGrid> &ion_mobility_grid_sp)
323{
324 msp_ionMobilityGrid = ion_mobility_grid_sp;
325}
326
327bool
332
333const std::shared_ptr<pappso::IonMobilityGrid> &
338
339const QString &
341{
342 return m_id;
343}
const std::vector< MsRunRetentionTimeSeamarkPoint< T > > & getSeamarks() const
A simple container of DataPoint instances.
Definition trace.h:152
virtual void appendText(const QString &text)=0
append a text to a long report
void writeMsRunRetentionTime(const pappso::Trace &report_common_ms2, const pappso::MsRunRetentionTime< QString > &msrun_retention_time)
void writeQrDataBlock(pappso::UiMonitorInterface &m_uiMonitor, const MsRunPeptideList &msrun_peptide_list, bool is_mbr)
MsRunGroup(const QString &id, const std::vector< MsRunPeptideListSp > &msrun_list)
std::shared_ptr< pappso::IonMobilityGrid > msp_ionMobilityGrid
Definition msrungroup.h:103
void quantify(CborOutputStream &cbor_output, const QString &quantify_id, const QString &tmp_dir, pappso::UiMonitorInterface &m_uiMonitor, const QuantificationMethodSp &quantification_method, const std::vector< PeptideSp > &peptide_sp_list) const
void setIonMobilityGridSp(const std::shared_ptr< pappso::IonMobilityGrid > &ion_mobility_grid_sp)
bool contains(const MsRun *msrun_p) const
const QString & getId() const
void align(CborOutputStream &cbor_output, const QString &align_id, pappso::UiMonitorInterface &m_uiMonitor) const
void setAlignmentMethodSp(const AlignmentMethodSp &alignment_method_sp, const QString &msrun_ref_id)
MsRunPeptideListSp msp_msRunPeptideListAlignmentReference
Definition msrungroup.h:101
const std::vector< MsRunPeptideListSp > m_msRunPeptideListSpList
Definition msrungroup.h:99
const std::shared_ptr< pappso::IonMobilityGrid > & getIonMobilityGridSp() const
AlignmentMethodSp msp_alignmentMethod
Definition msrungroup.h:100
void alignRetentionTimeBetweenMsRuns(CborOutputStream &cbor_output, pappso::UiMonitorInterface &m_uiMonitor) const
std::shared_ptr< QuantificationMethod > QuantificationMethodSp
std::shared_ptr< MsRunPeptideList > MsRunPeptideListSp
std::shared_ptr< AlignmentMethod > AlignmentMethodSp
std::shared_ptr< Peptide > PeptideSp
Definition peptide.h:46