OpenMS
PeptideHit.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: Timo Sachsenberg $
32 // $Authors: $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 #include <iosfwd>
38 #include <vector>
39 
40 #include <OpenMS/CONCEPT/Types.h>
45 
46 namespace OpenMS
47 {
55  class OPENMS_DLLAPI PeptideHit :
56  public MetaInfoInterface
57  {
58 public:
59 
84  {
85  String annotation = ""; // e.g. [alpha|ci$y3-H2O-NH3]
86  int charge = 0;
87  double mz = -1.;
88  double intensity = 0.;
89 
90  bool operator<(const PeptideHit::PeakAnnotation& other) const
91  {
92  // sensible to sort first by m/z and charge
93  return std::tie(mz, charge, annotation, intensity) < std::tie(other.mz, other.charge, other.annotation, other.intensity);
94  }
95 
96  bool operator==(const PeptideHit::PeakAnnotation& other) const
97  {
98  if (charge != other.charge || mz != other.mz ||
99  intensity != other.intensity || annotation != other.annotation) return false;
100  return true;
101  }
102 
103  static void writePeakAnnotationsString_(String& annotation_string, std::vector<PeptideHit::PeakAnnotation> annotations)
104  {
105  if (annotations.empty()) { return; }
106 
107  // sort by mz, charge, ...
108  stable_sort(annotations.begin(), annotations.end());
109 
110  String val;
111  for (auto& a : annotations)
112  {
113  annotation_string += String(a.mz) + "," + String(a.intensity) + "," + String(a.charge) + "," + String(a.annotation).quote();
114  if (&a != &annotations.back()) { annotation_string += "|"; }
115  }
116  }
117 
118  };
119 
120 public:
121 
123 
124  class OPENMS_DLLAPI ScoreMore
126  {
127 public:
128  template <typename Arg>
129  bool operator()(const Arg& a, const Arg& b)
130  {
131  return a.getScore() > b.getScore();
132  }
133 
134  };
135 
137  class OPENMS_DLLAPI ScoreLess
138  {
139 public:
140  template <typename Arg>
141  bool operator()(const Arg& a, const Arg& b)
142  {
143  return a.getScore() < b.getScore();
144  }
145 
146  };
147 
149  class OPENMS_DLLAPI RankLess
150  {
151 public:
152  template <typename Arg>
153  bool operator()(const Arg& a, const Arg& b)
154  {
155  return a.getRank() < b.getRank();
156  }
157 
158  };
160 
161 
163  class OPENMS_DLLAPI SequenceLessComparator
164  {
165  template <typename Arg>
166  bool operator()(const Arg& a, const Arg& b)
167  {
168  if (a.getSequence().toString() < b.getSequence().toString()) return true;
169  return false;
170  }
171  };
173 
175  class OPENMS_DLLAPI PepXMLAnalysisResult
176  {
177 public:
180  double main_score;
181  std::map<String, double> sub_scores;
182 
183  bool operator==(const PepXMLAnalysisResult& rhs) const
184  {
185  return score_type == rhs.score_type
186  && higher_is_better == rhs.higher_is_better
187  && main_score == rhs.main_score
188  && sub_scores == rhs.sub_scores;
189  }
190  };
191 
198  PeptideHit(double score,
199  UInt rank,
200  Int charge,
201  const AASequence& sequence);
203  PeptideHit(double score,
204  UInt rank,
205  Int charge,
206  AASequence&& sequence);
208  PeptideHit(const PeptideHit& source);
210  PeptideHit(PeptideHit&&) noexcept;
212  virtual ~PeptideHit();
213 
215  PeptideHit& operator=(const PeptideHit& source);
217  PeptideHit& operator=(PeptideHit&&) noexcept;
219 
221  bool operator==(const PeptideHit& rhs) const;
222 
224  bool operator!=(const PeptideHit& rhs) const;
225 
230  const AASequence& getSequence() const;
231 
233  AASequence& getSequence();
234 
236  void setSequence(const AASequence& sequence);
237 
239  void setSequence(AASequence&& sequence);
240 
242  Int getCharge() const;
243 
245  void setCharge(Int charge);
246 
248  const std::vector<PeptideEvidence>& getPeptideEvidences() const;
249 
251  void setPeptideEvidences(const std::vector<PeptideEvidence>& peptide_evidences);
252 
253  void setPeptideEvidences(std::vector<PeptideEvidence>&& peptide_evidences);
254 
256  void addPeptideEvidence(const PeptideEvidence& peptide_evidence);
257 
259  double getScore() const;
260 
262  void setScore(double score);
263 
265  void setAnalysisResults(std::vector<PepXMLAnalysisResult> aresult);
266 
268  void addAnalysisResults(const PepXMLAnalysisResult& aresult);
269 
271  const std::vector<PepXMLAnalysisResult>& getAnalysisResults() const;
272 
274  UInt getRank() const;
275 
277  void setRank(UInt newrank);
278 
280  std::vector<PeptideHit::PeakAnnotation>& getPeakAnnotations();
281  const std::vector<PeptideHit::PeakAnnotation>& getPeakAnnotations() const;
282 
283 
285  void setPeakAnnotations(std::vector<PeptideHit::PeakAnnotation> frag_annotations);
286 
288 
290  std::set<String> extractProteinAccessionsSet() const;
291 
292 protected:
293  AASequence sequence_;
294 
296  double score_;
297 
299  std::vector<PepXMLAnalysisResult>* analysis_results_;
300 
302  UInt rank_;
303 
305  Int charge_;
306 
308  std::vector<PeptideEvidence> peptide_evidences_;
309 
311  std::vector<PeptideHit::PeakAnnotation> fragment_annotations_;
312  };
313 
315  OPENMS_DLLAPI std::ostream& operator<< (std::ostream& stream, const PeptideHit& hit);
316 } // namespace OpenMS
Representation of a peptide/protein sequence.
Definition: AASequence.h:112
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition: MetaInfoInterface.h:61
Representation of a peptide evidence.
Definition: PeptideEvidence.h:51
Analysis Result (containing search engine / prophet results)
Definition: PeptideHit.h:176
bool operator==(const PepXMLAnalysisResult &rhs) const
additional scores attached to the original, aggregated score
Definition: PeptideHit.h:183
String score_type
Definition: PeptideHit.h:178
bool higher_is_better
e.g. peptideprophet / interprophet
Definition: PeptideHit.h:179
std::map< String, double > sub_scores
posterior probability for example
Definition: PeptideHit.h:181
double main_score
is higher score better ?
Definition: PeptideHit.h:180
Lesser predicate for scores of hits.
Definition: PeptideHit.h:150
bool operator()(const Arg &a, const Arg &b)
Definition: PeptideHit.h:153
Lesser predicate for scores of hits.
Definition: PeptideHit.h:138
bool operator()(const Arg &a, const Arg &b)
Definition: PeptideHit.h:141
bool operator()(const Arg &a, const Arg &b)
Definition: PeptideHit.h:129
Lesser predicate for (modified) sequence of hits.
Definition: PeptideHit.h:164
bool operator()(const Arg &a, const Arg &b)
Definition: PeptideHit.h:166
Representation of a peptide hit.
Definition: PeptideHit.h:57
PeptideHit(PeptideHit &&) noexcept
Move constructor.
PeptideHit(double score, UInt rank, Int charge, const AASequence &sequence)
Values constructor that copies sequence.
PeptideHit()
Default constructor.
PeptideHit(const PeptideHit &source)
Copy constructor.
PeptideHit(double score, UInt rank, Int charge, AASequence &&sequence)
Values constructor that moves sequence R-value.
A more convenient string class.
Definition: String.h:60
String & quote(char q='"', QuotingMethod method = ESCAPE)
Wraps the string in quotation marks.
int Int
Signed integer type.
Definition: Types.h:102
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48
Contains annotations of a peak.
Definition: PeptideHit.h:84
double intensity
Definition: PeptideHit.h:88
bool operator==(const PeptideHit::PeakAnnotation &other) const
Definition: PeptideHit.h:96
double mz
Definition: PeptideHit.h:87
String annotation
Definition: PeptideHit.h:85
int charge
Definition: PeptideHit.h:86
bool operator<(const PeptideHit::PeakAnnotation &other) const
Definition: PeptideHit.h:90
static void writePeakAnnotationsString_(String &annotation_string, std::vector< PeptideHit::PeakAnnotation > annotations)
Definition: PeptideHit.h:103