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
55 pappso::masschroq::CborOutputStream &cbor_output, [[maybe_unused]] pappso::UiMonitorInterface &m_uiMonitor) const
56{
58 {
59 throw pappso::PappsoException(QObject::tr("match between run requires an MSrun reference"));
60 }
61 cbor_output.getCborStreamWriter().append(QLatin1String("alignment"));
62 cbor_output.getCborStreamWriter().startMap();
63 cbor_output.getCborStreamWriter().append(QLatin1String("msrun_ref"));
65 ->getMsRunSp()
66 .get()
67 ->getMsRunReaderSPtr()
68 .get()
69 ->getMsRunId()
70 .get()
71 ->getXmlId());
72 // "alignment": {
73 // "msrun_ref": "msruna2",
74
76 {
77 msrun_peptide_list.get()->buildMsRunRetentionTimeSpOnPeptideObservations(msp_alignmentMethod);
78 }
79 const pappso::MsRunRetentionTime<QString> *reference_msrun_retetiontime_p =
80 msp_msRunPeptideListAlignmentReference.get()->getMsRunRetentionTimeConstPtr();
81
82 cbor_output.getCborStreamWriter().append(QLatin1String("corrections"));
83
84 cbor_output.getCborStreamWriter().startMap();
85 // "corrections": {
87 {
88
89 if(msrun_peptide_list.get() == msp_msRunPeptideListAlignmentReference.get())
90 continue;
91
92
93 /*
94 "msruna1": {
95 "original": [1,2,3,4.5],
96 "aligned":[1,2,3,4.5]
97 },
98 "msruna2": {
99 "original": [1,2,3,4.5],
100 "aligned":[1,2,3,4.5]
101 }*/
102 msrun_peptide_list.get()->getMsRunRetentionTimePtr()->align(*reference_msrun_retetiontime_p);
103
104 pappso::Trace report_common_MS2_delta_rt =
105 msrun_peptide_list.get()->getMsRunRetentionTimePtr()->getCommonDeltaRt(
106 reference_msrun_retetiontime_p->getSeamarks());
107
108 cbor_output.getCborStreamWriter().append(msrun_peptide_list.get()
109 ->getMsRunSp()
110 .get()
111 ->getMsRunReaderSPtr()
112 .get()
113 ->getMsRunId()
114 .get()
115 ->getXmlId());
116 cbor_output.writeMsRunRetentionTime(report_common_MS2_delta_rt, *msrun_peptide_list.get()->getMsRunRetentionTimePtr());
117 }
118
119
120 cbor_output.getCborStreamWriter().endMap();
121 cbor_output.getCborStreamWriter().endMap();
122}
123
124
125void
127 const QString &align_id,
128 pappso::UiMonitorInterface &m_uiMonitor) const
129{
130
131 cbor_output.getCborStreamWriter().startMap();
132 cbor_output.getCborStreamWriter().append(QLatin1String("alignment_id"));
133 cbor_output.getCborStreamWriter().append(align_id);
134 cbor_output.getCborStreamWriter().append(QLatin1String("group_id"));
135 cbor_output.getCborStreamWriter().append(getId());
136 cbor_output.getCborStreamWriter().append(QLatin1String("timestamp1"));
137 cbor_output.getCborStreamWriter().append(QDateTime::currentDateTime().toString(Qt::ISODate));
138
139 // std::shared_ptr<pappso::MsRunRetentionTime<QString>>
140 // retention_time_reference_sp = nullptr;
141 m_uiMonitor.appendText("Starting retention time alignment");
142 alignRetentionTimeBetweenMsRuns(cbor_output, m_uiMonitor);
143 m_uiMonitor.appendText("retention time alignment done");
144
145
146 cbor_output.getCborStreamWriter().append(QLatin1String("timestamp2"));
147 cbor_output.getCborStreamWriter().append(QDateTime::currentDateTime().toString(Qt::ISODate));
148 cbor_output.getCborStreamWriter().endMap();
149}
150
151
152void
155 const QString &quantify_id,
156 const QString &tmp_dir,
157 pappso::UiMonitorInterface &m_uiMonitor,
158 const pappso::masschroq::QuantificationMethodSp &quantification_method,
159 const std::vector<pappso::masschroq::PeptideSp> &peptide_sp_list) const
160{
161
162 bool match_between_run = quantification_method.get()->getMatchBetweenRun();
163
164 cbor_output.getCborStreamWriter().startMap();
165 cbor_output.getCborStreamWriter().append("quantify_id");
166 cbor_output.getCborStreamWriter().append(quantify_id);
167 cbor_output.getCborStreamWriter().append("group_id");
168 cbor_output.getCborStreamWriter().append(getId());
169 cbor_output.getCborStreamWriter().append(QLatin1String("timestamp1"));
170 cbor_output.getCborStreamWriter().append(QDateTime::currentDateTime().toString(Qt::ISODate));
171
172 cbor_output.getCborStreamWriter().append("first_pass");
173 cbor_output.getCborStreamWriter().startMap(m_msRunPeptideListSpList.size());
174
175
176 const pappso::MsRunRetentionTime<QString> *msrun_rt_reference_p = nullptr;
177 if(match_between_run)
178 {
179
180 if(msp_msRunPeptideListAlignmentReference.get() == nullptr)
181 {
183 QObject::tr("group %1 is not aligned, match between run is not possible").arg(getId()));
184 }
185 msrun_rt_reference_p =
186 msp_msRunPeptideListAlignmentReference.get()->getMsRunRetentionTimeConstPtr();
187 }
188
189
191 {
192 msrun_peptide_list.get()->quantify(this, tmp_dir, m_uiMonitor, quantification_method);
193
194
195 if(match_between_run)
196 {
197
198
199 const pappso::MsRunRetentionTime<QString> *msrun_rt_p =
200 msrun_peptide_list.get()->getMsRunRetentionTimeConstPtr();
201
202
203 if((msrun_rt_reference_p == nullptr) || (msrun_rt_p == nullptr) ||
204 ((!msrun_rt_p->isAligned()) && (msrun_rt_reference_p != msrun_rt_p)))
205 {
207 QObject::tr("msrun %1 is not aligned, match between run is not possible")
208 .arg(msrun_peptide_list.get()
209 ->getMsRunSp()
210 .get()
211 ->getMsRunReaderSPtr()
212 .get()
213 ->getMsRunId()
214 .get()
215 ->getXmlId()));
216 }
217 m_uiMonitor.appendText("Collecting peak apex");
218 msrun_peptide_list.get()->collectPeptidePeakRetentionTime(msrun_rt_reference_p);
219 msrun_peptide_list.get()->collectPeptideMs2RetentionTime(msrun_rt_reference_p);
220 }
221
222 cbor_output.writeQrDataBlock(m_uiMonitor, *msrun_peptide_list.get(), false);
223
224
225 msrun_peptide_list.get()->clearMeasurements();
226 }
227
228 cbor_output.getCborStreamWriter().endMap();
229
230 cbor_output.getCborStreamWriter().append(QLatin1String("timestamp2"));
231 cbor_output.getCborStreamWriter().append(QDateTime::currentDateTime().toString(Qt::ISODate));
232 if(match_between_run)
233 {
234 if(msrun_rt_reference_p != nullptr)
235 { // second pass
236
237 m_uiMonitor.appendText(
238 QObject::tr("Computing consensus retention time (%1)").arg(peptide_sp_list.size()));
239 for(const pappso::masschroq::PeptideSp &peptide_sp : peptide_sp_list)
240 {
241 peptide_sp.get()->computeConsensusRetentionTime();
242 }
243
244 cbor_output.getCborStreamWriter().append("second_pass");
245 cbor_output.getCborStreamWriter().startMap(m_msRunPeptideListSpList.size());
246 for(const pappso::masschroq::MsRunPeptideListSp &msrun_peptide_list :
248 {
249 const pappso::masschroq::MsRun *msrun_p =
250 msrun_peptide_list.get()->getMsRunSp().get();
251 std::vector<pappso::masschroq::PeptideSp> peptide_mbr_list;
252 for(const pappso::masschroq::PeptideSp &peptide_sp : peptide_sp_list)
253 {
254 if(!peptide_sp.get()->isObservedInMsRunSp(msrun_p))
255 {
256 peptide_mbr_list.push_back(peptide_sp);
257 }
258 }
259 msrun_peptide_list.get()->quantifyMatchBetweenRun(
260 this, peptide_mbr_list, tmp_dir, m_uiMonitor, quantification_method);
261
262
263 cbor_output.writeQrDataBlock(m_uiMonitor, *msrun_peptide_list.get(), true);
264
265 msrun_peptide_list.get()->clearMeasurements();
266 }
267
268 cbor_output.getCborStreamWriter().endMap();
269 }
270 }
271
272 cbor_output.getCborStreamWriter().append(QLatin1String("timestamp3"));
273 cbor_output.getCborStreamWriter().append(QDateTime::currentDateTime().toString(Qt::ISODate));
274 cbor_output.getCborStreamWriter().endMap();
275}
276
277void
279 const pappso::masschroq::AlignmentMethodSp &alignment_method_sp, const QString &msrun_ref_id)
280{
281 auto it = find_if(m_msRunPeptideListSpList.begin(),
283 [msrun_ref_id](const pappso::masschroq::MsRunPeptideListSp &msrun) {
284 if(msrun.get()
285 ->getMsRunSp()
286 .get()
287 ->getMsRunReaderSPtr()
288 .get()
289 ->getMsRunId()
290 .get()
291 ->getXmlId() == msrun_ref_id)
292 return true;
293 return false;
294 });
295 if(it != m_msRunPeptideListSpList.end())
296 {
297 msp_alignmentMethod = alignment_method_sp;
299 }
300 else
301 {
303 QObject::tr("msrun_id %1 not found in group %2").arg(msrun_ref_id).arg(m_id));
304 }
305}
306
307bool
309{
310 auto it = find_if(m_msRunPeptideListSpList.begin(),
312 [msrun_p](const pappso::masschroq::MsRunPeptideListSp &msrun) {
313 return (msrun.get()->getMsRunSp().get() == msrun_p);
314 });
315 return (it != m_msRunPeptideListSpList.end());
316}
317
318void
320 const std::shared_ptr<pappso::IonMobilityGrid> &ion_mobility_grid_sp)
321{
322 msp_ionMobilityGrid = ion_mobility_grid_sp;
323}
324
325bool
330
331const std::shared_ptr<pappso::IonMobilityGrid> &
336
337const QString &
339{
340 return m_id;
341}
const std::vector< MsRunRetentionTimeSeamarkPoint< T > > & getSeamarks() const
A simple container of DataPoint instances.
Definition trace.h:148
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