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 std::string& getScoreType() const;
127 void setScoreType(const std::string& type);
128
130 bool isHigherScoreBetter() const;
132 void setHigherScoreBetter(bool value);
133
135 const std::string& getIdentifier() const;
137 void setIdentifier(const std::string& id);
138
140 const std::string getExperimentLabel() const;
142 void setExperimentLabel(const std::string& type);
143
146 // TODO make a mandatory data member, add to idXML schema, think about storing the
147 // extracted spectrum "number" only!
148 std::string getSpectrumReference() const;
151 void setSpectrumReference(const std::string& ref);
152
153 // Returns a higher or lower comparator based on @p higher_score_better_
154 static std::function<bool(const PeptideHit&, const PeptideHit&)> getScoreComparator(bool higher_score_better);
155
161 void sort();
162
164 bool empty() const;
165
167 static std::vector<PeptideHit> getReferencingHits(const std::vector<PeptideHit>&, const std::set<std::string>& accession);
168
177 static std::multimap<std::string, std::pair<Size, Size>> buildUIDsFromAllPepIDs(const ConsensusMap &cmap);
178
196 static std::string buildUIDFromPepID(const PeptideIdentification& pep_id,
197 const IdentifierMSRunMapper& mapping);
198
222 USI buildUSI(const std::string& ms_run_name,
223 const std::string& dataset_id = "local",
224 bool include_interpretation = false) const;
225
249 USI buildUSI(const IdentifierMSRunMapper& mapping,
250 const std::string& dataset_id = "local",
251 bool include_interpretation = false) const;
252
253protected:
254 std::string id_;
255 std::vector<PeptideHit> hits_;
256 std::string score_type_;
257 bool higher_score_better_;
258 double mz_;
259 double rt_;
260 };
261
262} //namespace OpenMS
263
264// Hash function specialization for PeptideIdentification
265namespace std
266{
283 template<>
284 struct hash<OpenMS::PeptideIdentification>
285 {
286 std::size_t operator()(const OpenMS::PeptideIdentification& pi) const noexcept
287 {
288 // Start with MetaInfoInterface hash (includes significance_threshold, experiment_label, base_name)
289 std::size_t seed = std::hash<OpenMS::MetaInfoInterface>{}(pi);
290
291 // Hash identifier
292 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(pi.getIdentifier()));
293
294 // Hash all peptide hits
295 for (const auto& hit : pi.getHits())
296 {
297 OpenMS::hash_combine(seed, std::hash<OpenMS::PeptideHit>{}(hit));
298 }
299
300 // Hash score type
301 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(pi.getScoreType()));
302
303 // Hash higher_score_better
304 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(pi.isHigherScoreBetter())));
305
306 // Hash mz (with NaN handling - NaN values hash to same value)
307 if (pi.hasMZ())
308 {
309 OpenMS::hash_combine(seed, OpenMS::hash_float(pi.getMZ()));
310 }
311 else
312 {
313 // Hash a sentinel value for NaN (consistent with operator== which treats NaN==NaN as true)
314 OpenMS::hash_combine(seed, OpenMS::hash_int(0xDEADBEEF));
315 }
316
317 // Hash rt (with NaN handling)
318 if (pi.hasRT())
319 {
320 OpenMS::hash_combine(seed, OpenMS::hash_float(pi.getRT()));
321 }
322 else
323 {
324 // Hash a different sentinel value for NaN RT
325 OpenMS::hash_combine(seed, OpenMS::hash_int(0xCAFEBABE));
326 }
327
328 return seed;
329 }
330 };
331} // namespace std
A container for consensus elements.
Definition ConsensusMap.h:67
Two-way mapping from ms-run-path to protID|pepID-identifier.
Definition IdentifierMSRunMapper.h:51
Definition MzIdentMLHandler.h:136
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition MetaInfoInterface.h:35
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
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:286