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
21
22namespace OpenMS
23{
32 class OPENMS_DLLAPI ProteinHit :
34 {
35public:
37 enum class TargetDecoyType
38 {
39 TARGET,
40 DECOY,
41 UNKNOWN
42 };
43
44 static const double COVERAGE_UNKNOWN; // == -1
45
47
48
49 class OPENMS_DLLAPI ProteinHitAccessionHash
50 {
51 public:
52 size_t operator()(const ProteinHit & p)
53 {
54 return std::hash<std::string>{}(p.getAccession());
55 }
56
57 };
58 class OPENMS_DLLAPI ProteinHitPtrAccessionHash
59 {
60 public:
61 size_t operator()(const ProteinHit * p)
62 {
63 return std::hash<std::string>{}(p->getAccession());
64 }
65
66 };
68
70
71
72 class OPENMS_DLLAPI ScoreMore
73 {
74 public:
75 template<typename Arg>
76 bool operator()(const Arg& a, const Arg& b) const
77 {
78 return std::make_tuple(a.getScore(), a.getAccession()) > std::make_tuple(b.getScore(), b.getAccession());
79 }
80 };
81
83 class OPENMS_DLLAPI ScoreLess
84 {
85public:
86 template <typename Arg>
87 bool operator()(const Arg & a, const Arg & b) const
88 {
89 return std::make_tuple(a.getScore(), a.getAccession()) < std::make_tuple(b.getScore(), b.getAccession());
90 }
91
92 };
94
97
100
102 ProteinHit(double score, UInt rank, std::string accession, std::string sequence);
103
105 ProteinHit(const ProteinHit &) = default;
106
108 ProteinHit(ProteinHit&&) = default;
109
111
113 ProteinHit & operator=(const ProteinHit &) = default;
114
116 ProteinHit& operator=(ProteinHit&&) = default; // TODO: add noexcept (gcc 4.8 bug)
117
120
122 bool operator==(const ProteinHit & rhs) const;
123
125 bool operator!=(const ProteinHit & rhs) const;
126
127
130
132 double getScore() const;
133
135 UInt getRank() const;
136
138 const std::string & getSequence() const;
139
141 const std::string & getAccession() const;
142
144 std::string getDescription() const;
145
147 double getCoverage() const;
148
150 void setScore(const double score);
151
153 void setRank(UInt newrank);
154
156 void setSequence(const std::string & sequence);
157 void setSequence(std::string && sequence);
158
160 void setAccession(const std::string & accession);
161
163 void setDescription(const std::string & description);
164
166 void setCoverage(const double coverage);
167
169 const std::set<std::pair<Size, ResidueModification> >& getModifications() const;
170
172 void setModifications(std::set<std::pair<Size, ResidueModification> >& mods);
173
175 bool isDecoy() const;
176
188
201
203
204protected:
205 double score_;
207 std::string accession_;
208 std::string sequence_;
209 double coverage_;
210 std::set<std::pair<Size, ResidueModification> > modifications_;
211 };
212
214 OPENMS_DLLAPI std::ostream& operator<< (std::ostream& stream, const ProteinHit& hit);
215
216} // namespace OpenMS
217
218// Hash function specialization for ProteinHit
219namespace std
220{
237 template<>
238 struct hash<OpenMS::ProteinHit>
239 {
240 std::size_t operator()(const OpenMS::ProteinHit& hit) const noexcept
241 {
242 std::size_t seed = OpenMS::hash_float(hit.getScore());
243 OpenMS::hash_combine(seed, OpenMS::hash_int(hit.getRank()));
244 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(hit.getAccession()));
245 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(hit.getSequence()));
246 OpenMS::hash_combine(seed, OpenMS::hash_float(hit.getCoverage()));
247
248 // Hash modifications (set of pairs: position + ResidueModification)
249 for (const auto& mod_pair : hit.getModifications())
250 {
251 OpenMS::hash_combine(seed, OpenMS::hash_int(mod_pair.first)); // position (Size)
252 // Use getFullId() for the modification, consistent with AASequence hashing
253 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(mod_pair.second.getFullId()));
254 }
255
256 return seed;
257 }
258 };
259} // namespace std
260
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition MetaInfoInterface.h:35
Hash of a ProteinHit based on its accession only!
Definition ProteinHit.h:50
size_t operator()(const ProteinHit &p)
Definition ProteinHit.h:52
size_t operator()(const ProteinHit *p)
Definition ProteinHit.h:61
Lesser predicate for scores of hits.
Definition ProteinHit.h:84
bool operator()(const Arg &a, const Arg &b) const
Definition ProteinHit.h:87
Greater predicate for scores of hits.
Definition ProteinHit.h:73
bool operator()(const Arg &a, const Arg &b) const
Definition ProteinHit.h:76
Representation of a protein hit.
Definition ProteinHit.h:34
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.
bool isDecoy() const
returns true if this is a decoy hit (false for TARGET and UNKNOWN)
void setDescription(const std::string &description)
sets the description of the protein
UInt rank_
the position(rank) where the hit appeared in the hit list
Definition ProteinHit.h:206
void setSequence(const std::string &sequence)
sets the protein sequence
void setModifications(std::set< std::pair< Size, ResidueModification > > &mods)
sets the set of modified protein positions
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:210
ProteinHit & operator=(const ProteinHit &)=default
Assignment operator.
void setRank(UInt newrank)
sets the rank
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
std::string sequence_
the amino acid sequence of the protein hit
Definition ProteinHit.h:208
std::string accession_
the protein identifier
Definition ProteinHit.h:207
const std::string & getSequence() const
returns the protein sequence
double coverage_
coverage of the protein based upon the matched peptide sequences
Definition ProteinHit.h:209
void setAccession(const std::string &accession)
sets the accession of the protein
ProteinHit & operator=(const MetaInfoInterface &source)
Assignment for MetaInfo.
const std::string & getAccession() const
returns the accession of the protein
void setSequence(std::string &&sequence)
TargetDecoyType
Enum for target/decoy annotation.
Definition ProteinHit.h:38
double score_
the score of the protein hit
Definition ProteinHit.h:205
std::string getDescription() const
returns the description of the protein
void setCoverage(const double coverage)
sets the coverage (in percent) of the protein hit based upon matched peptides
ProteinHit(double score, UInt rank, std::string accession, std::string sequence)
Values constructor.
static const double COVERAGE_UNKNOWN
Definition ProteinHit.h:44
ProteinHit(ProteinHit &&)=default
Move constructor.
ProteinHit(const ProteinHit &)=default
Copy constructor.
@ UNKNOWN
Unknown or unrecognized ion type.
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)
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:240