OpenMS  3.0.0
ObservationMatch.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-2022.
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 
40 #include <OpenMS/METADATA/PeptideHit.h> // for "PeakAnnotation"
42 
43 #include <boost/multi_index_container.hpp>
44 #include <boost/multi_index/ordered_index.hpp>
45 #include <boost/multi_index/composite_key.hpp>
46 
47 namespace OpenMS
48 {
49  namespace IdentificationDataInternal
50  {
51  // @TODO: move "PeakAnnotation" out of "PeptideHit"
52  typedef std::vector<PeptideHit::PeakAnnotation> PeakAnnotations;
53  typedef std::map<std::optional<ProcessingStepRef>,
55 
57  // @TODO: this allows adducts with duplicate names, but requires different
58  // sum formulas/charges - is this what we want?
60  {
61  bool operator()(const AdductInfo& left, const AdductInfo& right) const
62  {
63  return (std::make_pair(left.getCharge(), left.getEmpiricalFormula()) <
64  std::make_pair(right.getCharge(), right.getEmpiricalFormula()));
65  }
66  };
67 
68  typedef std::set<AdductInfo, AdductCompare> Adducts;
70  typedef std::optional<AdductRef> AdductOpt;
71 
74  {
76 
78 
80 
82 
83  // peak annotations (fragment ion matches), potentially from different
84  // data processing steps:
86 
87  explicit ObservationMatch(
90  const std::optional<AdductRef>& adduct_opt = std::nullopt,
97  {
98  }
99 
100  ObservationMatch(const ObservationMatch&) = default;
101 
103  {
105  if (charge == 0)
106  {
107  charge = other.charge;
108  }
109  else if (charge != other.charge)
110  {
111  throw Exception::InvalidValue(__FILE__, __LINE__,
112  OPENMS_PRETTY_FUNCTION,
113  "Trying to overwrite ObservationMatch charge with conflicting value.",
114  String(charge));
115  }
116 
117  if (!adduct_opt)
118  {
119  adduct_opt = other.adduct_opt;
120  }
121  else if (adduct_opt != other.adduct_opt)
122  {
123  throw Exception::InvalidValue(__FILE__, __LINE__,
124  OPENMS_PRETTY_FUNCTION,
125  "Trying to overwrite ObservationMatch adduct_opt with conflicting value.",
126  (*adduct_opt)->getName());
127  }
128 
129  peak_annotations.insert(other.peak_annotations.begin(),
130  other.peak_annotations.end());
131  return *this;
132  }
133  };
134 
135  // all matches for the same observation should be consecutive, so make sure
136  // the observation is used as the first member in the composite key:
137  typedef boost::multi_index_container<
138  ObservationMatch,
139  boost::multi_index::indexed_by<
140  boost::multi_index::ordered_unique<
141  boost::multi_index::composite_key<
142  ObservationMatch,
143  boost::multi_index::member<ObservationMatch, ObservationRef,
145  boost::multi_index::member<
146  ObservationMatch, IdentifiedMolecule,
148  boost::multi_index::member<ObservationMatch, AdductOpt,
151 
153  }
154 }
OpenMS::AdductInfo::getEmpiricalFormula
const EmpiricalFormula & getEmpiricalFormula() const
sum formula of adduct itself. Useful for comparison with feature adduct annotation
OpenMS::IdentificationDataInternal::ObservationMatch::identified_molecule_var
IdentifiedMolecule identified_molecule_var
Definition: ObservationMatch.h:75
OpenMS::Exception::InvalidValue
Invalid value exception.
Definition: Exception.h:327
MetaData.h
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::IdentificationDataInternal::AdductOpt
std::optional< AdductRef > AdductOpt
Definition: ObservationMatch.h:70
OpenMS::IdentificationDataInternal::IdentifiedMolecule
Variant type holding Peptide/Compound/Oligo references and convenience functions.
Definition: IdentifiedMolecule.h:54
OpenMS::IdentificationDataInternal::ObservationRef
IteratorWrapper< Observations::iterator > ObservationRef
Definition: Observation.h:96
OpenMS::IdentificationDataInternal::ObservationMatch::peak_annotations
PeakAnnotationSteps peak_annotations
Definition: ObservationMatch.h:85
OpenMS::IdentificationDataInternal::ScoredProcessingResult::steps_and_scores
AppliedProcessingSteps steps_and_scores
Definition: ScoredProcessingResult.h:46
OpenMS::IdentificationDataInternal::ObservationMatch::observation_ref
ObservationRef observation_ref
Definition: ObservationMatch.h:77
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, std::optional< ProcessingStepRef >, &AppliedProcessingStep::processing_step_opt > > > > AppliedProcessingSteps
Definition: AppliedProcessingStep.h:133
OpenMS::IdentificationDataInternal::ObservationMatch::charge
Int charge
Definition: ObservationMatch.h:79
AdductInfo.h
OpenMS::IdentificationDataInternal::AdductRef
IteratorWrapper< Adducts::iterator > AdductRef
Definition: ObservationMatch.h:69
OpenMS::Int
int Int
Signed integer type.
Definition: Types.h:102
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
OpenMS::IdentificationDataInternal::PeakAnnotations
std::vector< PeptideHit::PeakAnnotation > PeakAnnotations
Definition: ObservationMatch.h:52
OpenMS::IdentificationDataInternal::ObservationMatchRef
IteratorWrapper< ObservationMatches::iterator > ObservationMatchRef
Definition: ObservationMatch.h:152
PeptideHit.h
OpenMS::IdentificationDataInternal::AdductCompare
Comparator for adducts.
Definition: ObservationMatch.h:59
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:45
OpenMS::AdductInfo
Definition: AdductInfo.h:42
OpenMS::AdductInfo::getCharge
int getCharge() const
get charge of adduct
OpenMS::IdentificationDataInternal::Adducts
std::set< AdductInfo, AdductCompare > Adducts
Definition: ObservationMatch.h:68
OpenMS::IdentificationDataInternal::ObservationMatches
boost::multi_index_container< ObservationMatch, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::composite_key< ObservationMatch, boost::multi_index::member< ObservationMatch, ObservationRef, &ObservationMatch::observation_ref >, boost::multi_index::member< ObservationMatch, IdentifiedMolecule, &ObservationMatch::identified_molecule_var >, boost::multi_index::member< ObservationMatch, AdductOpt, &ObservationMatch::adduct_opt > > > > > ObservationMatches
Definition: ObservationMatch.h:150
OpenMS::IdentificationDataInternal::PeakAnnotationSteps
std::map< std::optional< ProcessingStepRef >, PeakAnnotations > PeakAnnotationSteps
Definition: ObservationMatch.h:54
OpenMS::IdentificationDataInternal::AdductCompare::operator()
bool operator()(const AdductInfo &left, const AdductInfo &right) const
Definition: ObservationMatch.h:61
OpenMS::IdentificationDataInternal::ScoredProcessingResult
Base class for ID data with scores and processing steps (and meta info)
Definition: ScoredProcessingResult.h:44
OpenMS::IdentificationDataInternal::ObservationMatch::ObservationMatch
ObservationMatch(IdentifiedMolecule identified_molecule_var, ObservationRef observation_ref, Int charge=0, const std::optional< AdductRef > &adduct_opt=std::nullopt, const AppliedProcessingSteps &steps_and_scores=AppliedProcessingSteps(), const PeakAnnotationSteps &peak_annotations=PeakAnnotationSteps())
Definition: ObservationMatch.h:87
IdentifiedMolecule.h
OpenMS::IdentificationDataInternal::ObservationMatch::adduct_opt
AdductOpt adduct_opt
optional reference to adduct
Definition: ObservationMatch.h:81
Observation.h
OpenMS::IdentificationDataInternal::ObservationMatch::merge
ObservationMatch & merge(const ObservationMatch &other)
Definition: ObservationMatch.h:102
OpenMS::IdentificationDataInternal::ObservationMatch
Representation of a search hit (e.g. peptide-spectrum match).
Definition: ObservationMatch.h:73
OpenMS::IdentificationDataInternal::ScoredProcessingResult::merge
ScoredProcessingResult & merge(const ScoredProcessingResult &other)
Merge in data from another object.
Definition: ScoredProcessingResult.h:107