OpenMS
Loading...
Searching...
No Matches
ProteinHit.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#include <set>
15#include <map>
16
22
23namespace OpenMS
24{
33 class OPENMS_DLLAPI ProteinHit :
35 {
36public:
38 enum class TargetDecoyType
39 {
40 TARGET,
41 DECOY,
42 UNKNOWN
43 };
44
45 static const double COVERAGE_UNKNOWN; // == -1
46
48
49
50 class OPENMS_DLLAPI ProteinHitAccessionHash
51 {
52 public:
53 size_t operator()(const ProteinHit & p)
54 {
55 return std::hash<std::string>{}(p.getAccession());
56 }
57
58 };
59 class OPENMS_DLLAPI ProteinHitPtrAccessionHash
60 {
61 public:
62 size_t operator()(const ProteinHit * p)
63 {
64 return std::hash<std::string>{}(p->getAccession());
65 }
66
67 };
69
71
72
73 class OPENMS_DLLAPI ScoreMore
74 {
75 public:
76 template<typename Arg>
77 bool operator()(const Arg& a, const Arg& b) const
78 {
79 return std::make_tuple(a.getScore(), a.getAccession()) > std::make_tuple(b.getScore(), b.getAccession());
80 }
81 };
82
84 class OPENMS_DLLAPI ScoreLess
85 {
86public:
87 template <typename Arg>
88 bool operator()(const Arg & a, const Arg & b) const
89 {
90 return std::make_tuple(a.getScore(), a.getAccession()) < std::make_tuple(b.getScore(), b.getAccession());
91 }
92
93 };
95
98
101
103 ProteinHit(double score, UInt rank, String accession, String sequence);
104
106 ProteinHit(const ProteinHit &) = default;
107
109 ProteinHit(ProteinHit&&) = default;
110
112
114 ProteinHit & operator=(const ProteinHit &) = default;
115
117 ProteinHit& operator=(ProteinHit&&) = default; // TODO: add noexcept (gcc 4.8 bug)
118
121
123 bool operator==(const ProteinHit & rhs) const;
124
126 bool operator!=(const ProteinHit & rhs) const;
127
128
131
133 double getScore() const;
134
136 UInt getRank() const;
137
139 const String & getSequence() const;
140
142 const String & getAccession() const;
143
146
148 double getCoverage() const;
149
151 void setScore(const double score);
152
154 void setRank(UInt newrank);
155
157 void setSequence(const String & sequence);
158 void setSequence(String && sequence);
159
161 void setAccession(const String & accession);
162
164 void setDescription(const String & description);
165
167 void setCoverage(const double coverage);
168
170 const std::set<std::pair<Size, ResidueModification> >& getModifications() const;
171
173 void setModifications(std::set<std::pair<Size, ResidueModification> >& mods);
174
176 bool isDecoy() const;
177
189
202
204
205protected:
206 double score_;
210 double coverage_;
211 std::set<std::pair<Size, ResidueModification> > modifications_;
212 };
213
215 OPENMS_DLLAPI std::ostream& operator<< (std::ostream& stream, const ProteinHit& hit);
216
217} // namespace OpenMS
218
219// Hash function specialization for ProteinHit
220namespace std
221{
238 template<>
239 struct hash<OpenMS::ProteinHit>
240 {
241 std::size_t operator()(const OpenMS::ProteinHit& hit) const noexcept
242 {
243 std::size_t seed = OpenMS::hash_float(hit.getScore());
244 OpenMS::hash_combine(seed, OpenMS::hash_int(hit.getRank()));
245 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(hit.getAccession()));
246 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(hit.getSequence()));
247 OpenMS::hash_combine(seed, OpenMS::hash_float(hit.getCoverage()));
248
249 // Hash modifications (set of pairs: position + ResidueModification)
250 for (const auto& mod_pair : hit.getModifications())
251 {
252 OpenMS::hash_combine(seed, OpenMS::hash_int(mod_pair.first)); // position (Size)
253 // Use getFullId() for the modification, consistent with AASequence hashing
254 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(mod_pair.second.getFullId()));
255 }
256
257 return seed;
258 }
259 };
260} // namespace std
261
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition MetaInfoInterface.h:36
Hash of a ProteinHit based on its accession only!
Definition ProteinHit.h:51
size_t operator()(const ProteinHit &p)
Definition ProteinHit.h:53
size_t operator()(const ProteinHit *p)
Definition ProteinHit.h:62
Lesser predicate for scores of hits.
Definition ProteinHit.h:85
bool operator()(const Arg &a, const Arg &b) const
Definition ProteinHit.h:88
Greater predicate for scores of hits.
Definition ProteinHit.h:74
bool operator()(const Arg &a, const Arg &b) const
Definition ProteinHit.h:77
Representation of a protein hit.
Definition ProteinHit.h:35
double getScore() const
returns the score of the protein hit
double getCoverage() const
returns the coverage (in percent) of the protein hit based upon matched peptides
void setTargetDecoyType(TargetDecoyType type)
Sets the target/decoy type for this protein hit.
TargetDecoyType getTargetDecoyType() const
Returns the target/decoy type for this protein hit.
bool operator==(const ProteinHit &rhs) const
Equality operator.
void setSequence(const String &sequence)
sets the protein sequence
bool isDecoy() const
returns true if this is a decoy hit (false for TARGET and UNKNOWN)
String sequence_
the amino acid sequence of the protein hit
Definition ProteinHit.h:209
UInt rank_
the position(rank) where the hit appeared in the hit list
Definition ProteinHit.h:207
void setModifications(std::set< std::pair< Size, ResidueModification > > &mods)
sets the set of modified protein positions
void setSequence(String &&sequence)
ProteinHit()
Default constructor.
ProteinHit & operator=(ProteinHit &&)=default
Move assignment operator.
void setScore(const double score)
sets the score of the protein hit
bool operator!=(const ProteinHit &rhs) const
Inequality operator.
std::set< std::pair< Size, ResidueModification > > modifications_
modified positions in a protein
Definition ProteinHit.h:211
ProteinHit & operator=(const ProteinHit &)=default
Assignment operator.
void setRank(UInt newrank)
sets the rank
const String & getSequence() const
returns the protein sequence
const std::set< std::pair< Size, ResidueModification > > & getModifications() const
returns the set of modified protein positions
UInt getRank() const
returns the rank of the protein hit
ProteinHit(double score, UInt rank, String accession, String sequence)
Values constructor.
String accession_
the protein identifier
Definition ProteinHit.h:208
void setDescription(const String &description)
sets the description of the protein
void setAccession(const String &accession)
sets the accession of the protein
double coverage_
coverage of the protein based upon the matched peptide sequences
Definition ProteinHit.h:210
ProteinHit & operator=(const MetaInfoInterface &source)
Assignment for MetaInfo.
const String & getAccession() const
returns the accession of the protein
TargetDecoyType
Enum for target/decoy annotation.
Definition ProteinHit.h:39
String getDescription() const
returns the description of the protein
double score_
the score of the protein hit
Definition ProteinHit.h:206
void setCoverage(const double coverage)
sets the coverage (in percent) of the protein hit based upon matched peptides
static const double COVERAGE_UNKNOWN
Definition ProteinHit.h:45
ProteinHit(ProteinHit &&)=default
Move constructor.
ProteinHit(const ProteinHit &)=default
Copy constructor.
A more convenient string class.
Definition String.h:34
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.
std::size_t operator()(const OpenMS::ProteinHit &hit) const noexcept
Definition ProteinHit.h:241