OpenMS  2.7.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 namespace OpenMS
47 {
48  namespace IdentificationDataInternal
49  {
53  {
54  // if there are only scores, the processing step may be missing:
55  boost::optional<ProcessingStepRef> processing_step_opt;
56  std::map<ScoreTypeRef, double> scores;
57 
59  const boost::optional<ProcessingStepRef>& processing_step_opt =
60  boost::none, const std::map<ScoreTypeRef, double>& scores =
61  std::map<ScoreTypeRef, double>()):
63  {
64  }
65 
66  bool operator==(const AppliedProcessingStep& other) const
67  {
68  return ((processing_step_opt == other.processing_step_opt) &&
69  (scores == other.scores));
70  }
71 
77  std::vector<std::pair<ScoreTypeRef, double>> getScoresInOrder() const
78  {
79  std::vector<std::pair<ScoreTypeRef, double>> result;
80  std::set<ScoreTypeRef> scores_done;
81 
83  {
84  ProcessingSoftwareRef sw_ref = (*processing_step_opt)->software_ref;
85  for (ScoreTypeRef score_ref : sw_ref->assigned_scores)
86  {
87  auto pos = scores.find(score_ref);
88  if (pos != scores.end())
89  {
90  result.push_back(*pos);
91  scores_done.insert(score_ref);
92  }
93  }
94  }
95  for (const auto& pair: scores)
96  {
97  if (!scores_done.count(pair.first))
98  {
99  result.push_back(pair);
100  }
101  }
102  return result;
103  }
104  };
105 
106  // we want to keep track of the processing steps in sequence (order of
107  // application), but also ensure there are no duplicate steps:
108  typedef boost::multi_index_container<
109  AppliedProcessingStep,
110  boost::multi_index::indexed_by<
111  boost::multi_index::sequenced<>,
112  boost::multi_index::ordered_unique<
113  boost::multi_index::member<
114  AppliedProcessingStep, boost::optional<ProcessingStepRef>,
117 
118  }
119 }
boost::multi_index_container< AppliedProcessingStep, boost::multi_index::indexed_by< boost::multi_index::sequenced<>, boost::multi_index::ordered_unique< boost::multi_index::member< AppliedProcessingStep, boost::optional< ProcessingStepRef >, &AppliedProcessingStep::processing_step_opt > > > > AppliedProcessingSteps
Definition: AppliedProcessingStep.h:116
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
A processing step that was applied to a data item, possibly with associated scores.
Definition: AppliedProcessingStep.h:53
std::map< ScoreTypeRef, double > scores
Definition: AppliedProcessingStep.h:56
bool operator==(const AppliedProcessingStep &other) const
Definition: AppliedProcessingStep.h:66
boost::optional< ProcessingStepRef > processing_step_opt
Definition: AppliedProcessingStep.h:55
std::vector< std::pair< ScoreTypeRef, double > > getScoresInOrder() const
Return scores in order of priority (primary first).
Definition: AppliedProcessingStep.h:77
AppliedProcessingStep(const boost::optional< ProcessingStepRef > &processing_step_opt=boost::none, const std::map< ScoreTypeRef, double > &scores=std::map< ScoreTypeRef, double >())
Definition: AppliedProcessingStep.h:58