OpenMS
ObservationMatch.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Hendrik Weisser $
6 // $Authors: Hendrik Weisser $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
14 #include <OpenMS/METADATA/PeptideHit.h> // for "PeakAnnotation"
16 
17 #include <boost/multi_index_container.hpp>
18 #include <boost/multi_index/ordered_index.hpp>
19 #include <boost/multi_index/composite_key.hpp>
20 
21 namespace OpenMS
22 {
23  namespace IdentificationDataInternal
24  {
25  // @TODO: move "PeakAnnotation" out of "PeptideHit"
26  typedef std::vector<PeptideHit::PeakAnnotation> PeakAnnotations;
27  typedef std::map<std::optional<ProcessingStepRef>,
29 
31  // @TODO: this allows adducts with duplicate names, but requires different
32  // sum formulas/charges - is this what we want?
34  {
35  bool operator()(const AdductInfo& left, const AdductInfo& right) const
36  {
37  return (std::make_pair(left.getCharge(), left.getEmpiricalFormula()) <
38  std::make_pair(right.getCharge(), right.getEmpiricalFormula()));
39  }
40  };
41 
42  typedef std::set<AdductInfo, AdductCompare> Adducts;
44  typedef std::optional<AdductRef> AdductOpt;
45 
48  {
50 
52 
54 
56 
57  // peak annotations (fragment ion matches), potentially from different
58  // data processing steps:
60 
61  explicit ObservationMatch(
64  const std::optional<AdductRef>& adduct_opt = std::nullopt,
71  {
72  }
73 
75 
77  {
79  if (charge == 0)
80  {
81  charge = other.charge;
82  }
83  else if (charge != other.charge)
84  {
85  throw Exception::InvalidValue(__FILE__, __LINE__,
86  OPENMS_PRETTY_FUNCTION,
87  "Trying to overwrite ObservationMatch charge with conflicting value.",
88  String(charge));
89  }
90 
91  if (!adduct_opt)
92  {
93  adduct_opt = other.adduct_opt;
94  }
95  else if (adduct_opt != other.adduct_opt)
96  {
97  throw Exception::InvalidValue(__FILE__, __LINE__,
98  OPENMS_PRETTY_FUNCTION,
99  "Trying to overwrite ObservationMatch adduct_opt with conflicting value.",
100  (*adduct_opt)->getName());
101  }
102 
103  peak_annotations.insert(other.peak_annotations.begin(),
104  other.peak_annotations.end());
105  return *this;
106  }
107  };
108 
109  // all matches for the same observation should be consecutive, so make sure
110  // the observation is used as the first member in the composite key:
111  typedef boost::multi_index_container<
112  ObservationMatch,
113  boost::multi_index::indexed_by<
114  boost::multi_index::ordered_unique<
115  boost::multi_index::composite_key<
116  ObservationMatch,
117  boost::multi_index::member<ObservationMatch, ObservationRef,
119  boost::multi_index::member<
120  ObservationMatch, IdentifiedMolecule,
122  boost::multi_index::member<ObservationMatch, AdductOpt,
125 
127  }
128 }
Definition: AdductInfo.h:17
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:303
A more convenient string class.
Definition: String.h:34
int Int
Signed integer type.
Definition: Types.h:76
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:124
std::optional< AdductRef > AdductOpt
Definition: ObservationMatch.h:44
IteratorWrapper< Adducts::iterator > AdductRef
Definition: ObservationMatch.h:43
IteratorWrapper< Observations::iterator > ObservationRef
Definition: Observation.h:70
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:107
IteratorWrapper< ObservationMatches::iterator > ObservationMatchRef
Definition: ObservationMatch.h:126
std::vector< PeptideHit::PeakAnnotation > PeakAnnotations
Definition: ObservationMatch.h:26
std::map< std::optional< ProcessingStepRef >, PeakAnnotations > PeakAnnotationSteps
Definition: ObservationMatch.h:28
std::set< AdductInfo, AdductCompare > Adducts
Definition: ObservationMatch.h:42
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22
Comparator for adducts.
Definition: ObservationMatch.h:34
bool operator()(const AdductInfo &left, const AdductInfo &right) const
Definition: ObservationMatch.h:35
Variant type holding Peptide/Compound/Oligo references and convenience functions.
Definition: IdentifiedMolecule.h:29
Wrapper that adds operator< to iterators, so they can be used as (part of) keys in maps/sets or multi...
Definition: MetaData.h:20
Representation of a search hit (e.g. peptide-spectrum match).
Definition: ObservationMatch.h:48
ObservationMatch(const ObservationMatch &)=default
AdductOpt adduct_opt
optional reference to adduct
Definition: ObservationMatch.h:55
IdentifiedMolecule identified_molecule_var
Definition: ObservationMatch.h:49
Int charge
Definition: ObservationMatch.h:53
PeakAnnotationSteps peak_annotations
Definition: ObservationMatch.h:59
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:61
ObservationMatch & merge(const ObservationMatch &other)
Definition: ObservationMatch.h:76
ObservationRef observation_ref
Definition: ObservationMatch.h:51
Base class for ID data with scores and processing steps (and meta info)
Definition: ScoredProcessingResult.h:19
AppliedProcessingSteps steps_and_scores
Definition: ScoredProcessingResult.h:20
ScoredProcessingResult & merge(const ScoredProcessingResult &other)
Merge in data from another object.
Definition: ScoredProcessingResult.h:81