OpenMS  2.4.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-2018.
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 <vector>
38 
39 #include <OpenMS/CONCEPT/Types.h>
44 
45 namespace OpenMS
46 {
54  class OPENMS_DLLAPI PeptideHit :
55  public MetaInfoInterface
56  {
57 public:
58 
83  {
84  String annotation; // e.g. [alpha|ci$y3-H2O-NH3]
85  int charge;
86  double mz;
87  double intensity;
88 
89  bool operator<(const PeptideHit::PeakAnnotation& other) const
90  {
91  // sensible to sort first by m/z and charge
92  if (mz < other.mz)
93  {
94  return true;
95  }
96  else if (mz > other.mz)
97  {
98  return false;
99  }
100 
101  if (charge < other.charge)
102  {
103  return true;
104  }
105  else if (charge > other.charge)
106  {
107  return false;
108  }
109 
110  if (annotation < other.annotation)
111  {
112  return true;
113  }
114  else if (annotation > other.annotation)
115  {
116  return false;
117  }
118 
119  if (intensity < other.intensity)
120  {
121  return true;
122  }
123  else if (intensity > other.intensity)
124  {
125  return false;
126  }
127 
128  return false;
129  }
130 
131  bool operator==(const PeptideHit::PeakAnnotation& other) const
132  {
133  if (charge != other.charge || mz != other.mz ||
134  intensity != other.intensity || annotation != other.annotation) return false;
135  return true;
136  }
137 
138  static void writePeakAnnotationsString_(String& annotation_string, std::vector<PeptideHit::PeakAnnotation> annotations)
139  {
140  if (annotations.empty()) { return; }
141 
142  // sort by mz, charge, ...
143  stable_sort(annotations.begin(), annotations.end());
144 
145  String val;
146  for (auto& a : annotations)
147  {
148  annotation_string += String(a.mz) + "," + String(a.intensity) + "," + String(a.charge) + "," + String(a.annotation).quote();
149  if (&a != &annotations.back()) { annotation_string += "|"; }
150  }
151  }
152 
153  };
154 
155 public:
156 
158 
159  class OPENMS_DLLAPI ScoreMore
161  {
162 public:
163  template <typename Arg>
164  bool operator()(const Arg& a, const Arg& b)
165  {
166  return a.getScore() > b.getScore();
167  }
168 
169  };
170 
172  class OPENMS_DLLAPI ScoreLess
173  {
174 public:
175  template <typename Arg>
176  bool operator()(const Arg& a, const Arg& b)
177  {
178  return a.getScore() < b.getScore();
179  }
180 
181  };
182 
184  class OPENMS_DLLAPI RankLess
185  {
186 public:
187  template <typename Arg>
188  bool operator()(const Arg& a, const Arg& b)
189  {
190  return a.getRank() < b.getRank();
191  }
192 
193  };
195 
196 
198  class OPENMS_DLLAPI SequenceLessComparator
199  {
200  template <typename Arg>
201  bool operator()(const Arg& a, const Arg& b)
202  {
203  if (a.getSequence().toString() < b.getSequence().toString()) return true;
204  return false;
205  }
206  };
208 
210  class OPENMS_DLLAPI PepXMLAnalysisResult
211  {
212 public:
213  String score_type; // e.g. peptideprophet / interprophet
214  bool higher_is_better; // is higher score better ?
215  double main_score; // posterior probability for example
216  std::map<String, double> sub_scores;
217 
218  bool operator==(const PepXMLAnalysisResult& rhs) const
219  {
220  return score_type == rhs.score_type
221  && higher_is_better == rhs.higher_is_better
222  && main_score == rhs.main_score
223  && sub_scores == rhs.sub_scores;
224  }
225 
227  {
228  if (this == &source) return *this;
229  score_type = source.score_type;
230  higher_is_better = source.higher_is_better;
231  main_score = source.main_score;
232  sub_scores = source.sub_scores;
233  return *this;
234  }
235 
236  };
237 
240  PeptideHit();
242 
244  PeptideHit(double score,
245  UInt rank,
246  Int charge,
247  const AASequence& sequence);
248 
250  PeptideHit(const PeptideHit& source);
251 
253  virtual ~PeptideHit();
255 
257  PeptideHit& operator=(const PeptideHit& source);
258 
260  bool operator==(const PeptideHit& rhs) const;
261 
263  bool operator!=(const PeptideHit& rhs) const;
264 
268  const AASequence& getSequence() const;
270 
272  void setSequence(const 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 
287  void addPeptideEvidence(const PeptideEvidence& peptide_evidence);
288 
290  double getScore() const;
291 
293  void setScore(double score);
294 
296  void setAnalysisResults(std::vector<PepXMLAnalysisResult> aresult);
297 
299  void addAnalysisResults(PepXMLAnalysisResult aresult);
300 
302  const std::vector<PepXMLAnalysisResult>& getAnalysisResults() const;
303 
305  UInt getRank() const;
306 
308  void setRank(UInt newrank);
309 
311  std::vector<PeptideHit::PeakAnnotation> getPeakAnnotations() const;
312 
314  void setPeakAnnotations(std::vector<PeptideHit::PeakAnnotation> frag_annotations);
315 
317 
319  std::set<String> extractProteinAccessionsSet() const;
320 
321 protected:
323 
325  double score_;
326 
328  std::vector<PepXMLAnalysisResult>* analysis_results_;
329 
332 
335 
337  std::vector<PeptideEvidence> peptide_evidences_;
338 
340  std::vector<PeptideHit::PeakAnnotation> fragment_annotations_;
341  };
342 
343 } // namespace OpenMS
double main_score
Definition: PeptideHit.h:215
A more convenient string class.
Definition: String.h:57
Lesser predicate for scores of hits.
Definition: PeptideHit.h:184
String & quote(char q='"', QuotingMethod method = ESCAPE)
Wraps the string in quotation marks.
std::vector< PeptideHit::PeakAnnotation > fragment_annotations_
annotations of fragments in the corresponding spectrum
Definition: PeptideHit.h:340
UInt rank_
the position(rank) where the hit appeared in the hit list
Definition: PeptideHit.h:331
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
bool operator<(const PeptideHit::PeakAnnotation &other) const
Definition: PeptideHit.h:89
bool operator==(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:806
static void writePeakAnnotationsString_(String &annotation_string, std::vector< PeptideHit::PeakAnnotation > annotations)
Definition: PeptideHit.h:138
std::map< String, double > sub_scores
Definition: PeptideHit.h:216
Representation of a peptide/protein sequence.
Definition: AASequence.h:107
double mz
Definition: PeptideHit.h:86
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
Lesser predicate for (modified) sequence of hits.
Definition: PeptideHit.h:198
std::vector< PepXMLAnalysisResult > * analysis_results_
additional scores attached to the original, aggregated score
Definition: PeptideHit.h:328
bool operator()(const Arg &a, const Arg &b)
Definition: PeptideHit.h:164
bool higher_is_better
Definition: PeptideHit.h:214
bool operator()(const Arg &a, const Arg &b)
Definition: PeptideHit.h:188
String annotation
Definition: PeptideHit.h:84
String score_type
Definition: PeptideHit.h:213
bool operator==(const PeptideHit::PeakAnnotation &other) const
Definition: PeptideHit.h:131
Representation of a peptide hit.
Definition: PeptideHit.h:54
Representation of a peptide evidence.
Definition: PeptideEvidence.h:50
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition: MetaInfoInterface.h:55
Int charge_
the charge of the peptide
Definition: PeptideHit.h:334
bool operator==(const PepXMLAnalysisResult &rhs) const
additional scores attached to the original, aggregated score
Definition: PeptideHit.h:218
double intensity
Definition: PeptideHit.h:87
Analysis Result (containing search engine / prophet results)
Definition: PeptideHit.h:210
bool operator!=(_Iterator< _Val, _Ref, _Ptr > const &, _Iterator< _Val, _Ref, _Ptr > const &)
Definition: KDTree.h:824
Lesser predicate for scores of hits.
Definition: PeptideHit.h:172
bool operator()(const Arg &a, const Arg &b)
Definition: PeptideHit.h:201
int charge
Definition: PeptideHit.h:85
double score_
the score of the peptide hit
Definition: PeptideHit.h:325
Contains annotations of a peak.
Definition: PeptideHit.h:82
int Int
Signed integer type.
Definition: Types.h:102
bool operator()(const Arg &a, const Arg &b)
Definition: PeptideHit.h:176
AASequence sequence_
Definition: PeptideHit.h:322
PepXMLAnalysisResult & operator=(const PepXMLAnalysisResult &source)
Definition: PeptideHit.h:226
std::vector< PeptideEvidence > peptide_evidences_
information on the potential peptides observed through this PSM.
Definition: PeptideHit.h:337