OpenMS
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-2023.
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 
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 }
Definition: AdductInfo.h:43
const EmpiricalFormula & getEmpiricalFormula() const
sum formula of adduct itself. Useful for comparison with feature adduct annotation
int getCharge() const
get charge of adduct
Invalid value exception.
Definition: Exception.h:329
A more convenient string class.
Definition: String.h:60
int Int
Signed integer type.
Definition: Types.h:102
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
std::optional< AdductRef > AdductOpt
Definition: ObservationMatch.h:70
IteratorWrapper< Adducts::iterator > AdductRef
Definition: ObservationMatch.h:69
IteratorWrapper< Observations::iterator > ObservationRef
Definition: Observation.h:96
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
IteratorWrapper< ObservationMatches::iterator > ObservationMatchRef
Definition: ObservationMatch.h:152
std::vector< PeptideHit::PeakAnnotation > PeakAnnotations
Definition: ObservationMatch.h:52
std::map< std::optional< ProcessingStepRef >, PeakAnnotations > PeakAnnotationSteps
Definition: ObservationMatch.h:54
std::set< AdductInfo, AdductCompare > Adducts
Definition: ObservationMatch.h:68
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48
Comparator for adducts.
Definition: ObservationMatch.h:60
bool operator()(const AdductInfo &left, const AdductInfo &right) const
Definition: ObservationMatch.h:61
Variant type holding Peptide/Compound/Oligo references and convenience functions.
Definition: IdentifiedMolecule.h:55
Wrapper that adds operator< to iterators, so they can be used as (part of) keys in maps/sets or multi...
Definition: MetaData.h:46
Representation of a search hit (e.g. peptide-spectrum match).
Definition: ObservationMatch.h:74
ObservationMatch(const ObservationMatch &)=default
AdductOpt adduct_opt
optional reference to adduct
Definition: ObservationMatch.h:81
IdentifiedMolecule identified_molecule_var
Definition: ObservationMatch.h:75
Int charge
Definition: ObservationMatch.h:79
PeakAnnotationSteps peak_annotations
Definition: ObservationMatch.h:85
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
ObservationMatch & merge(const ObservationMatch &other)
Definition: ObservationMatch.h:102
ObservationRef observation_ref
Definition: ObservationMatch.h:77
Base class for ID data with scores and processing steps (and meta info)
Definition: ScoredProcessingResult.h:45
AppliedProcessingSteps steps_and_scores
Definition: ScoredProcessingResult.h:46
ScoredProcessingResult & merge(const ScoredProcessingResult &other)
Merge in data from another object.
Definition: ScoredProcessingResult.h:107