OpenMS  2.6.0
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-2020.
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  if (mz < other.mz)
94  {
95  return true;
96  }
97  else if (mz > other.mz)
98  {
99  return false;
100  }
101 
102  if (charge < other.charge)
103  {
104  return true;
105  }
106  else if (charge > other.charge)
107  {
108  return false;
109  }
110 
111  if (annotation < other.annotation)
112  {
113  return true;
114  }
115  else if (annotation > other.annotation)
116  {
117  return false;
118  }
119 
120  if (intensity < other.intensity)
121  {
122  return true;
123  }
124  else if (intensity > other.intensity)
125  {
126  return false;
127  }
128 
129  return false;
130  }
131 
132  bool operator==(const PeptideHit::PeakAnnotation& other) const
133  {
134  if (charge != other.charge || mz != other.mz ||
135  intensity != other.intensity || annotation != other.annotation) return false;
136  return true;
137  }
138 
139  static void writePeakAnnotationsString_(String& annotation_string, std::vector<PeptideHit::PeakAnnotation> annotations)
140  {
141  if (annotations.empty()) { return; }
142 
143  // sort by mz, charge, ...
144  stable_sort(annotations.begin(), annotations.end());
145 
146  String val;
147  for (auto& a : annotations)
148  {
149  annotation_string += String(a.mz) + "," + String(a.intensity) + "," + String(a.charge) + "," + String(a.annotation).quote();
150  if (&a != &annotations.back()) { annotation_string += "|"; }
151  }
152  }
153 
154  };
155 
156 public:
157 
159 
160  class OPENMS_DLLAPI ScoreMore
162  {
163 public:
164  template <typename Arg>
165  bool operator()(const Arg& a, const Arg& b)
166  {
167  return a.getScore() > b.getScore();
168  }
169 
170  };
171 
173  class OPENMS_DLLAPI ScoreLess
174  {
175 public:
176  template <typename Arg>
177  bool operator()(const Arg& a, const Arg& b)
178  {
179  return a.getScore() < b.getScore();
180  }
181 
182  };
183 
185  class OPENMS_DLLAPI RankLess
186  {
187 public:
188  template <typename Arg>
189  bool operator()(const Arg& a, const Arg& b)
190  {
191  return a.getRank() < b.getRank();
192  }
193 
194  };
196 
197 
199  class OPENMS_DLLAPI SequenceLessComparator
200  {
201  template <typename Arg>
202  bool operator()(const Arg& a, const Arg& b)
203  {
204  if (a.getSequence().toString() < b.getSequence().toString()) return true;
205  return false;
206  }
207  };
209 
211  class OPENMS_DLLAPI PepXMLAnalysisResult
212  {
213 public:
214  String score_type; // e.g. peptideprophet / interprophet
215  bool higher_is_better; // is higher score better ?
216  double main_score; // posterior probability for example
217  std::map<String, double> sub_scores;
218 
219  bool operator==(const PepXMLAnalysisResult& rhs) const
220  {
221  return score_type == rhs.score_type
222  && higher_is_better == rhs.higher_is_better
223  && main_score == rhs.main_score
224  && sub_scores == rhs.sub_scores;
225  }
226  };
227 
231  PeptideHit();
234  PeptideHit(double score,
235  UInt rank,
236  Int charge,
237  const AASequence& sequence);
239  PeptideHit(double score,
240  UInt rank,
241  Int charge,
242  AASequence&& sequence);
244  PeptideHit(const PeptideHit& source);
246  PeptideHit(PeptideHit&&) noexcept;
248  virtual ~PeptideHit();
249 
251  PeptideHit& operator=(const PeptideHit& source);
253  PeptideHit& operator=(PeptideHit&&) noexcept;
255 
257  bool operator==(const PeptideHit& rhs) const;
258 
260  bool operator!=(const PeptideHit& rhs) const;
261 
265  const AASequence& getSequence() const;
267 
269  void setSequence(const AASequence& sequence);
270 
272  void setSequence(AASequence&& sequence);
273 
275  Int getCharge() const;
276 
278  void setCharge(Int charge);
279 
281  const std::vector<PeptideEvidence>& getPeptideEvidences() const;
282 
284  void setPeptideEvidences(const std::vector<PeptideEvidence>& peptide_evidences);
285 
286  void setPeptideEvidences(std::vector<PeptideEvidence>&& peptide_evidences);
287 
289  void addPeptideEvidence(const PeptideEvidence& peptide_evidence);
290 
292  double getScore() const;
293 
295  void setScore(double score);
296 
298  void setAnalysisResults(std::vector<PepXMLAnalysisResult> aresult);
299 
301  void addAnalysisResults(PepXMLAnalysisResult aresult);
302 
304  const std::vector<PepXMLAnalysisResult>& getAnalysisResults() const;
305 
307  UInt getRank() const;
308 
310  void setRank(UInt newrank);
311 
313  std::vector<PeptideHit::PeakAnnotation> getPeakAnnotations() const;
314 
316  void setPeakAnnotations(std::vector<PeptideHit::PeakAnnotation> frag_annotations);
317 
319 
321  std::set<String> extractProteinAccessionsSet() const;
322 
323 protected:
324  AASequence sequence_;
325 
327  double score_;
328 
330  std::vector<PepXMLAnalysisResult>* analysis_results_;
331 
333  UInt rank_;
334 
336  Int charge_;
337 
339  std::vector<PeptideEvidence> peptide_evidences_;
340 
342  std::vector<PeptideHit::PeakAnnotation> fragment_annotations_;
343  };
344 
346  OPENMS_DLLAPI std::ostream& operator<< (std::ostream& stream, const PeptideHit& hit);
347 } // namespace OpenMS
OpenMS::PeptideHit::ScoreMore::operator()
bool operator()(const Arg &a, const Arg &b)
Definition: PeptideHit.h:165
OpenMS::PeptideHit::SequenceLessComparator
Lesser predicate for (modified) sequence of hits.
Definition: PeptideHit.h:199
Types.h
OpenMS::PeptideHit::PeakAnnotation::writePeakAnnotationsString_
static void writePeakAnnotationsString_(String &annotation_string, std::vector< PeptideHit::PeakAnnotation > annotations)
Definition: PeptideHit.h:139
OpenMS::PeptideHit::PepXMLAnalysisResult::score_type
String score_type
Definition: PeptideHit.h:214
OpenMS::PeptideHit::PepXMLAnalysisResult
Analysis Result (containing search engine / prophet results)
Definition: PeptideHit.h:211
OpenMS::String
A more convenient string class.
Definition: String.h:59
PeptideEvidence.h
OpenMS::PeptideHit::PeakAnnotation::operator==
bool operator==(const PeptideHit::PeakAnnotation &other) const
Definition: PeptideHit.h:132
OpenMS::PeptideHit::PeakAnnotation::operator<
bool operator<(const PeptideHit::PeakAnnotation &other) const
Definition: PeptideHit.h:90
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::PeptideHit::PeakAnnotation::charge
int charge
Definition: PeptideHit.h:86
OpenMS::PeptideHit::RankLess::operator()
bool operator()(const Arg &a, const Arg &b)
Definition: PeptideHit.h:189
OpenMS::PeptideHit::PeakAnnotation::annotation
String annotation
Definition: PeptideHit.h:85
OpenMS::MetaInfoInterface
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition: MetaInfoInterface.h:60
int
OpenMS::PeptideHit::PepXMLAnalysisResult::operator==
bool operator==(const PepXMLAnalysisResult &rhs) const
additional scores attached to the original, aggregated score
Definition: PeptideHit.h:219
OpenMS::PeptideEvidence
Representation of a peptide evidence.
Definition: PeptideEvidence.h:50
OpenMS::PeptideHit::RankLess
Lesser predicate for scores of hits.
Definition: PeptideHit.h:185
OpenMS::PeptideHit::SequenceLessComparator::operator()
bool operator()(const Arg &a, const Arg &b)
Definition: PeptideHit.h:202
OpenMS::PeptideHit::PeakAnnotation::mz
double mz
Definition: PeptideHit.h:87
OpenMS::PeptideHit::PepXMLAnalysisResult::higher_is_better
bool higher_is_better
Definition: PeptideHit.h:215
OpenMS::PeptideHit::PeakAnnotation::intensity
double intensity
Definition: PeptideHit.h:88
OpenMS::PeptideHit::ScoreLess
Lesser predicate for scores of hits.
Definition: PeptideHit.h:173
OpenMS::UInt
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
OpenMS::String::quote
String & quote(char q='"', QuotingMethod method = ESCAPE)
Wraps the string in quotation marks.
OpenMS::PeptideHit::PepXMLAnalysisResult::main_score
double main_score
Definition: PeptideHit.h:216
AASequence.h
MetaInfoInterface.h
String.h
OpenMS::AASequence
Representation of a peptide/protein sequence.
Definition: AASequence.h:111
OpenMS::PeptideHit::PeakAnnotation
Contains annotations of a peak.
Definition: PeptideHit.h:83
OpenMS::PeptideHit::PepXMLAnalysisResult::sub_scores
std::map< String, double > sub_scores
Definition: PeptideHit.h:217
OpenMS::PeptideHit::ScoreLess::operator()
bool operator()(const Arg &a, const Arg &b)
Definition: PeptideHit.h:177
OpenMS::PeptideHit
Representation of a peptide hit.
Definition: PeptideHit.h:55