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
16#include <OpenMS/METADATA/USI.h>
17
18#include <functional>
19#include <string>
20#include <map>
21
22namespace OpenMS
23{
24 class ConsensusMap;
25 class PeptideIdentification;
26
27 using SpectrumIdentification = PeptideIdentification; // better name that might become the default in future version
28
64 class OPENMS_DLLAPI PeptideIdentification :
66 {
67public:
68
71
73
74
77 virtual ~PeptideIdentification() noexcept;
82
84 PeptideIdentification& operator=(const PeptideIdentification&) = default;
86 PeptideIdentification& operator=(PeptideIdentification&&) = default; // TODO: add noexcept (gcc 4.8 bug)
88 bool operator==(const PeptideIdentification& rhs) const;
90 bool operator!=(const PeptideIdentification& rhs) const;
92
94 double getRT() const;
96 void setRT(double rt);
98 bool hasRT() const;
99
101 double getMZ() const;
103 void setMZ(double mz);
105 bool hasMZ() const;
106
108 const std::vector<PeptideHit>& getHits() const;
110 std::vector<PeptideHit>& getHits();
112 void insertHit(const PeptideHit& hit);
114 void insertHit(PeptideHit&& hit);
116 void setHits(const std::vector<PeptideHit>& hits);
117 void setHits(std::vector<PeptideHit>&& hits);
118
120 double getSignificanceThreshold() const;
122 void setSignificanceThreshold(double value);
123
125 const String& getScoreType() const;
127 void setScoreType(const String& type);
128
130 bool isHigherScoreBetter() const;
132 void setHigherScoreBetter(bool value);
133
135 const String& getIdentifier() const;
137 void setIdentifier(const String& id);
138
140 String getBaseName() const;
142 void setBaseName(const String& base_name);
143
145 const String getExperimentLabel() const;
147 void setExperimentLabel(const String& type);
148
151 // TODO make a mandatory data member, add to idXML schema, think about storing the
152 // extracted spectrum "number" only!
153 String getSpectrumReference() const;
156 void setSpectrumReference(const String& ref);
157
158 // Returns a higher or lower comparator based on @p higher_score_better_
159 static std::function<bool(const PeptideHit&, const PeptideHit&)> getScoreComparator(bool higher_score_better);
160
166 void sort();
167
169 bool empty() const;
170
172 static std::vector<PeptideHit> getReferencingHits(const std::vector<PeptideHit>&, const std::set<String>& accession);
173
182 static std::multimap<String, std::pair<Size, Size>> buildUIDsFromAllPepIDs(const ConsensusMap &cmap);
183
201 static String buildUIDFromPepID(const PeptideIdentification& pep_id,
202 const IdentifierMSRunMapper& mapping);
203
227 USI buildUSI(const String& ms_run_name,
228 const String& dataset_id = "local",
229 bool include_interpretation = false) const;
230
254 USI buildUSI(const IdentifierMSRunMapper& mapping,
255 const String& dataset_id = "local",
256 bool include_interpretation = false) const;
257
258protected:
259 String id_;
260 std::vector<PeptideHit> hits_;
261 String score_type_;
262 bool higher_score_better_;
263 double mz_;
264 double rt_;
265 };
266
267} //namespace OpenMS
268
269// Hash function specialization for PeptideIdentification
270namespace std
271{
289 template<>
290 struct hash<OpenMS::PeptideIdentification>
291 {
292 std::size_t operator()(const OpenMS::PeptideIdentification& pi) const noexcept
293 {
294 // Start with MetaInfoInterface hash (includes significance_threshold, experiment_label, base_name)
295 std::size_t seed = std::hash<OpenMS::MetaInfoInterface>{}(pi);
296
297 // Hash identifier
298 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(pi.getIdentifier()));
299
300 // Hash all peptide hits
301 for (const auto& hit : pi.getHits())
302 {
303 OpenMS::hash_combine(seed, std::hash<OpenMS::PeptideHit>{}(hit));
304 }
305
306 // Hash score type
307 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(pi.getScoreType()));
308
309 // Hash higher_score_better
310 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(pi.isHigherScoreBetter())));
311
312 // Hash mz (with NaN handling - NaN values hash to same value)
313 if (pi.hasMZ())
314 {
315 OpenMS::hash_combine(seed, OpenMS::hash_float(pi.getMZ()));
316 }
317 else
318 {
319 // Hash a sentinel value for NaN (consistent with operator== which treats NaN==NaN as true)
320 OpenMS::hash_combine(seed, OpenMS::hash_int(0xDEADBEEF));
321 }
322
323 // Hash rt (with NaN handling)
324 if (pi.hasRT())
325 {
326 OpenMS::hash_combine(seed, OpenMS::hash_float(pi.getRT()));
327 }
328 else
329 {
330 // Hash a different sentinel value for NaN RT
331 OpenMS::hash_combine(seed, OpenMS::hash_int(0xCAFEBABE));
332 }
333
334 return seed;
335 }
336 };
337} // namespace std
A container for consensus elements.
Definition ConsensusMap.h:68
Two-way mapping from ms-run-path to protID|pepID-identifier.
Definition IdentifierMSRunMapper.h:51
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:66
PeptideHit HitType
Hit type definition.
Definition PeptideIdentification.h:70
PeptideIdentification()
default constructor
virtual ~PeptideIdentification() noexcept
destructor
A more convenient string class.
Definition String.h:34
Utility class for handling Universal Spectrum Identifiers (USI).
Definition USI.h:54
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
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:292