OpenMS
PeptideHit.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: Timo Sachsenberg $
6 // $Authors: $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
11 #include <iosfwd>
12 #include <vector>
13 
14 #include <OpenMS/CONCEPT/Types.h>
19 
20 namespace OpenMS
21 {
29  class OPENMS_DLLAPI PeptideHit :
30  public MetaInfoInterface
31  {
32 public:
33 
58  {
59  String annotation = ""; // e.g. [alpha|ci$y3-H2O-NH3]
60  int charge = 0;
61  double mz = -1.;
62  double intensity = 0.;
63 
64  bool operator<(const PeptideHit::PeakAnnotation& other) const
65  {
66  // sensible to sort first by m/z and charge
67  return std::tie(mz, charge, annotation, intensity) < std::tie(other.mz, other.charge, other.annotation, other.intensity);
68  }
69 
70  bool operator==(const PeptideHit::PeakAnnotation& other) const
71  {
72  if (charge != other.charge || mz != other.mz ||
73  intensity != other.intensity || annotation != other.annotation) return false;
74  return true;
75  }
76 
77  static void writePeakAnnotationsString_(String& annotation_string, std::vector<PeptideHit::PeakAnnotation> annotations)
78  {
79  if (annotations.empty()) { return; }
80 
81  // sort by mz, charge, ...
82  stable_sort(annotations.begin(), annotations.end());
83 
84  String val;
85  for (auto& a : annotations)
86  {
87  annotation_string += String(a.mz) + "," + String(a.intensity) + "," + String(a.charge) + "," + String(a.annotation).quote();
88  if (&a != &annotations.back()) { annotation_string += "|"; }
89  }
90  }
91 
92  };
93 
94 public:
95 
97 
98  class OPENMS_DLLAPI ScoreMore
100  {
101 public:
102  template <typename Arg>
103  bool operator()(const Arg& a, const Arg& b)
104  {
105  return a.getScore() > b.getScore();
106  }
107 
108  };
109 
111  class OPENMS_DLLAPI ScoreLess
112  {
113 public:
114  template <typename Arg>
115  bool operator()(const Arg& a, const Arg& b)
116  {
117  return a.getScore() < b.getScore();
118  }
119 
120  };
121 
123  class OPENMS_DLLAPI RankLess
124  {
125 public:
126  template <typename Arg>
127  bool operator()(const Arg& a, const Arg& b)
128  {
129  return a.getRank() < b.getRank();
130  }
131 
132  };
134 
135 
137  class OPENMS_DLLAPI SequenceLessComparator
138  {
139  template <typename Arg>
140  bool operator()(const Arg& a, const Arg& b)
141  {
142  if (a.getSequence().toString() < b.getSequence().toString()) return true;
143  return false;
144  }
145  };
147 
149  class OPENMS_DLLAPI PepXMLAnalysisResult
150  {
151 public:
153  bool higher_is_better{};
154  double main_score{};
155  std::map<String, double> sub_scores;
156 
157  bool operator==(const PepXMLAnalysisResult& rhs) const
158  {
159  return score_type == rhs.score_type
160  && higher_is_better == rhs.higher_is_better
161  && main_score == rhs.main_score
162  && sub_scores == rhs.sub_scores;
163  }
164  };
165 
172  PeptideHit(double score,
173  UInt rank,
174  Int charge,
175  const AASequence& sequence);
177  PeptideHit(double score,
178  UInt rank,
179  Int charge,
180  AASequence&& sequence);
182  PeptideHit(const PeptideHit& source);
184  PeptideHit(PeptideHit&&) noexcept;
186  virtual ~PeptideHit();
187 
189  PeptideHit& operator=(const PeptideHit& source);
191  PeptideHit& operator=(PeptideHit&&) noexcept;
193 
195  bool operator==(const PeptideHit& rhs) const;
196 
198  bool operator!=(const PeptideHit& rhs) const;
199 
204  const AASequence& getSequence() const;
205 
207  AASequence& getSequence();
208 
210  void setSequence(const AASequence& sequence);
211 
213  void setSequence(AASequence&& sequence);
214 
216  Int getCharge() const;
217 
219  void setCharge(Int charge);
220 
222  const std::vector<PeptideEvidence>& getPeptideEvidences() const;
223 
225  void setPeptideEvidences(const std::vector<PeptideEvidence>& peptide_evidences);
226 
227  void setPeptideEvidences(std::vector<PeptideEvidence>&& peptide_evidences);
228 
230  void addPeptideEvidence(const PeptideEvidence& peptide_evidence);
231 
233  double getScore() const;
234 
236  void setScore(double score);
237 
239  void setAnalysisResults(std::vector<PepXMLAnalysisResult> aresult);
240 
242  void addAnalysisResults(const PepXMLAnalysisResult& aresult);
243 
245  const std::vector<PepXMLAnalysisResult>& getAnalysisResults() const;
246 
248  UInt getRank() const;
249 
251  void setRank(UInt newrank);
252 
254  std::vector<PeptideHit::PeakAnnotation>& getPeakAnnotations();
255  const std::vector<PeptideHit::PeakAnnotation>& getPeakAnnotations() const;
256 
257 
259  void setPeakAnnotations(std::vector<PeptideHit::PeakAnnotation> frag_annotations);
260 
262 
264  std::set<String> extractProteinAccessionsSet() const;
265 
266 protected:
267  AASequence sequence_;
268 
270  double score_{};
271 
273  std::vector<PepXMLAnalysisResult>* analysis_results_;
274 
276  UInt rank_{};
277 
279  Int charge_{};
280 
282  std::vector<PeptideEvidence> peptide_evidences_;
283 
285  std::vector<PeptideHit::PeakAnnotation> fragment_annotations_;
286  };
287 
289  OPENMS_DLLAPI std::ostream& operator<< (std::ostream& stream, const PeptideHit& hit);
290 } // namespace OpenMS
Representation of a peptide/protein sequence.
Definition: AASequence.h:86
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition: MetaInfoInterface.h:35
Representation of a peptide evidence.
Definition: PeptideEvidence.h:25
Analysis Result (containing search engine / prophet results)
Definition: PeptideHit.h:150
bool operator==(const PepXMLAnalysisResult &rhs) const
additional scores attached to the original, aggregated score
Definition: PeptideHit.h:157
String score_type
Definition: PeptideHit.h:152
bool higher_is_better
e.g. peptideprophet / interprophet
Definition: PeptideHit.h:153
std::map< String, double > sub_scores
posterior probability for example
Definition: PeptideHit.h:155
double main_score
is higher score better ?
Definition: PeptideHit.h:154
Lesser predicate for scores of hits.
Definition: PeptideHit.h:124
bool operator()(const Arg &a, const Arg &b)
Definition: PeptideHit.h:127
Lesser predicate for scores of hits.
Definition: PeptideHit.h:112
bool operator()(const Arg &a, const Arg &b)
Definition: PeptideHit.h:115
bool operator()(const Arg &a, const Arg &b)
Definition: PeptideHit.h:103
Lesser predicate for (modified) sequence of hits.
Definition: PeptideHit.h:138
bool operator()(const Arg &a, const Arg &b)
Definition: PeptideHit.h:140
Representation of a peptide hit.
Definition: PeptideHit.h:31
PeptideHit(PeptideHit &&) noexcept
Move constructor.
PeptideHit(double score, UInt rank, Int charge, const AASequence &sequence)
Values constructor that copies sequence.
PeptideHit()
Default constructor.
std::vector< PeptideEvidence > peptide_evidences_
information on the potential peptides observed through this PSM.
Definition: PeptideHit.h:282
PeptideHit(const PeptideHit &source)
Copy constructor.
std::vector< PeptideHit::PeakAnnotation > fragment_annotations_
annotations of fragments in the corresponding spectrum
Definition: PeptideHit.h:285
std::vector< PepXMLAnalysisResult > * analysis_results_
additional scores attached to the original, aggregated score
Definition: PeptideHit.h:273
PeptideHit(double score, UInt rank, Int charge, AASequence &&sequence)
Values constructor that moves sequence R-value.
A more convenient string class.
Definition: String.h:34
String & quote(char q='"', QuotingMethod method = ESCAPE)
Wraps the string in quotation marks.
int Int
Signed integer type.
Definition: Types.h:76
unsigned int UInt
Unsigned integer type.
Definition: Types.h:68
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
Contains annotations of a peak.
Definition: PeptideHit.h:58
double intensity
Definition: PeptideHit.h:62
bool operator==(const PeptideHit::PeakAnnotation &other) const
Definition: PeptideHit.h:70
double mz
Definition: PeptideHit.h:61
String annotation
Definition: PeptideHit.h:59
int charge
Definition: PeptideHit.h:60
bool operator<(const PeptideHit::PeakAnnotation &other) const
Definition: PeptideHit.h:64
static void writePeakAnnotationsString_(String &annotation_string, std::vector< PeptideHit::PeakAnnotation > annotations)
Definition: PeptideHit.h:77