OpenMS
Loading...
Searching...
No Matches
PeptideIdentification.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
15
16#include <functional>
17#include <string>
18#include <map>
19
20namespace OpenMS
21{
22 class ConsensusMap;
23 class PeptideIdentification;
24
25 using SpectrumIdentification = PeptideIdentification; // better name that might become the default in future version
26
62 class OPENMS_DLLAPI PeptideIdentification :
64 {
65public:
66
69
71
72
75 virtual ~PeptideIdentification() noexcept;
80
82 PeptideIdentification& operator=(const PeptideIdentification&) = default;
84 PeptideIdentification& operator=(PeptideIdentification&&) = default; // TODO: add noexcept (gcc 4.8 bug)
86 bool operator==(const PeptideIdentification& rhs) const;
88 bool operator!=(const PeptideIdentification& rhs) const;
90
92 double getRT() const;
94 void setRT(double rt);
96 bool hasRT() const;
97
99 double getMZ() const;
101 void setMZ(double mz);
103 bool hasMZ() const;
104
106 const std::vector<PeptideHit>& getHits() const;
108 std::vector<PeptideHit>& getHits();
110 void insertHit(const PeptideHit& hit);
112 void insertHit(PeptideHit&& hit);
114 void setHits(const std::vector<PeptideHit>& hits);
115 void setHits(std::vector<PeptideHit>&& hits);
116
118 double getSignificanceThreshold() const;
120 void setSignificanceThreshold(double value);
121
123 const String& getScoreType() const;
125 void setScoreType(const String& type);
126
128 bool isHigherScoreBetter() const;
130 void setHigherScoreBetter(bool value);
131
133 const String& getIdentifier() const;
135 void setIdentifier(const String& id);
136
138 String getBaseName() const;
140 void setBaseName(const String& base_name);
141
143 const String getExperimentLabel() const;
145 void setExperimentLabel(const String& type);
146
149 // TODO make a mandatory data member, add to idXML schema, think about storing the
150 // extracted spectrum "number" only!
151 String getSpectrumReference() const;
154 void setSpectrumReference(const String& ref);
155
156 // Returns a higher or lower comparator based on @p higher_score_better_
157 static std::function<bool(const PeptideHit&, const PeptideHit&)> getScoreComparator(bool higher_score_better);
158
164 void sort();
165
167 bool empty() const;
168
170 static std::vector<PeptideHit> getReferencingHits(const std::vector<PeptideHit>&, const std::set<String>& accession);
171
180 static std::multimap<String, std::pair<Size, Size>> buildUIDsFromAllPepIDs(const ConsensusMap &cmap);
181
200 static String buildUIDFromPepID(const PeptideIdentification& pep_id,
201 const std::map<String, StringList>& identifier_to_msrunpath);
202
203protected:
204 String id_;
205 std::vector<PeptideHit> hits_;
206 String score_type_;
207 bool higher_score_better_;
208 double mz_;
209 double rt_;
210 };
211
212} //namespace OpenMS
213
214// Hash function specialization for PeptideIdentification
215namespace std
216{
234 template<>
235 struct hash<OpenMS::PeptideIdentification>
236 {
237 std::size_t operator()(const OpenMS::PeptideIdentification& pi) const noexcept
238 {
239 // Start with MetaInfoInterface hash (includes significance_threshold, experiment_label, base_name)
240 std::size_t seed = std::hash<OpenMS::MetaInfoInterface>{}(pi);
241
242 // Hash identifier
243 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(pi.getIdentifier()));
244
245 // Hash all peptide hits
246 for (const auto& hit : pi.getHits())
247 {
248 OpenMS::hash_combine(seed, std::hash<OpenMS::PeptideHit>{}(hit));
249 }
250
251 // Hash score type
252 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(pi.getScoreType()));
253
254 // Hash higher_score_better
255 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(pi.isHigherScoreBetter())));
256
257 // Hash mz (with NaN handling - NaN values hash to same value)
258 if (pi.hasMZ())
259 {
260 OpenMS::hash_combine(seed, OpenMS::hash_float(pi.getMZ()));
261 }
262 else
263 {
264 // Hash a sentinel value for NaN (consistent with operator== which treats NaN==NaN as true)
265 OpenMS::hash_combine(seed, OpenMS::hash_int(0xDEADBEEF));
266 }
267
268 // Hash rt (with NaN handling)
269 if (pi.hasRT())
270 {
271 OpenMS::hash_combine(seed, OpenMS::hash_float(pi.getRT()));
272 }
273 else
274 {
275 // Hash a different sentinel value for NaN RT
276 OpenMS::hash_combine(seed, OpenMS::hash_int(0xCAFEBABE));
277 }
278
279 return seed;
280 }
281 };
282} // namespace std
283
A container for consensus elements.
Definition ConsensusMap.h:68
Definition MzIdentMLHandler.h:135
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition MetaInfoInterface.h:36
Represents a single spectrum match (candidate) for a specific tandem mass spectrum (MS/MS).
Definition PeptideHit.h:52
Represents the set of candidates (SpectrumMatches) identified for a single precursor spectrum.
Definition PeptideIdentification.h:64
PeptideHit HitType
Hit type definition.
Definition PeptideIdentification.h:68
PeptideIdentification()
default constructor
virtual ~PeptideIdentification() noexcept
destructor
A more convenient string class.
Definition String.h:34
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
std::vector< String > StringList
Vector of String.
Definition ListUtils.h:44
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
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::PeptideIdentification &pi) const noexcept
Definition PeptideIdentification.h:237