| OpenMS 2.5.0

ScoredProcessingResult.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-2020.
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
37 #include <OpenMS/METADATA/ID/AppliedProcessingStep.h>
38
39 namespace OpenMS
40 {
41 namespace IdentificationDataInternal
42 {
44 struct ScoredProcessingResult: public MetaInfoInterface
45 {
46 AppliedProcessingSteps steps_and_scores;
47
49 AppliedProcessingSteps::nth_index<1>::type& getStepsAndScoresByStep()
50 {
51 return steps_and_scores.get<1>();
52 }
53
55 const AppliedProcessingSteps::nth_index<1>::type&
56 getStepsAndScoresByStep() const
57 {
58 return steps_and_scores.get<1>();
59 }
60
66 void addProcessingStep(const AppliedProcessingStep& step)
67 {
68 auto step_pos =
69 steps_and_scores.get<1>().find(step.processing_step_opt);
70 if (step_pos == steps_and_scores.get<1>().end()) // new step
71 {
72 steps_and_scores.push_back(step);
73 }
74 else // existing step - add or update scores
75 {
76 steps_and_scores.get<1>().modify(
77 step_pos, [&](AppliedProcessingStep& old_step)
78 {
79 for (const auto& pair : step.scores)
80 {
81 old_step.scores[pair.first] = pair.second;
82 }
83 });
84 }
85 }
86
88 void addProcessingStep(ProcessingStepRef step_ref,
89 const std::map<ScoreTypeRef, double>& scores =
90 std::map<ScoreTypeRef, double>())
91 {
92 AppliedProcessingStep applied(step_ref, scores);
93 addProcessingStep(applied);
94 }
95
97 void addScore(ScoreTypeRef score_type, double score,
98 const boost::optional<ProcessingStepRef>&
99 processing_step_opt = boost::none)
100 {
101 AppliedProcessingStep applied(processing_step_opt);
102 applied.scores[score_type] = score;
103 addProcessingStep(applied);
104 }
105
107 ScoredProcessingResult& operator+=(const ScoredProcessingResult& other)
108 {
109 // merge applied processing steps and scores:
110 for (const auto& step : other.steps_and_scores)
111 {
112 addProcessingStep(step);
113 }
114 // merge meta info - existing entries may be overwritten:
115 std::vector<UInt> keys;
116 other.getKeys(keys);
117 for (const UInt key : keys)
118 {
119 setMetaValue(key, other.getMetaValue(key));
120 }
121
122 return *this;
123 }
124
132 std::pair<double, bool> getScore(ScoreTypeRef score_ref) const
133 {
134 std::tuple<double, boost::optional<ProcessingStepRef>, bool> result =
135 getScoreAndStep(score_ref);
136 return std::make_pair(std::get<0>(result), std::get<2>(result));
137 }
138
144 std::pair<double, bool> getScore(ScoreTypeRef score_ref,
145 boost::optional<ProcessingStepRef>
146 processing_step_opt) const
147 {
148 auto step_pos = steps_and_scores.get<1>().find(processing_step_opt);
149 if (step_pos != steps_and_scores.get<1>().end())
150 {
151 auto score_pos = step_pos->scores.find(score_ref);
152 if (score_pos != step_pos->scores.end())
153 {
154 return std::make_pair(score_pos->second, true);
155 }
156 }
157 // not found:
158 return std::make_pair(std::numeric_limits<double>::quiet_NaN(), false);
159 }
160
168 std::tuple<double, boost::optional<ProcessingStepRef>, bool>
169 getScoreAndStep(ScoreTypeRef score_ref) const
170 {
171 // give priority to scores from later processing steps:
172 for (const auto& step : boost::adaptors::reverse(steps_and_scores))
173 {
174 auto pos = step.scores.find(score_ref);
175 if (pos != step.scores.end())
176 {
177 return std::make_tuple(pos->second, step.processing_step_opt, true);
178 }
179 }
180 // not found:
181 return std::make_tuple(std::numeric_limits<double>::quiet_NaN(),
182 boost::none, false);
183 }
184
185 protected:
186 explicit ScoredProcessingResult(
187 const AppliedProcessingSteps& steps_and_scores =
188 AppliedProcessingSteps()):
189 steps_and_scores(steps_and_scores)
190 {
191 }
192
193 ScoredProcessingResult(const ScoredProcessingResult&) = default;
194 };
195
196 }
197 }
OpenMS::MetaInfoInterface::getMetaValue
const DataValue & getMetaValue(const String &name, const DataValue &default_value=DataValue::EMPTY) const
Returns the value corresponding to a string, or a default value (default: DataValue::EMPTY) if not fo...
OpenMS::MetaInfoInterface::getKeys
void getKeys(std::vector< String > &keys) const
Fills the given vector with a list of all keys for which a value is set.
OpenMS::IdentificationDataInternal::ScoredProcessingResult::getScoreAndStep
std::tuple< double, boost::optional< ProcessingStepRef >, bool > getScoreAndStep(ScoreTypeRef score_ref) const
Definition: ScoredProcessingResult.h:169
AppliedProcessingStep.h
OpenMS::IdentificationDataInternal::ScoredProcessingResult::getStepsAndScoresByStep
const AppliedProcessingSteps::nth_index< 1 >::type & getStepsAndScoresByStep() const
Return the applied processing steps (incl. scores) as a set ordered by processing step reference (opt...
Definition: ScoredProcessingResult.h:56
OpenMS::IdentificationDataInternal::ScoredProcessingResult::addProcessingStep
void addProcessingStep(const AppliedProcessingStep &step)
Definition: ScoredProcessingResult.h:66
OpenMS::IdentificationDataInternal::IteratorWrapper
Wrapper that adds operator< to iterators, so they can be used as (part of) keys in maps/sets or multi...
Definition: MetaData.h:43
OpenMS::IdentificationDataInternal::AppliedProcessingStep::scores
std::map< ScoreTypeRef, double > scores
Definition: AppliedProcessingStep.h:56
OpenMS::IdentificationDataInternal::ScoredProcessingResult::addScore
void addScore(ScoreTypeRef score_type, double score, const boost::optional< ProcessingStepRef > &processing_step_opt=boost::none)
Add a score (possibly connected to a processing step)
Definition: ScoredProcessingResult.h:97
OpenMS::IdentificationDataInternal::AppliedProcessingSteps
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
OpenMS::IdentificationDataInternal::ScoredProcessingResult
Base class for ID data with scores and processing steps (and meta info)
Definition: ScoredProcessingResult.h:44
OpenMS::IdentificationDataInternal::ScoredProcessingResult::addProcessingStep
void addProcessingStep(ProcessingStepRef step_ref, const std::map< ScoreTypeRef, double > &scores=std::map< ScoreTypeRef, double >())
Add a processing step (and associated scores, if any)
Definition: ScoredProcessingResult.h:88
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::IdentificationDataInternal::ScoredProcessingResult::getScore
std::pair< double, bool > getScore(ScoreTypeRef score_ref) const
Definition: ScoredProcessingResult.h:132
OpenMS::IdentificationDataInternal::ScoredProcessingResult::steps_and_scores
AppliedProcessingSteps steps_and_scores
Definition: ScoredProcessingResult.h:46
OpenMS::IdentificationDataInternal::AppliedProcessingStep::processing_step_opt
boost::optional< ProcessingStepRef > processing_step_opt
Definition: AppliedProcessingStep.h:55
OpenMS::IdentificationDataInternal::ScoredProcessingResult::ScoredProcessingResult
ScoredProcessingResult(const AppliedProcessingSteps &steps_and_scores=AppliedProcessingSteps())
Definition: ScoredProcessingResult.h:186
OpenMS::UInt
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
seqan::find
bool find(TFinder &finder, const Pattern< TNeedle, FuzzyAC > &me, PatternAuxData< TNeedle > &dh)
Definition: AhoCorasickAmbiguous.h:884
OpenMS::IdentificationDataInternal::ScoredProcessingResult::operator+=
ScoredProcessingResult & operator+=(const ScoredProcessingResult &other)
Merge in data from another object.
Definition: ScoredProcessingResult.h:107
OpenMS::MetaInfoInterface::setMetaValue
void setMetaValue(const String &name, const DataValue &value)
Sets the DataValue corresponding to a name.
OpenMS::IdentificationDataInternal::AppliedProcessingStep
A processing step that was applied to a data item, possibly with associated scores.
Definition: AppliedProcessingStep.h:52
OpenMS::IdentificationDataInternal::ScoredProcessingResult::getScore
std::pair< double, bool > getScore(ScoreTypeRef score_ref, boost::optional< ProcessingStepRef > processing_step_opt) const
Definition: ScoredProcessingResult.h:144
OpenMS::MetaInfoInterface
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition: MetaInfoInterface.h:60
OpenMS::IdentificationDataInternal::ScoredProcessingResult::getStepsAndScoresByStep
AppliedProcessingSteps::nth_index< 1 >::type & getStepsAndScoresByStep()
Return the applied processing steps (incl. scores) as a set ordered by processing step reference (opt...
Definition: ScoredProcessingResult.h:49