OpenMS  2.8.0
AppliedProcessingStep.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2021.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Hendrik Weisser $
32 // $Authors: Hendrik Weisser $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
39 
40 #include <boost/range/adaptor/reversed.hpp>
41 #include <boost/multi_index_container.hpp>
42 #include <boost/multi_index/member.hpp>
43 #include <boost/multi_index/ordered_index.hpp>
44 #include <boost/multi_index/sequenced_index.hpp>
45 
46 #include <optional>
47 
48 namespace OpenMS
49 {
50  namespace IdentificationDataInternal
51  {
56  {
62  std::optional<ProcessingStepRef> processing_step_opt;
63 
65  std::map<ScoreTypeRef, double> scores;
66 
69  const std::optional<ProcessingStepRef>& processing_step_opt =
70  std::nullopt, const std::map<ScoreTypeRef, double>& scores =
71  std::map<ScoreTypeRef, double>()):
73  {
74  }
75 
77  bool operator==(const AppliedProcessingStep& other) const
78  {
79  return ((processing_step_opt == other.processing_step_opt) &&
80  (scores == other.scores));
81  }
82 
91  std::vector<std::pair<ScoreTypeRef, double>>
92  getScoresInOrder(bool primary_only = false) const
93  {
94  std::vector<std::pair<ScoreTypeRef, double>> result;
95  std::set<ScoreTypeRef> scores_done;
96 
98  {
99  ProcessingSoftwareRef sw_ref = (*processing_step_opt)->software_ref;
100  for (ScoreTypeRef score_ref : sw_ref->assigned_scores)
101  {
102  auto pos = scores.find(score_ref);
103  if (pos != scores.end())
104  {
105  result.push_back(*pos);
106  if (primary_only) return result;
107  scores_done.insert(score_ref);
108  }
109  }
110  }
111  for (const auto& pair: scores)
112  {
113  if (!scores_done.count(pair.first))
114  {
115  result.push_back(pair);
116  if (primary_only) return result;
117  }
118  }
119  return result;
120  }
121  };
122 
123  // we want to keep track of the processing steps in sequence (order of
124  // application), but also ensure there are no duplicate steps:
125  typedef boost::multi_index_container<
126  AppliedProcessingStep,
127  boost::multi_index::indexed_by<
128  boost::multi_index::sequenced<>,
129  boost::multi_index::ordered_unique<
130  boost::multi_index::member<
131  AppliedProcessingStep, std::optional<ProcessingStepRef>,
134 
135  }
136 }
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:133
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Definition: AppliedProcessingStep.h:56
std::map< ScoreTypeRef, double > scores
Map of scores and their types.
Definition: AppliedProcessingStep.h:65
bool operator==(const AppliedProcessingStep &other) const
Equality operator (needed for multi-index container)
Definition: AppliedProcessingStep.h:77
std::optional< ProcessingStepRef > processing_step_opt
(Optional) reference to the processing step
Definition: AppliedProcessingStep.h:62
std::vector< std::pair< ScoreTypeRef, double > > getScoresInOrder(bool primary_only=false) const
Return scores in order of priority (primary first).
Definition: AppliedProcessingStep.h:92
AppliedProcessingStep(const std::optional< ProcessingStepRef > &processing_step_opt=std::nullopt, const std::map< ScoreTypeRef, double > &scores=std::map< ScoreTypeRef, double >())
Constructor.
Definition: AppliedProcessingStep.h:68