libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
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
29#include "types.h"
31#include "utils.h"
35
36namespace pappso
37{
38
40{
41 // by default
42 qDebug();
46
47 qDebug();
48 setXicFilter(std::make_shared<FilterMorphoAntiSpike>(5));
49
50 qDebug();
52 std::make_shared<TraceDetectionZivy>(1, 3, 2, 5000, 3000);
53 qDebug();
54}
55
69
70
74
75const QString &
80
81double
86
87void
92
93bool
98
99void
101{
102 if((ratio < 1) && (ratio >= 0))
103 {
104 m_isotopeMinimumRatio = ratio;
105 }
106}
107
108double
113
114void
116{
117 m_xicFilterSuite = std::make_shared<FilterSuiteString>(filter.get()->toString());
118}
119
120
121void
123{
124 if(m_xicFilterSuite.get() == nullptr)
125 {
126 m_xicFilterSuite = std::make_shared<FilterSuiteString>(filter.get()->toString());
127 }
128 else
129 {
130 m_xicFilterSuite.get()->addFilter(filter);
131 }
132}
133
139
140
157
163
164void
170
171void
177
178void
184
185void
190
196
197const MzRange
203
209
212{
213 ProjectParameters parameters;
214
215 ProjectParam project_param(
216 {ProjectParamCategory::quantification, "", QVariant()});
217 // xic_type="max"
218 project_param.name = "mcq_xic_extraction_type";
219 project_param.value.setValue(masschroq::Utils::enumToString(m_xicExtractMethod));
220 parameters.setProjectParam(project_param);
221
222 project_param.name = "mcq_mbr";
223 project_param.value.setValue(getMatchBetweenRun());
224 parameters.setProjectParam(project_param);
225
226 project_param.name = "mcq_isotope_minimum_ratio";
227 project_param.value.setValue(getIsotopeMinimumRatio());
228 parameters.setProjectParam(project_param);
229
230
232 {
233
234 //<!--For XIC extraction on Da use: mz_range-->
235 //<ppm_range min="10" max="10"/>
236
237 project_param.name = "mcq_xic_ppm_range_min";
238 project_param.value.setValue(mp_xicExtractionLowerPrecisionPtr->getNominal());
239 parameters.setProjectParam(project_param);
240
241 project_param.name = "mcq_xic_ppm_range_max";
242 project_param.value.setValue(mp_xicExtractionUppersPrecisionPtr->getNominal());
243 parameters.setProjectParam(project_param);
244 }
246 {
247
248 //<!--For XIC extraction on Da use: mz_range-->
249 //<ppm_range min="10" max="10"/>
250
251 project_param.name = "mcq_xic_mz_range_min";
252 project_param.value.setValue(mp_xicExtractionLowerPrecisionPtr->getNominal());
253 parameters.setProjectParam(project_param);
254
255 project_param.name = "mcq_xic_mz_range_max";
256 project_param.value.setValue(mp_xicExtractionUppersPrecisionPtr->getNominal());
257 parameters.setProjectParam(project_param);
258 }
259
260 project_param.name = "mcq_xic_pre_filter";
261 if(m_xicFilterSuite.get() != nullptr)
262 project_param.value.setValue(m_xicFilterSuite.get()->toString());
263 else
264 project_param.value.setValue("");
265 parameters.setProjectParam(project_param);
266
267
268 const TraceDetectionZivy *detection_zivy =
269 dynamic_cast<const TraceDetectionZivy *>(mcsp_traceDetectionInterfaceCstSPtr.get());
270
271 if(detection_zivy != nullptr)
272 {
273 project_param.name = "mcq_detection_zivy";
274 project_param.value.setValue(QString("%1 %2 %3 %4 %5")
275 .arg(detection_zivy->getSmoothingHalfEdgeWindows())
276 .arg(detection_zivy->getMinMaxHalfEdgeWindows())
277 .arg(detection_zivy->getMaxMinHalfEdgeWindows())
278 .arg(detection_zivy->getDetectionThresholdOnMinmax())
279 .arg(detection_zivy->getDetectionThresholdOnMaxmin()));
280 parameters.setProjectParam(project_param);
281 }
282 return parameters;
283}
284
285QJsonObject
287{
288 QJsonObject method;
289
290 qDebug();
291
292 QString xic_type = Utils::enumToString(m_xicExtractMethod);
293
295 {
296 throw PappsoException(
297 "mp_xicExtractionUppersPrecisionPtr == "
298 "nullptr");
299 }
301 {
302 throw PappsoException(
303 "mp_xicExtractionLowerPrecisionPtr == "
304 "nullptr");
305 }
306 qDebug();
307 QJsonObject precision;
308 precision.insert("unit", Utils::enumToString(mp_xicExtractionUppersPrecisionPtr->unit()));
309 precision.insert("down", mp_xicExtractionLowerPrecisionPtr->getNominal());
310 precision.insert("up", mp_xicExtractionUppersPrecisionPtr->getNominal());
311
312
313 QJsonObject extraction;
314 extraction.insert("integration", xic_type);
315 extraction.insert("precision", precision);
316
317 method.insert("extraction", extraction);
318 method.insert("match_between_run", m_matchBetweenRun);
319 method.insert("isotope_minimum_ratio", m_isotopeMinimumRatio);
320 method.insert("rt_range", m_xicExtractionRetentionTimeAroundTarget);
321
322 // xic_filters
323
324 if(m_xicFilterSuite.get() == nullptr)
325 {
326 throw PappsoException(
327 "m_xicFilterSuite.get() == "
328 "nullptr");
329 }
330 method.insert("pre_filter", m_xicFilterSuite.get()->toString());
331
332
333 const TraceDetectionZivy *detection_zivy =
334 dynamic_cast<const TraceDetectionZivy *>(getTraceDetectionInterfaceCstSPtr().get());
335
336 if(detection_zivy == nullptr)
337 {
338 throw PappsoException(
339 "m_quantificationMethod.getTraceDetectionInterfaceCstSPtr().get() == "
340 "nullptr");
341 }
342
343 QJsonObject detection;
344 detection.insert("type", "zivy");
345 detection.insert("meanfilter", (int)detection_zivy->getSmoothingHalfEdgeWindows());
346 detection.insert("minmax", (int)detection_zivy->getMinMaxHalfEdgeWindows());
347 detection.insert("maxmin", (int)detection_zivy->getMaxMinHalfEdgeWindows());
348 detection.insert("threshold_on_max", detection_zivy->getDetectionThresholdOnMinmax());
349 detection.insert("threshold_on_min", detection_zivy->getDetectionThresholdOnMaxmin());
350 method.insert("detection", detection);
351
352
353 return method;
354}
355
356void
357masschroq::QuantificationMethod::setJsonObject(const QJsonObject &quantification_method)
358{
359 m_matchBetweenRun = quantification_method.value("match_between_run").toBool();
360 m_isotopeMinimumRatio = quantification_method.value("isotope_minimum_ratio").toDouble();
361 QString filter_str = quantification_method.value("pre_filter").toString();
362
363 qDebug() << filter_str;
364 if(!filter_str.isEmpty())
365 {
366 FilterNameInterfaceSPtr filter_sp =
367 std::make_shared<FilterSuiteString>(filter_str);
368 addXicFilter(filter_sp);
369 qDebug() << filter_str;
370 }
371 QJsonObject extraction = quantification_method.value("extraction").toObject();
372
373 QJsonValue rt_range = extraction.value("rt_range");
374 if(!rt_range.isUndefined())
375 {
376 setXicExtractionRtRange(rt_range.toDouble());
377 }
378
379 QString integration = extraction.value("integration").toString();
380 if(integration == "sum")
381 {
383 }
384 else if(integration == "max")
385 {
387 }
388 else
389 {
390 throw ExceptionNotFound(
391 QObject::tr("missing "
392 "masschroq_methods>quantification_method>extraction>"
393 "integration %1 value")
394 .arg(integration));
395 }
396
397 QJsonObject precision = extraction.value("precision").toObject();
398 qDebug() << precision.value("down").toDouble();
399 qDebug() << precision.value("up").toDouble();
400
401 if(precision.value("unit").toString() == "dalton")
402 {
404 PrecisionFactory::getDaltonInstance(precision.value("down").toDouble()));
406 PrecisionFactory::getDaltonInstance(precision.value("up").toDouble()));
407 }
408 else if(precision.value("unit").toString() == "ppm")
409 {
411 PrecisionFactory::getPpmInstance(precision.value("down").toDouble()));
413 PrecisionFactory::getPpmInstance(precision.value("up").toDouble()));
414 }
415 else
416 {
417 throw ExceptionNotFound(
418 QObject::tr("missing "
419 "masschroq_methods>quantification_method>extraction>precision>"
420 "unit"));
421 }
422
423
424 QJsonObject detection = quantification_method.value("detection").toObject();
425 if(detection.value("type").toString() == "zivy")
426 {
427 std::shared_ptr<TraceDetectionZivy> sp_detection_zivy =
428 std::make_shared<TraceDetectionZivy>(detection.value("meanfilter").toInt(),
429 detection.value("minmax").toInt(),
430 detection.value("maxmin").toInt(),
431 detection.value("threshold_on_max").toInt(),
432 detection.value("threshold_on_min").toInt());
433 setTraceDetectionInterfaceCstSPtr(sp_detection_zivy);
434 }
435 else
436 {
437
438 throw ExceptionNotFound(
439 QObject::tr("only masschroq_methods>quantification_method>detection>type == zivy "
440 "allowed"));
441 }
442}
443
449
455
456void
461
462} // namespace pappso
static PrecisionPtr getPpmInstance(pappso_double value)
get a ppm precision pointer
static PrecisionPtr getDaltonInstance(pappso_double value)
get a Dalton precision pointer
void setProjectParam(const ProjectParam &param)
unsigned int getMinMaxHalfEdgeWindows() const
unsigned int getSmoothingHalfEdgeWindows() const
unsigned int getMaxMinHalfEdgeWindows() const
const pappso::TraceDetectionInterfaceCstSPtr & getTraceDetectionInterfaceCstSPtr() const
Enums::XicExtractMethod getXicExtractMethod() const
pappso::FilterSuiteStringSPtr m_xicFilterSuite
the xic filters
void setXicExtractionUpperPrecisionPtr(pappso::PrecisionPtr precision)
pappso::PrecisionPtr getXicExtractionMeanPrecisionPtr() const
pappso::PrecisionPtr getXicExtractionUppersPrecisionPtr() 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)
void setXicExtractMethod(Enums::XicExtractMethod method)
pappso::ProjectParameters getProjectParameters() const
pappso::PrecisionPtr getXicExtractionLowerPrecisionPtr() const
void setXicFilter(const pappso::FilterNameInterfaceSPtr &filter)
void addXicFilter(const pappso::FilterNameInterfaceSPtr &filter)
const FilterSuiteStringSPtr & getFilterSuiteStringSPtr() const
const pappso::MzRange getXicExtractionMzRange(double mz) const
double m_isotopeMinimumRatio
the minimum percentage of theoretical intensity of the isotope pattern to compute
void setXicExtractionLowerPrecisionPtr(pappso::PrecisionPtr precision)
void setTraceDetectionInterfaceCstSPtr(const pappso::TraceDetectionInterfaceCstSPtr &detection)
const pappso::FilterNameInterfaceSPtr getXicFilter() const
static QString enumToString(PeakQualityCategory peak_category)
Convenience function to return a string describing the specglob alingment type.
Definition utils.cpp:44
@ sum
sum of intensities
Definition types.h:279
@ max
maximum of intensities
Definition types.h:280
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
std::shared_ptr< FilterSuiteString > FilterSuiteStringSPtr
std::shared_ptr< const TraceDetectionInterface > TraceDetectionInterfaceCstSPtr
@ filter
concerning filters (psm, peptide, protein validation)
std::shared_ptr< FilterNameInterface > FilterNameInterfaceSPtr
const PrecisionBase * PrecisionPtr
Definition precision.h:122