OpenMS
Loading...
Searching...
No Matches
Compomer.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: Chris Bielow $
7// --------------------------------------------------------------------------
8
9#pragma once
10
15#include <OpenMS/OpenMSConfig.h>
16
17#include <functional>
18#include <map>
19#include <vector>
20
21namespace OpenMS
22{
23
24 class String;
25
50 class OPENMS_DLLAPI Compomer
51 {
52public:
60 enum SIDE {LEFT, RIGHT, BOTH};
61
63 typedef std::map<String, Adduct> CompomerSide;
64
72 typedef std::vector<CompomerSide> CompomerComponents;
73
80
88 Compomer(Int net_charge, double mass, double log_p);
89
95 Compomer(const Compomer& p);
96
103 Compomer& operator=(const Compomer& source);
104
114 void add(const Adduct& a, UInt side);
115
127 bool isConflicting(const Compomer& cmp, UInt side_this, UInt side_other) const;
128
134 void setID(const Size& id);
135
141 const Size& getID() const;
142
149
157 const Int& getNetCharge() const;
158
164 const double& getMass() const;
165
171 const Int& getPositiveCharges() const;
172
178 const Int& getNegativeCharges() const;
179
187 const double& getLogP() const;
188
194 const double& getRTShift() const;
195
202
210
218 bool isSingleAdduct(Adduct& a, const UInt side) const;
219
226 Compomer removeAdduct(const Adduct& a) const;
227
234 Compomer removeAdduct(const Adduct& a, const UInt side) const;
235
242 StringList getLabels(const UInt side) const;
243
244
251 void add(const CompomerSide& add_side, UInt side);
252
265 friend OPENMS_DLLAPI bool operator<(const Compomer& c1, const Compomer& c2);
266
274 friend OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const Compomer& cmp);
275
283 friend OPENMS_DLLAPI bool operator==(const Compomer& a, const Compomer& b);
284
285private:
286
289 double mass_;
292 double log_p_;
293 double rt_shift_;
295
296 }; // \Compomer
297
298} // namespace OpenMS
299
300// Hash function specialization for Compomer
301// Note: Only hash fields used in operator== (cmp_, net_charge_, mass_, pos_charges_, neg_charges_, log_p_, id_)
302// Do NOT hash rt_shift_ as it is not compared in operator==
303namespace std
304{
305 template<>
306 struct hash<OpenMS::Compomer>
307 {
308 std::size_t operator()(const OpenMS::Compomer& c) const noexcept
309 {
310 std::size_t seed = OpenMS::hash_int(c.getNetCharge());
311 OpenMS::hash_combine(seed, OpenMS::hash_float(c.getMass()));
312 OpenMS::hash_combine(seed, OpenMS::hash_int(c.getPositiveCharges()));
313 OpenMS::hash_combine(seed, OpenMS::hash_int(c.getNegativeCharges()));
314 OpenMS::hash_combine(seed, OpenMS::hash_float(c.getLogP()));
315 OpenMS::hash_combine(seed, OpenMS::hash_int(c.getID()));
316
317 // Hash the compomer components (vector<map<String, Adduct>>)
318 const auto& components = c.getComponent();
319 OpenMS::hash_combine(seed, OpenMS::hash_int(components.size()));
320 for (const auto& side : components)
321 {
322 OpenMS::hash_combine(seed, OpenMS::hash_int(side.size()));
323 for (const auto& [key, adduct] : side)
324 {
326 OpenMS::hash_combine(seed, std::hash<OpenMS::Adduct>{}(adduct));
327 }
328 }
329 return seed;
330 }
331 };
332} // namespace std
333
Definition Adduct.h:22
Holds information on an edge connecting two features from a (putative) charge ladder.
Definition Compomer.h:51
bool isConflicting(const Compomer &cmp, UInt side_this, UInt side_other) const
Determines if two compomers conflict with each other.
const double & getRTShift() const
Get the expected retention time shift caused by this compomer.
StringList getLabels(const UInt side) const
Returns the adduct labels from side (LEFT or RIGHT)
const Int & getNetCharge() const
Get the net charge of this compomer.
double mass_
Net mass (right - left)
Definition Compomer.h:289
std::map< String, Adduct > CompomerSide
Type definition for one side of a compomer (maps adduct labels to Adduct objects)
Definition Compomer.h:63
double log_p_
Log probability of this adduct combination.
Definition Compomer.h:292
Compomer(const Compomer &p)
Copy constructor.
void add(const Adduct &a, UInt side)
Add an adduct to a specific side of the compomer.
CompomerComponents cmp_
Adducts of left and right side.
Definition Compomer.h:287
Int neg_charges_
Sum of negative charges.
Definition Compomer.h:291
Compomer removeAdduct(const Adduct &a) const
Remove all adducts of type a.
Compomer(Int net_charge, double mass, double log_p)
Constructor with net-charge, mass, and probability.
const double & getMass() const
Get the total mass difference represented by this compomer.
const Int & getPositiveCharges() const
Get the sum of positive charges in this compomer.
String getAdductsAsString() const
Get a string representation of all adducts in this compomer.
friend bool operator==(const Compomer &a, const Compomer &b)
Equality comparison operator.
const Size & getID() const
Get the unique identifier of this compomer.
bool isSingleAdduct(Adduct &a, const UInt side) const
Check if the compomer contains only a single adduct on the specified side.
Compomer & operator=(const Compomer &source)
Assignment Operator.
Int pos_charges_
Sum of positive charges.
Definition Compomer.h:290
const CompomerComponents & getComponent() const
Get both sides (left and right) of this compomer.
double rt_shift_
Expected net RT shift (-shift_leftside + shift_rightside)
Definition Compomer.h:293
String getAdductsAsString(UInt side) const
Get a string representation of adducts on a specific side.
Int net_charge_
Net charge (right - left)
Definition Compomer.h:288
void add(const CompomerSide &add_side, UInt side)
Add a complete set of adducts to a specific side of the compomer.
Compomer removeAdduct(const Adduct &a, const UInt side) const
Remove all adducts of type a from side (LEFT or RIGHT)
friend std::ostream & operator<<(std::ostream &os, const Compomer &cmp)
Output stream operator for printing compomer contents.
std::vector< CompomerSide > CompomerComponents
Container for both sides of a compomer.
Definition Compomer.h:72
const double & getLogP() const
Get the log probability of this adduct combination.
friend bool operator<(const Compomer &c1, const Compomer &c2)
Comparison operator for sorting compomers.
void setID(const Size &id)
Set a unique identifier for this compomer.
Size id_
Unique identifier for this compomer.
Definition Compomer.h:294
const Int & getNegativeCharges() const
Get the sum of negative charges in this compomer.
SIDE
Enumeration for specifying which side of the compomer to operate on.
Definition Compomer.h:60
Compomer()
Default Constructor.
A more convenient string class.
Definition String.h:34
int Int
Signed integer type.
Definition Types.h:72
unsigned int UInt
Unsigned integer type.
Definition Types.h:64
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
@ BOTH
combine COMPACT and ONE_BY_ONE
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::Compomer &c) const noexcept
Definition Compomer.h:308