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();
51 mcsp_traceDetectionInterfaceCstSPtr = std::make_shared<TraceDetectionZivy>(1, 3, 2, 5000, 3000);
52 qDebug();
53}
54
67
68
72
73const QString &
78
79double
84
85void
90
91bool
96
97void
99{
100 if((ratio < 1) && (ratio >= 0))
101 {
102 m_isotopeMinimumRatio = ratio;
103 }
104}
105
106double
111
112void
114{
115 m_xicFilterSuite = std::make_shared<FilterSuiteString>(filter.get()->toString());
116}
117
118
119void
121{
122 if(m_xicFilterSuite.get() == nullptr)
123 {
124 m_xicFilterSuite = std::make_shared<FilterSuiteString>(filter.get()->toString());
125 }
126 else
127 {
128 m_xicFilterSuite.get()->addFilter(filter);
129 }
130}
131
137
138
153
159
160void
166
167void
172
173void
178
179void
184
190
191const MzRange
197
203
206{
207 ProjectParameters parameters;
208
209 ProjectParam project_param({ProjectParamCategory::quantification, "", QVariant()});
210 // xic_type="max"
211 project_param.name = "mcq_xic_extraction_type";
212 project_param.value.setValue(masschroq::Utils::enumToString(m_xicExtractMethod));
213 parameters.setProjectParam(project_param);
214
215 project_param.name = "mcq_mbr";
216 project_param.value.setValue(getMatchBetweenRun());
217 parameters.setProjectParam(project_param);
218
219 project_param.name = "mcq_isotope_minimum_ratio";
220 project_param.value.setValue(getIsotopeMinimumRatio());
221 parameters.setProjectParam(project_param);
222
223
225 {
226
227 //<!--For XIC extraction on Da use: mz_range-->
228 //<ppm_range min="10" max="10"/>
229
230 project_param.name = "mcq_xic_ppm_range_min";
231 project_param.value.setValue(mp_xicExtractionLowerPrecisionPtr->getNominal());
232 parameters.setProjectParam(project_param);
233
234 project_param.name = "mcq_xic_ppm_range_max";
235 project_param.value.setValue(mp_xicExtractionUppersPrecisionPtr->getNominal());
236 parameters.setProjectParam(project_param);
237 }
239 {
240
241 //<!--For XIC extraction on Da use: mz_range-->
242 //<ppm_range min="10" max="10"/>
243
244 project_param.name = "mcq_xic_mz_range_min";
245 project_param.value.setValue(mp_xicExtractionLowerPrecisionPtr->getNominal());
246 parameters.setProjectParam(project_param);
247
248 project_param.name = "mcq_xic_mz_range_max";
249 project_param.value.setValue(mp_xicExtractionUppersPrecisionPtr->getNominal());
250 parameters.setProjectParam(project_param);
251 }
252
253 project_param.name = "mcq_xic_pre_filter";
254 if(m_xicFilterSuite.get() != nullptr)
255 project_param.value.setValue(m_xicFilterSuite.get()->toString());
256 else
257 project_param.value.setValue("");
258 parameters.setProjectParam(project_param);
259
260
261 const TraceDetectionZivy *detection_zivy =
262 dynamic_cast<const TraceDetectionZivy *>(mcsp_traceDetectionInterfaceCstSPtr.get());
263
264 if(detection_zivy != nullptr)
265 {
266 project_param.name = "mcq_detection_zivy";
267 project_param.value.setValue(QString("%1 %2 %3 %4 %5")
268 .arg(detection_zivy->getSmoothingHalfEdgeWindows())
269 .arg(detection_zivy->getMinMaxHalfEdgeWindows())
270 .arg(detection_zivy->getMaxMinHalfEdgeWindows())
271 .arg(detection_zivy->getDetectionThresholdOnMinmax())
272 .arg(detection_zivy->getDetectionThresholdOnMaxmin()));
273 parameters.setProjectParam(project_param);
274 }
275 return parameters;
276}
277
278QJsonObject
280{
281 QJsonObject method;
282
283 qDebug();
284
285 QString xic_type = Utils::enumToString(m_xicExtractMethod);
286
288 {
289 throw PappsoException(
290 "mp_xicExtractionUppersPrecisionPtr == "
291 "nullptr");
292 }
294 {
295 throw PappsoException(
296 "mp_xicExtractionLowerPrecisionPtr == "
297 "nullptr");
298 }
299 qDebug();
300 QJsonObject precision;
301 precision.insert("unit", Utils::enumToString(mp_xicExtractionUppersPrecisionPtr->unit()));
302 precision.insert("down", mp_xicExtractionLowerPrecisionPtr->getNominal());
303 precision.insert("up", mp_xicExtractionUppersPrecisionPtr->getNominal());
304
305
306 QJsonObject extraction;
307 extraction.insert("integration", xic_type);
308 extraction.insert("precision", precision);
309
310 method.insert("extraction", extraction);
311 method.insert("match_between_run", m_matchBetweenRun);
312 method.insert("isotope_minimum_ratio", m_isotopeMinimumRatio);
313 method.insert("rt_range", m_xicExtractionRetentionTimeAroundTarget);
314
315 // xic_filters
316
317 if(m_xicFilterSuite.get() == nullptr)
318 {
319 throw PappsoException(
320 "m_xicFilterSuite.get() == "
321 "nullptr");
322 }
323 method.insert("pre_filter", m_xicFilterSuite.get()->toString());
324
325
326 const TraceDetectionZivy *detection_zivy =
327 dynamic_cast<const TraceDetectionZivy *>(getTraceDetectionInterfaceCstSPtr().get());
328
329 if(detection_zivy == nullptr)
330 {
331 throw PappsoException(
332 "m_quantificationMethod.getTraceDetectionInterfaceCstSPtr().get() == "
333 "nullptr");
334 }
335
336 QJsonObject detection;
337 detection.insert("type", "zivy");
338 detection.insert("meanfilter", (int)detection_zivy->getSmoothingHalfEdgeWindows());
339 detection.insert("minmax", (int)detection_zivy->getMinMaxHalfEdgeWindows());
340 detection.insert("maxmin", (int)detection_zivy->getMaxMinHalfEdgeWindows());
341 detection.insert("threshold_on_max", detection_zivy->getDetectionThresholdOnMinmax());
342 detection.insert("threshold_on_min", detection_zivy->getDetectionThresholdOnMaxmin());
343 method.insert("detection", detection);
344
345
346 return method;
347}
348
349void
350masschroq::QuantificationMethod::setJsonObject(const QJsonObject &quantification_method)
351{
352 m_matchBetweenRun = quantification_method.value("match_between_run").toBool();
353 m_isotopeMinimumRatio = quantification_method.value("isotope_minimum_ratio").toDouble();
354 QString filter_str = quantification_method.value("pre_filter").toString();
355
356 qDebug() << filter_str;
357 if(!filter_str.isEmpty())
358 {
359 FilterNameInterfaceSPtr filter_sp = std::make_shared<FilterSuiteString>(filter_str);
360 addXicFilter(filter_sp);
361 qDebug() << filter_str;
362 }
363 QJsonObject extraction = quantification_method.value("extraction").toObject();
364
365 QJsonValue rt_range = extraction.value("rt_range");
366 if(!rt_range.isUndefined())
367 {
368 setXicExtractionRtRange(rt_range.toDouble());
369 }
370
371 QString integration = extraction.value("integration").toString();
372 if(integration == "sum")
373 {
375 }
376 else if(integration == "max")
377 {
379 }
380 else
381 {
382 throw ExceptionNotFound(QObject::tr("missing "
383 "masschroq_methods>quantification_method>extraction>"
384 "integration %1 value")
385 .arg(integration));
386 }
387
388 QJsonObject precision = extraction.value("precision").toObject();
389 qDebug() << precision.value("down").toDouble();
390 qDebug() << precision.value("up").toDouble();
391
392 if(precision.value("unit").toString() == "dalton")
393 {
395 PrecisionFactory::getDaltonInstance(precision.value("down").toDouble()));
397 PrecisionFactory::getDaltonInstance(precision.value("up").toDouble()));
398 }
399 else if(precision.value("unit").toString() == "ppm")
400 {
402 PrecisionFactory::getPpmInstance(precision.value("down").toDouble()));
404 PrecisionFactory::getPpmInstance(precision.value("up").toDouble()));
405 }
406 else
407 {
408 throw ExceptionNotFound(
409 QObject::tr("missing "
410 "masschroq_methods>quantification_method>extraction>precision>"
411 "unit"));
412 }
413
414
415 QJsonObject detection = quantification_method.value("detection").toObject();
416 if(detection.value("type").toString() == "zivy")
417 {
418 std::shared_ptr<TraceDetectionZivy> sp_detection_zivy =
419 std::make_shared<TraceDetectionZivy>(detection.value("meanfilter").toInt(),
420 detection.value("minmax").toInt(),
421 detection.value("maxmin").toInt(),
422 detection.value("threshold_on_max").toInt(),
423 detection.value("threshold_on_min").toInt());
424 setTraceDetectionInterfaceCstSPtr(sp_detection_zivy);
425 }
426 else
427 {
428
429 throw ExceptionNotFound(
430 QObject::tr("only masschroq_methods>quantification_method>detection>type == zivy "
431 "allowed"));
432 }
433}
434
440
446
447void
452
453} // 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