OpenMS
Loading...
Searching...
No Matches
Adduct.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: Chris Bielow $
6// $Authors: $
7// --------------------------------------------------------------------------
8
9#pragma once
10
11#include <OpenMS/OpenMSConfig.h>
15
16#include <functional>
17
18namespace OpenMS
19{
20
21 class OPENMS_DLLAPI Adduct
22 {
23public:
24
25 typedef std::vector<Adduct> AdductsType;
26
29
31 Adduct(Int charge);
32
34 Adduct(Int charge, Int amount, double singleMass, const String& formula, double log_prob, double rt_shift, const String& label = "");
35
37 Adduct operator*(const Int m) const;
39 Adduct operator+(const Adduct& rhs);
41 void operator+=(const Adduct& rhs);
42
43
45 friend OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const Adduct& a);
46
48 friend OPENMS_DLLAPI bool operator==(const Adduct& a, const Adduct& b);
49
51 const Int& getCharge() const;
52
53 void setCharge(const Int& charge);
54
55 const Int& getAmount() const;
56 void setAmount(const Int& amount);
57
58 const double& getSingleMass() const;
59 void setSingleMass(const double& singleMass);
60
61 const double& getLogProb() const;
62 void setLogProb(const double& log_prob);
63
64 const String& getFormula() const;
65 void setFormula(const String& formula);
66
67 const double& getRTShift() const;
68 const String& getLabel() const;
69
70 // convert a ion string to adduct string with charge information (eg. ion_string = "Na1", charge = "1" --> "[M+Na]+")
71 String toAdductString(const String& ion_string, const Int& charge);
72 //}
73
74private:
77 double singleMass_;
78 double log_prob_;
80 double rt_shift_;
82
83 String checkFormula_(const String& formula);
84
85 };
86
87} // namespace OpenMS
88
89// Hash function specialization for Adduct
90// Note: Only hash fields used in operator== (charge, amount, singleMass, log_prob, formula)
91// Do NOT hash rt_shift_ and label_ as they are not compared in operator==
92namespace std
93{
94 template<>
95 struct hash<OpenMS::Adduct>
96 {
97 std::size_t operator()(const OpenMS::Adduct& a) const noexcept
98 {
99 std::size_t seed = OpenMS::hash_int(a.getCharge());
100 OpenMS::hash_combine(seed, OpenMS::hash_int(a.getAmount()));
101 OpenMS::hash_combine(seed, OpenMS::hash_float(a.getSingleMass()));
102 OpenMS::hash_combine(seed, OpenMS::hash_float(a.getLogProb()));
103 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(a.getFormula()));
104 return seed;
105 }
106 };
107} // namespace std
108
109
Definition Adduct.h:22
const double & getRTShift() const
void setLogProb(const double &log_prob)
const String & getLabel() const
String checkFormula_(const String &formula)
const String & getFormula() const
Adduct operator+(const Adduct &rhs)
Add two adducts amount if they are equal (defined by equal formula)
Adduct()
Default C'tor.
double log_prob_
log probability of observing a single entity of this adduct
Definition Adduct.h:78
void setCharge(const Int &charge)
Adduct operator*(const Int m) const
Increase amount of this adduct by factor.
friend bool operator==(const Adduct &a, const Adduct &b)
Comparator.
String formula_
chemical formula (parsable by EmpiricalFormula)
Definition Adduct.h:79
void setAmount(const Int &amount)
const double & getSingleMass() const
String toAdductString(const String &ion_string, const Int &charge)
const Int & getAmount() const
const Int & getCharge() const
void operator+=(const Adduct &rhs)
Add other adducts amount to *this (equal formula required!)
Adduct(Int charge)
C'tor with initial charge.
String label_
Label for this adduct (can be used to indicate heavy labels)
Definition Adduct.h:81
double rt_shift_
RT shift induced by a single entity of this adduct (this is for adducts attached prior to ESI,...
Definition Adduct.h:80
friend std::ostream & operator<<(std::ostream &os, const Adduct &a)
Print the contents of an Adduct to a stream.
std::vector< Adduct > AdductsType
Definition Adduct.h:25
void setSingleMass(const double &singleMass)
Adduct(Int charge, Int amount, double singleMass, const String &formula, double log_prob, double rt_shift, const String &label="")
C'tor for all members.
void setFormula(const String &formula)
double singleMass_
mass of a single entity
Definition Adduct.h:77
const double & getLogProb() const
Int amount_
number of entities
Definition Adduct.h:76
Int charge_
usually +1
Definition Adduct.h:75
A more convenient string class.
Definition String.h:34
int Int
Signed integer type.
Definition Types.h:72
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::Adduct &a) const noexcept
Definition Adduct.h:97