libpappsomspp
Library for mass spectrometry
quantificationmethod.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/masschroq/quantificationmethod.cpp
3 * \date 24/10/2024
4 * \author Olivier Langella
5 * \brief store parameters related to peak detection and quantification
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
30#include "utils.h"
31#include "../pappsoexception.h"
32#include "../exception/exceptionnotfound.h"
33#include "../processing/detection/tracedetectionzivy.h"
34
36{
37 // by default
38 qDebug();
42
43 qDebug();
44 setXicFilter(std::make_shared<pappso::FilterMorphoAntiSpike>(5));
45
46 qDebug();
48 std::make_shared<pappso::TraceDetectionZivy>(1, 3, 2, 5000, 3000);
49 qDebug();
50}
51
54 : m_id(other.m_id)
55{
64}
65
66
68{
69}
70
71const QString &
73{
74 return m_id;
75}
76
77double
79{
80 return m_xicExtractionRetentionTimeAroundTarget;
81}
82
83void
85{
86 m_xicExtractionRetentionTimeAroundTarget = rt_range;
87}
88
89bool
91{
92 return m_matchBetweenRun;
93}
94
95void
97{
98 if((ratio < 1) && (ratio >= 0))
99 {
100 m_isotopeMinimumRatio = ratio;
101 }
102}
103
104double
106{
107 return m_isotopeMinimumRatio;
108}
109
110void
112{
113 m_xicFilterSuite = std::make_shared<pappso::FilterSuiteString>(filter.get()->toString());
114}
115
116
117void
119{
120 if(m_xicFilterSuite.get() == nullptr)
121 {
122 m_xicFilterSuite = std::make_shared<pappso::FilterSuiteString>(filter.get()->toString());
123 }
124 else
125 {
126 m_xicFilterSuite.get()->addFilter(filter);
127 }
128}
129
132{
133 return m_xicFilterSuite;
134}
135
136
139{
140
141 if(mp_xicExtractionLowerPrecisionPtr->unit() == pappso::PrecisionUnit::ppm)
142 {
144 (mp_xicExtractionLowerPrecisionPtr->getNominal() +
145 mp_xicExtractionUppersPrecisionPtr->getNominal()) /
146 2);
147 }
149 (mp_xicExtractionLowerPrecisionPtr->getNominal() +
150 mp_xicExtractionUppersPrecisionPtr->getNominal()) /
151 2);
152}
153
156{
157 return m_xicExtractMethod;
158}
159
160void
163{
164 mcsp_traceDetectionInterfaceCstSPtr = detection;
165}
166
167void
169 pappso::PrecisionPtr precision)
170{
171 mp_xicExtractionLowerPrecisionPtr = precision;
172}
173
174void
176 pappso::PrecisionPtr precision)
177{
178 mp_xicExtractionUppersPrecisionPtr = precision;
179}
180
181void
183{
184 m_xicExtractMethod = method;
185}
186
189{
190 return m_xicFilterSuite;
191}
192
193const pappso::MzRange
195{
196
197 return pappso::MzRange(mz, mp_xicExtractionLowerPrecisionPtr, mp_xicExtractionUppersPrecisionPtr);
198}
199
202{
203 return mcsp_traceDetectionInterfaceCstSPtr;
204}
205
208{
209 pappso::ProjectParameters parameters;
210
211 pappso::ProjectParam project_param(
213 // xic_type="max"
214 project_param.name = "mcq_xic_extraction_type";
215 project_param.value.setValue(pappso::masschroq::Utils::enumToString(m_xicExtractMethod));
216 parameters.setProjectParam(project_param);
217
218 project_param.name = "mcq_mbr";
219 project_param.value.setValue(getMatchBetweenRun());
220 parameters.setProjectParam(project_param);
221
222 project_param.name = "mcq_isotope_minimum_ratio";
223 project_param.value.setValue(getIsotopeMinimumRatio());
224 parameters.setProjectParam(project_param);
225
226
227 if(mp_xicExtractionLowerPrecisionPtr->unit() == pappso::PrecisionUnit::ppm)
228 {
229
230 //<!--For XIC extraction on Da use: mz_range-->
231 //<ppm_range min="10" max="10"/>
232
233 project_param.name = "mcq_xic_ppm_range_min";
234 project_param.value.setValue(mp_xicExtractionLowerPrecisionPtr->getNominal());
235 parameters.setProjectParam(project_param);
236
237 project_param.name = "mcq_xic_ppm_range_max";
238 project_param.value.setValue(mp_xicExtractionUppersPrecisionPtr->getNominal());
239 parameters.setProjectParam(project_param);
240 }
241 if(mp_xicExtractionLowerPrecisionPtr->unit() == pappso::PrecisionUnit::dalton)
242 {
243
244 //<!--For XIC extraction on Da use: mz_range-->
245 //<ppm_range min="10" max="10"/>
246
247 project_param.name = "mcq_xic_mz_range_min";
248 project_param.value.setValue(mp_xicExtractionLowerPrecisionPtr->getNominal());
249 parameters.setProjectParam(project_param);
250
251 project_param.name = "mcq_xic_mz_range_max";
252 project_param.value.setValue(mp_xicExtractionUppersPrecisionPtr->getNominal());
253 parameters.setProjectParam(project_param);
254 }
255
256 project_param.name = "mcq_xic_pre_filter";
257 if(m_xicFilterSuite.get() != nullptr)
258 project_param.value.setValue(m_xicFilterSuite.get()->toString());
259 else
260 project_param.value.setValue("");
261 parameters.setProjectParam(project_param);
262
263
264 const pappso::TraceDetectionZivy *detection_zivy =
265 dynamic_cast<const pappso::TraceDetectionZivy *>(mcsp_traceDetectionInterfaceCstSPtr.get());
266
267 if(detection_zivy != nullptr)
268 {
269 project_param.name = "mcq_detection_zivy";
270 project_param.value.setValue(QString("%1 %2 %3 %4 %5")
271 .arg(detection_zivy->getSmoothingHalfEdgeWindows())
272 .arg(detection_zivy->getMinMaxHalfEdgeWindows())
273 .arg(detection_zivy->getMaxMinHalfEdgeWindows())
274 .arg(detection_zivy->getDetectionThresholdOnMinmax())
275 .arg(detection_zivy->getDetectionThresholdOnMaxmin()));
276 parameters.setProjectParam(project_param);
277 }
278 return parameters;
279}
280
281QJsonObject
283{
284 QJsonObject method;
285
286 qDebug();
287
288 QString xic_type = Utils::enumToString(m_xicExtractMethod);
289
290 if(mp_xicExtractionUppersPrecisionPtr == nullptr)
291 {
293 "mp_xicExtractionUppersPrecisionPtr == "
294 "nullptr");
295 }
296 if(mp_xicExtractionLowerPrecisionPtr == nullptr)
297 {
299 "mp_xicExtractionLowerPrecisionPtr == "
300 "nullptr");
301 }
302 qDebug();
303 QJsonObject precision;
304 precision.insert("unit", Utils::enumToString(mp_xicExtractionUppersPrecisionPtr->unit()));
305 precision.insert("down", mp_xicExtractionLowerPrecisionPtr->getNominal());
306 precision.insert("up", mp_xicExtractionUppersPrecisionPtr->getNominal());
307
308
309 QJsonObject extraction;
310 extraction.insert("integration", xic_type);
311 extraction.insert("precision", precision);
312
313 method.insert("extraction", extraction);
314 method.insert("match_between_run", m_matchBetweenRun);
315 method.insert("isotope_minimum_ratio", m_isotopeMinimumRatio);
316 method.insert("rt_range", m_xicExtractionRetentionTimeAroundTarget);
317
318 // xic_filters
319
320 if(m_xicFilterSuite.get() == nullptr)
321 {
323 "m_xicFilterSuite.get() == "
324 "nullptr");
325 }
326 method.insert("pre_filter", m_xicFilterSuite.get()->toString());
327
328
329 const pappso::TraceDetectionZivy *detection_zivy =
330 dynamic_cast<const pappso::TraceDetectionZivy *>(getTraceDetectionInterfaceCstSPtr().get());
331
332 if(detection_zivy == nullptr)
333 {
335 "m_quantificationMethod.getTraceDetectionInterfaceCstSPtr().get() == "
336 "nullptr");
337 }
338
339 QJsonObject detection;
340 detection.insert("type", "zivy");
341 detection.insert("meanfilter", (int)detection_zivy->getSmoothingHalfEdgeWindows());
342 detection.insert("minmax", (int)detection_zivy->getMinMaxHalfEdgeWindows());
343 detection.insert("maxmin", (int)detection_zivy->getMaxMinHalfEdgeWindows());
344 detection.insert("threshold_on_max", detection_zivy->getDetectionThresholdOnMinmax());
345 detection.insert("threshold_on_min", detection_zivy->getDetectionThresholdOnMaxmin());
346 method.insert("detection", detection);
347
348
349 return method;
350}
351
352void
353pappso::masschroq::QuantificationMethod::setJsonObject(const QJsonObject &quantification_method)
354{
355 m_matchBetweenRun = quantification_method.value("match_between_run").toBool();
356 m_isotopeMinimumRatio = quantification_method.value("isotope_minimum_ratio").toDouble();
357 QString filter_str = quantification_method.value("pre_filter").toString();
358
359 qDebug() << filter_str;
360 if(!filter_str.isEmpty())
361 {
363 std::make_shared<pappso::FilterSuiteString>(filter_str);
364 addXicFilter(filter_sp);
365 qDebug() << filter_str;
366 }
367 QJsonObject extraction = quantification_method.value("extraction").toObject();
368
369 QJsonValue rt_range = extraction.value("rt_range");
370 if(!rt_range.isUndefined())
371 {
372 setXicExtractionRtRange(rt_range.toDouble());
373 }
374
375 QString integration = extraction.value("integration").toString();
376 if(integration == "sum")
377 {
378 setXicExtractMethod(pappso::XicExtractMethod::sum);
379 }
380 else if(integration == "max")
381 {
382 setXicExtractMethod(pappso::XicExtractMethod::max);
383 }
384 else
385 {
387 QObject::tr("missing "
388 "masschroq_methods>quantification_method>extraction>"
389 "integration %1 value")
390 .arg(integration));
391 }
392
393 QJsonObject precision = extraction.value("precision").toObject();
394 qDebug() << precision.value("down").toDouble();
395 qDebug() << precision.value("up").toDouble();
396
397 if(precision.value("unit").toString() == "dalton")
398 {
399 setXicExtractionLowerPrecisionPtr(
400 pappso::PrecisionFactory::getDaltonInstance(precision.value("down").toDouble()));
401 setXicExtractionUpperPrecisionPtr(
402 pappso::PrecisionFactory::getDaltonInstance(precision.value("up").toDouble()));
403 }
404 else if(precision.value("unit").toString() == "ppm")
405 {
406 setXicExtractionLowerPrecisionPtr(
407 pappso::PrecisionFactory::getPpmInstance(precision.value("down").toDouble()));
408 setXicExtractionUpperPrecisionPtr(
409 pappso::PrecisionFactory::getPpmInstance(precision.value("up").toDouble()));
410 }
411 else
412 {
414 QObject::tr("missing "
415 "masschroq_methods>quantification_method>extraction>precision>"
416 "unit"));
417 }
418
419
420 QJsonObject detection = quantification_method.value("detection").toObject();
421 if(detection.value("type").toString() == "zivy")
422 {
423 std::shared_ptr<pappso::TraceDetectionZivy> sp_detection_zivy =
424 std::make_shared<pappso::TraceDetectionZivy>(detection.value("meanfilter").toInt(),
425 detection.value("minmax").toInt(),
426 detection.value("maxmin").toInt(),
427 detection.value("threshold_on_max").toInt(),
428 detection.value("threshold_on_min").toInt());
429 setTraceDetectionInterfaceCstSPtr(sp_detection_zivy);
430 }
431 else
432 {
433
435 QObject::tr("only masschroq_methods>quantification_method>detection>type == zivy "
436 "allowed"));
437 }
438}
439
442{
443 return mp_xicExtractionLowerPrecisionPtr;
444}
445
448{
449 return mp_xicExtractionUppersPrecisionPtr;
450}
451
452void
454{
455 m_matchBetweenRun = is_match;
456}
static PrecisionPtr getPpmInstance(pappso_double value)
get a ppm precision pointer
Definition: precision.cpp:154
static PrecisionPtr getDaltonInstance(pappso_double value)
get a Dalton precision pointer
Definition: precision.cpp:135
void setProjectParam(const ProjectParam &param)
unsigned int getMinMaxHalfEdgeWindows() const
unsigned int getSmoothingHalfEdgeWindows() const
double getDetectionThresholdOnMinmax() const
double getDetectionThresholdOnMaxmin() const
unsigned int getMaxMinHalfEdgeWindows() const
void setXicExtractMethod(pappso::XicExtractMethod method)
pappso::FilterSuiteStringSPtr m_xicFilterSuite
the xic filters
void setXicExtractionUpperPrecisionPtr(pappso::PrecisionPtr precision)
pappso::XicExtractMethod getXicExtractMethod() const
pappso::TraceDetectionInterfaceCstSPtr mcsp_traceDetectionInterfaceCstSPtr
the peak detection method for this quantification
double m_xicExtractionRetentionTimeAroundTarget
set the retention time range in seconds around the target rt
void setJsonObject(const QJsonObject &json_object)
pappso::PrecisionPtr getXicExtractionLowerPrecisionPtr() const
const pappso::MzRange getXicExtractionMzRange(double mz) const
const pappso::FilterNameInterfaceSPtr getXicFilter() const
void setXicFilter(const pappso::FilterNameInterfaceSPtr &filter)
void addXicFilter(const pappso::FilterNameInterfaceSPtr &filter)
const FilterSuiteStringSPtr & getFilterSuiteStringSPtr() const
pappso::PrecisionPtr getXicExtractionUppersPrecisionPtr() const
double m_isotopeMinimumRatio
the minimum percentage of theoretical intensity of the isotope pattern to compute
pappso::PrecisionPtr getXicExtractionMeanPrecisionPtr() const
pappso::ProjectParameters getProjectParameters() const
const pappso::TraceDetectionInterfaceCstSPtr & getTraceDetectionInterfaceCstSPtr() const
void setXicExtractionLowerPrecisionPtr(pappso::PrecisionPtr precision)
void setTraceDetectionInterfaceCstSPtr(const pappso::TraceDetectionInterfaceCstSPtr &detection)
static QString enumToString(PeakQualityCategory peak_category)
Convenience function to return a string describing the specglob alingment type.
Definition: utils.cpp:44
std::shared_ptr< FilterSuiteString > FilterSuiteStringSPtr
std::shared_ptr< const TraceDetectionInterface > TraceDetectionInterfaceCstSPtr
@ quantification
quantification
@ filter
concerning filters (psm, peptide, protein validation)
std::shared_ptr< FilterNameInterface > FilterNameInterfaceSPtr
XicExtractMethod
Definition: types.h:258
@ sum
sum of intensities
@ max
maximum of intensities
store parameters related to peak detection and quantification