OpenMS
ParentSequence.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 
38 
39 #include <boost/multi_index_container.hpp>
40 #include <boost/multi_index/ordered_index.hpp>
41 #include <boost/multi_index/member.hpp>
42 
43 namespace OpenMS
44 {
45  namespace IdentificationDataInternal
46  {
50  {
52 
54 
55  // @TODO: if there are modifications in the sequence, "sequence.size()"
56  // etc. will be misleading!
58 
60 
61  double coverage;
62 
63  bool is_decoy;
64 
65  explicit ParentSequence(
66  const String& accession,
68  const String& sequence = "", const String& description = "",
69  double coverage = 0.0, bool is_decoy = false,
74  {
75  }
76 
77  ParentSequence(const ParentSequence&) = default;
78 
80  {
82  if (sequence.empty())
83  {
84  sequence = other.sequence;
85  }
86  else if (!other.sequence.empty() && sequence != other.sequence) // differ and none is empty
87  {
88  throw Exception::InvalidValue(__FILE__, __LINE__,
89  OPENMS_PRETTY_FUNCTION,
90  "Trying to overwrite ParentSequence sequence '" + sequence + "' with conflicting value.",
91  other.sequence);
92  }
93 
94  if (description.empty())
95  {
96  description = other.description;
97  }
98  else if (!other.description.empty() && description != other.description) // differ and none is empty
99  {
100  throw Exception::InvalidValue(__FILE__, __LINE__,
101  OPENMS_PRETTY_FUNCTION,
102  "Trying to overwrite ParentSequence description '" + description + "' with conflicting value.",
103  other.description);
104  }
105 
106  if (!is_decoy) is_decoy = other.is_decoy; // believe it when it's set
107  // @TODO: what about coverage? (not reliable if we're merging data)
108 
109  return *this;
110  }
111  };
112 
113  // parent sequences indexed by their accessions:
114  // @TODO: allow querying/iterating over proteins and RNAs separately
115  typedef boost::multi_index_container<
116  ParentSequence,
117  boost::multi_index::indexed_by<
118  boost::multi_index::ordered_unique<boost::multi_index::member<
119  ParentSequence, String, &ParentSequence::accession>>>
122 
123  }
124 }
Invalid value exception.
Definition: Exception.h:329
A more convenient string class.
Definition: String.h:60
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
MoleculeType
Definition: MetaData.h:66
@ PROTEIN
Definition: MetaData.h:67
boost::multi_index_container< ParentSequence, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::member< ParentSequence, String, &ParentSequence::accession > > > > ParentSequences
Definition: ParentSequence.h:120
IteratorWrapper< ParentSequences::iterator > ParentSequenceRef
Definition: ParentSequence.h:121
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48
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 parent sequence that is identified only indirectly (e.g. a protein).
Definition: ParentSequence.h:50
ParentSequence & merge(const ParentSequence &other)
Definition: ParentSequence.h:79
ParentSequence(const String &accession, MoleculeType molecule_type=MoleculeType::PROTEIN, const String &sequence="", const String &description="", double coverage=0.0, bool is_decoy=false, const AppliedProcessingSteps &steps_and_scores=AppliedProcessingSteps())
Definition: ParentSequence.h:65
bool is_decoy
Definition: ParentSequence.h:63
String sequence
Definition: ParentSequence.h:57
String description
Definition: ParentSequence.h:59
double coverage
sequence coverage as a fraction between 0 and 1
Definition: ParentSequence.h:61
String accession
Definition: ParentSequence.h:51
enum MoleculeType molecule_type
Definition: ParentSequence.h:53
ParentSequence(const ParentSequence &)=default
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