OpenMS
Loading...
Searching...
No Matches
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#include <functional>
14
22
23namespace OpenMS
24{
25 class PeptideHit;
26 using SpectrumMatch = PeptideHit; // better name that might become the default in future version
27
50 class OPENMS_DLLAPI PeptideHit :
52 {
53public:
55 enum class TargetDecoyType
56 {
57 TARGET,
58 DECOY,
59 TARGET_DECOY,
60 UNKNOWN
61 };
62
86 struct OPENMS_DLLAPI PeakAnnotation
87 {
88 String annotation = ""; // e.g. [alpha|ci$y3-H2O-NH3]
89 int charge = 0;
90 double mz = -1.;
91 double intensity = 0.;
92
93 bool operator<(const PeptideHit::PeakAnnotation& other) const;
94
95 bool operator==(const PeptideHit::PeakAnnotation& other) const;
96
97 static void writePeakAnnotationsString_(String& annotation_string, std::vector<PeptideHit::PeakAnnotation> annotations);
98
99 };
100
101public:
102
104
105
106 class OPENMS_DLLAPI ScoreMore
107 {
108public:
109 template <typename Arg>
110 bool operator()(const Arg& a, const Arg& b)
111 {
112 return a.getScore() > b.getScore();
113 }
114
115 };
116
118 class OPENMS_DLLAPI ScoreLess
119 {
120public:
121 template <typename Arg>
122 bool operator()(const Arg& a, const Arg& b)
123 {
124 return a.getScore() < b.getScore();
125 }
126
127 };
128
130 class OPENMS_DLLAPI RankLess
131 {
132public:
133 template <typename Arg>
134 bool operator()(const Arg& a, const Arg& b)
135 {
136 return a.getRank() < b.getRank();
137 }
138
139 };
141
143
144
160 class OPENMS_DLLAPI SequenceChargeHash
161 {
162 public:
163 std::size_t operator()(const PeptideHit& hit) const noexcept
164 {
165 std::size_t seed = std::hash<AASequence>{}(hit.getSequence());
166 OpenMS::hash_combine(seed, OpenMS::hash_int(hit.getCharge()));
167 return seed;
168 }
169 };
170
176 class OPENMS_DLLAPI SequenceChargeEqual
177 {
178 public:
179 bool operator()(const PeptideHit& a, const PeptideHit& b) const noexcept
180 {
181 return a.getSequence() == b.getSequence() && a.getCharge() == b.getCharge();
182 }
183 };
185
186
188 class OPENMS_DLLAPI SequenceLessComparator
189 {
190 template <typename Arg>
191 bool operator()(const Arg& a, const Arg& b)
192 {
193 if (a.getSequence().toString() < b.getSequence().toString()) return true;
194 return false;
195 }
196 };
198
200 class OPENMS_DLLAPI PepXMLAnalysisResult
201 {
202public:
204 bool higher_is_better{};
205 double main_score{};
206 std::map<String, double> sub_scores;
207
208 bool operator==(const PepXMLAnalysisResult& rhs) const
209 {
210 return score_type == rhs.score_type
211 && higher_is_better == rhs.higher_is_better
212 && main_score == rhs.main_score
213 && sub_scores == rhs.sub_scores;
214 }
215 };
216
223 PeptideHit(double score,
224 UInt rank,
225 Int charge,
226 const AASequence& sequence);
228 PeptideHit(double score,
229 UInt rank,
230 Int charge,
231 AASequence&& sequence);
233 PeptideHit(const PeptideHit& source);
237 virtual ~PeptideHit();
238
240 PeptideHit& operator=(const PeptideHit& source);
242 PeptideHit& operator=(PeptideHit&&) noexcept;
244
246 bool operator==(const PeptideHit& rhs) const;
247
249 bool operator!=(const PeptideHit& rhs) const;
250
255 const AASequence& getSequence() const;
256
258 AASequence& getSequence();
259
261 void setSequence(const AASequence& sequence);
262
264 void setSequence(AASequence&& sequence);
265
267 Int getCharge() const;
268
270 void setCharge(Int charge);
271
273 const std::vector<PeptideEvidence>& getPeptideEvidences() const;
274
276 void setPeptideEvidences(const std::vector<PeptideEvidence>& peptide_evidences);
277
278 void setPeptideEvidences(std::vector<PeptideEvidence>&& peptide_evidences);
279
281 void addPeptideEvidence(const PeptideEvidence& peptide_evidence);
282
284 double getScore() const;
285
287 void setScore(double score);
288
290 void setAnalysisResults(const std::vector<PepXMLAnalysisResult>& aresult);
291
293 void addAnalysisResults(const PepXMLAnalysisResult& aresult);
294
296 std::vector<PepXMLAnalysisResult> getAnalysisResults() const;
297
299 UInt getRank() const;
300
302 void setRank(UInt newrank);
303
305 std::vector<PeptideHit::PeakAnnotation>& getPeakAnnotations();
306 const std::vector<PeptideHit::PeakAnnotation>& getPeakAnnotations() const;
307
308
310 void setPeakAnnotations(std::vector<PeptideHit::PeakAnnotation> frag_annotations);
311
317 bool isDecoy() const;
318
333 void setTargetDecoyType(TargetDecoyType type);
334
347 TargetDecoyType getTargetDecoyType() const;
348
350
352 std::set<String> extractProteinAccessionsSet() const;
353
354protected:
355 AASequence sequence_;
356
358 double score_{};
359
361 Int charge_{};
362
364 std::vector<PeptideEvidence> peptide_evidences_;
365
367 std::vector<PeptideHit::PeakAnnotation> fragment_annotations_;
368
369private:
372
374 std::vector<PepXMLAnalysisResult> extractAnalysisResultsFromMetaValues_() const;
375 };
376
378 OPENMS_DLLAPI std::ostream& operator<< (std::ostream& stream, const PeptideHit& hit);
379} // namespace OpenMS
380
381// Hash function specialization for PeptideHit::PeakAnnotation
382namespace std
383{
392 template<>
393 struct hash<OpenMS::PeptideHit::PeakAnnotation>
394 {
395 std::size_t operator()(const OpenMS::PeptideHit::PeakAnnotation& pa) const noexcept
396 {
397 std::size_t seed = OpenMS::fnv1a_hash_string(pa.annotation);
398 OpenMS::hash_combine(seed, OpenMS::hash_int(pa.charge));
400 OpenMS::hash_combine(seed, OpenMS::hash_float(pa.intensity));
401 return seed;
402 }
403 };
404} // namespace std
405
406// Hash function specialization for PeptideHit
407namespace std
408{
423 template<>
424 struct hash<OpenMS::PeptideHit>
425 {
426 std::size_t operator()(const OpenMS::PeptideHit& hit) const noexcept
427 {
428 // Start with MetaInfoInterface hash (includes rank which is stored as meta value)
429 std::size_t seed = std::hash<OpenMS::MetaInfoInterface>{}(hit);
430
431 // Hash sequence
432 OpenMS::hash_combine(seed, std::hash<OpenMS::AASequence>{}(hit.getSequence()));
433
434 // Hash score
435 OpenMS::hash_combine(seed, OpenMS::hash_float(hit.getScore()));
436
437 // Note: rank is NOT hashed separately - it's included via MetaInfoInterface above
438 // (rank is stored as meta value "rank" when non-zero)
439
440 // Hash charge
441 OpenMS::hash_combine(seed, OpenMS::hash_int(hit.getCharge()));
442
443 // Hash peptide evidences
444 for (const auto& pe : hit.getPeptideEvidences())
445 {
446 OpenMS::hash_combine(seed, std::hash<OpenMS::PeptideEvidence>{}(pe));
447 }
448
449 // Hash fragment annotations
450 for (const auto& fa : hit.getPeakAnnotations())
451 {
452 OpenMS::hash_combine(seed, std::hash<OpenMS::PeptideHit::PeakAnnotation>{}(fa));
453 }
454
455 return seed;
456 }
457 };
458} // namespace std
Representation of a peptide/protein sequence.
Definition AASequence.h:88
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition MetaInfoInterface.h:36
Representation of a peptide evidence.
Definition PeptideEvidence.h:28
Analysis Result (containing search engine / prophet results)
Definition PeptideHit.h:201
bool operator==(const PepXMLAnalysisResult &rhs) const
additional scores attached to the original, aggregated score
Definition PeptideHit.h:208
String score_type
Definition PeptideHit.h:203
bool higher_is_better
e.g. peptideprophet / interprophet
Definition PeptideHit.h:204
std::map< String, double > sub_scores
posterior probability for example
Definition PeptideHit.h:206
double main_score
is higher score better ?
Definition PeptideHit.h:205
Lesser predicate for scores of hits.
Definition PeptideHit.h:131
bool operator()(const Arg &a, const Arg &b)
Definition PeptideHit.h:134
Lesser predicate for scores of hits.
Definition PeptideHit.h:119
bool operator()(const Arg &a, const Arg &b)
Definition PeptideHit.h:122
Greater predicate for scores of hits.
Definition PeptideHit.h:107
bool operator()(const Arg &a, const Arg &b)
Definition PeptideHit.h:110
Equality functor for PeptideHit based on sequence and charge.
Definition PeptideHit.h:177
bool operator()(const PeptideHit &a, const PeptideHit &b) const noexcept
Definition PeptideHit.h:179
Hash functor for PeptideHit based on sequence and charge.
Definition PeptideHit.h:161
std::size_t operator()(const PeptideHit &hit) const noexcept
Definition PeptideHit.h:163
Lesser predicate for (modified) sequence of hits.
Definition PeptideHit.h:189
bool operator()(const Arg &a, const Arg &b)
Definition PeptideHit.h:191
Represents a single spectrum match (candidate) for a specific tandem mass spectrum (MS/MS).
Definition PeptideHit.h:52
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.
PeptideHit()
Default constructor.
std::vector< PeptideEvidence > peptide_evidences_
information on the potential peptides observed through this PSM.
Definition PeptideHit.h:364
PeptideHit(const PeptideHit &source)
Copy constructor.
std::vector< PeptideHit::PeakAnnotation > fragment_annotations_
annotations of fragments in the corresponding spectrum
Definition PeptideHit.h:367
PeptideHit(double score, UInt rank, Int charge, AASequence &&sequence)
Values constructor that moves sequence R-value.
std::vector< PepXMLAnalysisResult > extractAnalysisResultsFromMetaValues_() const
Extract analysis results from meta values (only for pepXML results)
TargetDecoyType
Enum for target/decoy annotation.
Definition PeptideHit.h:56
A more convenient string class.
Definition String.h:34
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)
@ UNKNOWN
ion mobility format not yet determined.
std::size_t hash_int(T value) noexcept
Hash for an integer type.
Definition HashUtils.h:107
void hash_combine(std::size_t &seed, std::size_t value) noexcept
Combine a hash value with additional data using golden ratio mixing.
Definition HashUtils.h:87
std::size_t hash_float(T value) noexcept
Hash for a floating point type (float or double).
Definition HashUtils.h:142
std::size_t fnv1a_hash_string(const std::string &s) noexcept
FNV-1a hash for a string.
Definition HashUtils.h:70
STL namespace.
Contains annotations of a peak.
Definition PeptideHit.h:87
bool operator==(const PeptideHit::PeakAnnotation &other) const
bool operator<(const PeptideHit::PeakAnnotation &other) const
static void writePeakAnnotationsString_(String &annotation_string, std::vector< PeptideHit::PeakAnnotation > annotations)
std::size_t operator()(const OpenMS::PeptideHit &hit) const noexcept
Definition PeptideHit.h:426
std::size_t operator()(const OpenMS::PeptideHit::PeakAnnotation &pa) const noexcept
Definition PeptideHit.h:395