| OpenMS 2.5.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 <vector>
38
39 #include <OpenMS/CONCEPT/Types.h>
40 #include <OpenMS/DATASTRUCTURES/String.h>
41 #include <OpenMS/METADATA/MetaInfoInterface.h>
42 #include <OpenMS/CHEMISTRY/AASequence.h>
43 #include <OpenMS/METADATA/PeptideEvidence.h>
44
45 namespace OpenMS
46 {
54 class OPENMS_DLLAPI PeptideHit :
55 public MetaInfoInterface
56 {
57 public:
58
82 struct PeakAnnotation
83 {
84 String annotation = ""; // e.g. [alpha|ci$y3-H2O-NH3]
85 int charge = 0;
86 double mz = -1.;
87 double intensity = 0.;
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 };
226
230 PeptideHit();
233 PeptideHit(double score,
234 UInt rank,
235 Int charge,
236 const AASequence& sequence);
238 PeptideHit(double score,
239 UInt rank,
240 Int charge,
241 AASequence&& sequence);
243 PeptideHit(const PeptideHit& source);
245 PeptideHit(PeptideHit&&) noexcept;
247 virtual ~PeptideHit();
248
250 PeptideHit& operator=(const PeptideHit& source);
252 PeptideHit& operator=(PeptideHit&&) noexcept;
254
256 bool operator==(const PeptideHit& rhs) const;
257
259 bool operator!=(const PeptideHit& rhs) const;
260
264 const AASequence& getSequence() const;
266
268 void setSequence(const AASequence& sequence);
269
271 void setSequence(AASequence&& sequence);
272
274 Int getCharge() const;
275
277 void setCharge(Int charge);
278
280 const std::vector<PeptideEvidence>& getPeptideEvidences() const;
281
283 void setPeptideEvidences(const std::vector<PeptideEvidence>& peptide_evidences);
284
285 void setPeptideEvidences(std::vector<PeptideEvidence>&& peptide_evidences);
286
288 void addPeptideEvidence(const PeptideEvidence& peptide_evidence);
289
291 double getScore() const;
292
294 void setScore(double score);
295
297 void setAnalysisResults(std::vector<PepXMLAnalysisResult> aresult);
298
300 void addAnalysisResults(PepXMLAnalysisResult aresult);
301
303 const std::vector<PepXMLAnalysisResult>& getAnalysisResults() const;
304
306 UInt getRank() const;
307
309 void setRank(UInt newrank);
310
312 std::vector<PeptideHit::PeakAnnotation> getPeakAnnotations() const;
313
315 void setPeakAnnotations(std::vector<PeptideHit::PeakAnnotation> frag_annotations);
316
318
320 std::set<String> extractProteinAccessionsSet() const;
321
322 protected:
323 AASequence sequence_;
324
326 double score_;
327
329 std::vector<PepXMLAnalysisResult>* analysis_results_;
330
332 UInt rank_;
333
335 Int charge_;
336
338 std::vector<PeptideEvidence> peptide_evidences_;
339
341 std::vector<PeptideHit::PeakAnnotation> fragment_annotations_;
342 };
343
344 } // namespace OpenMS
OpenMS::PeptideHit::SequenceLessComparator::operator()
bool operator()(const Arg &a, const Arg &b)
Definition: PeptideHit.h:201
OpenMS::PeptideHit::PepXMLAnalysisResult::higher_is_better
bool higher_is_better
Definition: PeptideHit.h:214
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::PeptideHit::PeakAnnotation::charge
int charge
Definition: PeptideHit.h:85
AASequence.h
OpenMS::PeptideHit::RankLess::operator()
bool operator()(const Arg &a, const Arg &b)
Definition: PeptideHit.h:188
OpenMS::PeptideEvidence
Representation of a peptide evidence.
Definition: PeptideEvidence.h:50
std
STL namespace.
Types.h
OpenMS::PeptideHit::PepXMLAnalysisResult::operator==
bool operator==(const PepXMLAnalysisResult &rhs) const
additional scores attached to the original, aggregated score
Definition: PeptideHit.h:218
OpenMS::PeptideHit::PepXMLAnalysisResult::sub_scores
std::map< String, double > sub_scores
Definition: PeptideHit.h:216
PeptideEvidence.h
OpenMS::PeptideHit::RankLess
Lesser predicate for scores of hits.
Definition: PeptideHit.h:184
OpenMS::PeptideHit::PeakAnnotation
Contains annotations of a peak.
Definition: PeptideHit.h:82
OpenMS::AASequence
Representation of a peptide/protein sequence.
Definition: AASequence.h:113
OpenMS::PeptideHit::PeakAnnotation::writePeakAnnotationsString_
static void writePeakAnnotationsString_(String &annotation_string, std::vector< PeptideHit::PeakAnnotation > annotations)
Definition: PeptideHit.h:138
String.h
OpenMS::PeptideHit::PepXMLAnalysisResult
Analysis Result (containing search engine / prophet results)
Definition: PeptideHit.h:210
OpenMS::PeptideHit::PepXMLAnalysisResult::main_score
double main_score
Definition: PeptideHit.h:215
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::PeptideHit::ScoreLess
Lesser predicate for scores of hits.
Definition: PeptideHit.h:172
OpenMS::PeptideHit
Representation of a peptide hit.
Definition: PeptideHit.h:54
OpenMS::PeptideHit::PeakAnnotation::intensity
double intensity
Definition: PeptideHit.h:87
OpenMS::UInt
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
OpenMS::PeptideHit::SequenceLessComparator
Lesser predicate for (modified) sequence of hits.
Definition: PeptideHit.h:198
OpenMS::PeptideHit::PeakAnnotation::annotation
String annotation
Definition: PeptideHit.h:84
OpenMS::PeptideHit::PeakAnnotation::operator<
bool operator<(const PeptideHit::PeakAnnotation &other) const
Definition: PeptideHit.h:89
OpenMS::String::quote
String & quote(char q='"', QuotingMethod method = ESCAPE)
Wraps the string in quotation marks.
int
OpenMS::PeptideHit::PepXMLAnalysisResult::score_type
String score_type
Definition: PeptideHit.h:213
OpenMS::PeptideHit::PeakAnnotation::operator==
bool operator==(const PeptideHit::PeakAnnotation &other) const
Definition: PeptideHit.h:131
MetaInfoInterface.h
OpenMS::PeptideHit::ScoreLess::operator()
bool operator()(const Arg &a, const Arg &b)
Definition: PeptideHit.h:176
OpenMS::PeptideHit::PeakAnnotation::mz
double mz
Definition: PeptideHit.h:86
OpenMS::PeptideHit::ScoreMore::operator()
bool operator()(const Arg &a, const Arg &b)
Definition: PeptideHit.h:164
OpenMS::MetaInfoInterface
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition: MetaInfoInterface.h:60