OpenMS
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
PeptideHit.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, OpenMS Inc. -- 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 {
22  class PeptideHit;
23  using SpectrumMatch = PeptideHit; // better name that might become the default in future version
24 
47  class OPENMS_DLLAPI PeptideHit :
48  public MetaInfoInterface
49  {
50 public:
51 
76  {
77  String annotation = ""; // e.g. [alpha|ci$y3-H2O-NH3]
78  int charge = 0;
79  double mz = -1.;
80  double intensity = 0.;
81 
82  bool operator<(const PeptideHit::PeakAnnotation& other) const
83  {
84  // sensible to sort first by m/z and charge
85  return std::tie(mz, charge, annotation, intensity) < std::tie(other.mz, other.charge, other.annotation, other.intensity);
86  }
87 
88  bool operator==(const PeptideHit::PeakAnnotation& other) const
89  {
90  if (charge != other.charge || mz != other.mz ||
91  intensity != other.intensity || annotation != other.annotation) return false;
92  return true;
93  }
94 
95  static void writePeakAnnotationsString_(String& annotation_string, std::vector<PeptideHit::PeakAnnotation> annotations)
96  {
97  if (annotations.empty()) { return; }
98 
99  // sort by mz, charge, ...
100  stable_sort(annotations.begin(), annotations.end());
101 
102  String val;
103  for (auto& a : annotations)
104  {
105  annotation_string += String(a.mz) + "," + String(a.intensity) + "," + String(a.charge) + "," + String(a.annotation).quote();
106  if (&a != &annotations.back()) { annotation_string += "|"; }
107  }
108  }
109 
110  };
111 
112 public:
113 
115 
116  class OPENMS_DLLAPI ScoreMore
118  {
119 public:
120  template <typename Arg>
121  bool operator()(const Arg& a, const Arg& b)
122  {
123  return a.getScore() > b.getScore();
124  }
125 
126  };
127 
129  class OPENMS_DLLAPI ScoreLess
130  {
131 public:
132  template <typename Arg>
133  bool operator()(const Arg& a, const Arg& b)
134  {
135  return a.getScore() < b.getScore();
136  }
137 
138  };
139 
141  class OPENMS_DLLAPI RankLess
142  {
143 public:
144  template <typename Arg>
145  bool operator()(const Arg& a, const Arg& b)
146  {
147  return a.getRank() < b.getRank();
148  }
149 
150  };
152 
153 
155  class OPENMS_DLLAPI SequenceLessComparator
156  {
157  template <typename Arg>
158  bool operator()(const Arg& a, const Arg& b)
159  {
160  if (a.getSequence().toString() < b.getSequence().toString()) return true;
161  return false;
162  }
163  };
165 
167  class OPENMS_DLLAPI PepXMLAnalysisResult
168  {
169 public:
171  bool higher_is_better{};
172  double main_score{};
173  std::map<String, double> sub_scores;
174 
175  bool operator==(const PepXMLAnalysisResult& rhs) const
176  {
177  return score_type == rhs.score_type
178  && higher_is_better == rhs.higher_is_better
179  && main_score == rhs.main_score
180  && sub_scores == rhs.sub_scores;
181  }
182  };
183 
190  PeptideHit(double score,
191  UInt rank,
192  Int charge,
193  const AASequence& sequence);
195  PeptideHit(double score,
196  UInt rank,
197  Int charge,
198  AASequence&& sequence);
200  PeptideHit(const PeptideHit& source);
202  PeptideHit(PeptideHit&&) noexcept;
204  virtual ~PeptideHit();
205 
207  PeptideHit& operator=(const PeptideHit& source);
209  PeptideHit& operator=(PeptideHit&&) noexcept;
211 
213  bool operator==(const PeptideHit& rhs) const;
214 
216  bool operator!=(const PeptideHit& rhs) const;
217 
222  const AASequence& getSequence() const;
223 
225  AASequence& getSequence();
226 
228  void setSequence(const AASequence& sequence);
229 
231  void setSequence(AASequence&& sequence);
232 
234  Int getCharge() const;
235 
237  void setCharge(Int charge);
238 
240  const std::vector<PeptideEvidence>& getPeptideEvidences() const;
241 
243  void setPeptideEvidences(const std::vector<PeptideEvidence>& peptide_evidences);
244 
245  void setPeptideEvidences(std::vector<PeptideEvidence>&& peptide_evidences);
246 
248  void addPeptideEvidence(const PeptideEvidence& peptide_evidence);
249 
251  double getScore() const;
252 
254  void setScore(double score);
255 
257  void setAnalysisResults(const std::vector<PepXMLAnalysisResult>& aresult);
258 
260  void addAnalysisResults(const PepXMLAnalysisResult& aresult);
261 
263  std::vector<PepXMLAnalysisResult> getAnalysisResults() const;
264 
266  UInt getRank() const;
267 
269  void setRank(UInt newrank);
270 
272  std::vector<PeptideHit::PeakAnnotation>& getPeakAnnotations();
273  const std::vector<PeptideHit::PeakAnnotation>& getPeakAnnotations() const;
274 
275 
277  void setPeakAnnotations(std::vector<PeptideHit::PeakAnnotation> frag_annotations);
278 
280 
282  std::set<String> extractProteinAccessionsSet() const;
283 
284 protected:
285  AASequence sequence_;
286 
288  double score_{};
289 
291  UInt rank_{};
292 
294  Int charge_{};
295 
297  std::vector<PeptideEvidence> peptide_evidences_;
298 
300  std::vector<PeptideHit::PeakAnnotation> fragment_annotations_;
301 
302 private:
305 
307  std::vector<PepXMLAnalysisResult> extractAnalysisResultsFromMetaValues_() const;
308  };
309 
311  OPENMS_DLLAPI std::ostream& operator<< (std::ostream& stream, const PeptideHit& hit);
312 } // 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:168
bool operator==(const PepXMLAnalysisResult &rhs) const
additional scores attached to the original, aggregated score
Definition: PeptideHit.h:175
String score_type
Definition: PeptideHit.h:170
bool higher_is_better
e.g. peptideprophet / interprophet
Definition: PeptideHit.h:171
std::map< String, double > sub_scores
posterior probability for example
Definition: PeptideHit.h:173
double main_score
is higher score better ?
Definition: PeptideHit.h:172
Lesser predicate for scores of hits.
Definition: PeptideHit.h:142
bool operator()(const Arg &a, const Arg &b)
Definition: PeptideHit.h:145
Lesser predicate for scores of hits.
Definition: PeptideHit.h:130
bool operator()(const Arg &a, const Arg &b)
Definition: PeptideHit.h:133
bool operator()(const Arg &a, const Arg &b)
Definition: PeptideHit.h:121
Lesser predicate for (modified) sequence of hits.
Definition: PeptideHit.h:156
bool operator()(const Arg &a, const Arg &b)
Definition: PeptideHit.h:158
Represents a single spectrum match (candidate) for a specific tandem mass spectrum (MS/MS).
Definition: PeptideHit.h:49
PeptideHit(PeptideHit &&) noexcept
Move constructor.
size_t getNumberOfAnalysisResultsFromMetaValues_() const
Get the number of analysis results stored as meta values (only for pepXML results)
PeptideHit(double score, UInt rank, Int charge, const AASequence &sequence)
Values constructor that copies sequence.
std::vector< PepXMLAnalysisResult > extractAnalysisResultsFromMetaValues_() const
Extract analysis results from meta values (only for pepXML results)
PeptideHit()
Default constructor.
std::vector< PeptideEvidence > peptide_evidences_
information on the potential peptides observed through this PSM.
Definition: PeptideHit.h:297
PeptideHit(const PeptideHit &source)
Copy constructor.
std::vector< PeptideHit::PeakAnnotation > fragment_annotations_
annotations of fragments in the corresponding spectrum
Definition: PeptideHit.h:300
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:72
unsigned int UInt
Unsigned integer type.
Definition: Types.h:64
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
Contains annotations of a peak.
Definition: PeptideHit.h:76
double intensity
Definition: PeptideHit.h:80
bool operator==(const PeptideHit::PeakAnnotation &other) const
Definition: PeptideHit.h:88
double mz
Definition: PeptideHit.h:79
String annotation
Definition: PeptideHit.h:77
int charge
Definition: PeptideHit.h:78
bool operator<(const PeptideHit::PeakAnnotation &other) const
Definition: PeptideHit.h:82
static void writePeakAnnotationsString_(String &annotation_string, std::vector< PeptideHit::PeakAnnotation > annotations)
Definition: PeptideHit.h:95