OpenMS
AppliedProcessingStep.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, OpenMS Inc. -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Hendrik Weisser $
6 // $Authors: Hendrik Weisser $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
13 
14 #include <boost/range/adaptor/reversed.hpp>
15 #include <boost/multi_index_container.hpp>
16 #include <boost/multi_index/member.hpp>
17 #include <boost/multi_index/ordered_index.hpp>
18 #include <boost/multi_index/sequenced_index.hpp>
19 
20 #include <optional>
21 
22 namespace OpenMS
23 {
24  namespace IdentificationDataInternal
25  {
30  {
36  std::optional<ProcessingStepRef> processing_step_opt;
37 
39  std::map<ScoreTypeRef, double> scores;
40 
43  const std::optional<ProcessingStepRef>& processing_step_opt =
44  std::nullopt, const std::map<ScoreTypeRef, double>& scores =
45  std::map<ScoreTypeRef, double>()):
47  {
48  }
49 
51  bool operator==(const AppliedProcessingStep& other) const
52  {
53  return ((processing_step_opt == other.processing_step_opt) &&
54  (scores == other.scores));
55  }
56 
65  std::vector<std::pair<ScoreTypeRef, double>>
66  getScoresInOrder(bool primary_only = false) const
67  {
68  std::vector<std::pair<ScoreTypeRef, double>> result;
69  std::set<ScoreTypeRef> scores_done;
70 
72  {
73  ProcessingSoftwareRef sw_ref = (*processing_step_opt)->software_ref;
74  for (ScoreTypeRef score_ref : sw_ref->assigned_scores)
75  {
76  auto pos = scores.find(score_ref);
77  if (pos != scores.end())
78  {
79  result.push_back(*pos);
80  if (primary_only) return result;
81  scores_done.insert(score_ref);
82  }
83  }
84  }
85  for (const auto& pair: scores)
86  {
87  if (!scores_done.count(pair.first))
88  {
89  result.push_back(pair);
90  if (primary_only) return result;
91  }
92  }
93  return result;
94  }
95  };
96 
97  // we want to keep track of the processing steps in sequence (order of
98  // application), but also ensure there are no duplicate steps:
99  typedef boost::multi_index_container<
100  AppliedProcessingStep,
101  boost::multi_index::indexed_by<
102  boost::multi_index::sequenced<>,
103  boost::multi_index::ordered_unique<
104  boost::multi_index::member<
105  AppliedProcessingStep, std::optional<ProcessingStepRef>,
108 
109  }
110 }
boost::multi_index_container< AppliedProcessingStep, boost::multi_index::indexed_by< boost::multi_index::sequenced<>, boost::multi_index::ordered_unique< boost::multi_index::member< AppliedProcessingStep, std::optional< ProcessingStepRef >, &AppliedProcessingStep::processing_step_opt > > > > AppliedProcessingSteps
Definition: AppliedProcessingStep.h:107
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Definition: AppliedProcessingStep.h:30
std::map< ScoreTypeRef, double > scores
Map of scores and their types.
Definition: AppliedProcessingStep.h:39
bool operator==(const AppliedProcessingStep &other) const
Equality operator (needed for multi-index container)
Definition: AppliedProcessingStep.h:51
std::optional< ProcessingStepRef > processing_step_opt
(Optional) reference to the processing step
Definition: AppliedProcessingStep.h:36
std::vector< std::pair< ScoreTypeRef, double > > getScoresInOrder(bool primary_only=false) const
Return scores in order of priority (primary first).
Definition: AppliedProcessingStep.h:66
AppliedProcessingStep(const std::optional< ProcessingStepRef > &processing_step_opt=std::nullopt, const std::map< ScoreTypeRef, double > &scores=std::map< ScoreTypeRef, double >())
Constructor.
Definition: AppliedProcessingStep.h:42