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
49 class OPENMS_DLLAPI Compomer
50 {
51public:
59 enum SIDE {LEFT, RIGHT, BOTH};
60
62 typedef std::map<std::string, Adduct> CompomerSide;
63
71 typedef std::vector<CompomerSide> CompomerComponents;
72
79
87 Compomer(Int net_charge, double mass, double log_p);
88
94 Compomer(const Compomer& p);
95
102 Compomer& operator=(const Compomer& source);
103
113 void add(const Adduct& a, UInt side);
114
126 bool isConflicting(const Compomer& cmp, UInt side_this, UInt side_other) const;
127
133 void setID(const Size& id);
134
140 const Size& getID() const;
141
148
156 const Int& getNetCharge() const;
157
163 const double& getMass() const;
164
170 const Int& getPositiveCharges() const;
171
177 const Int& getNegativeCharges() const;
178
186 const double& getLogP() const;
187
193 const double& getRTShift() const;
194
200 std::string getAdductsAsString() const;
201
208 std::string getAdductsAsString(UInt side) const;
209
217 bool isSingleAdduct(Adduct& a, const UInt side) const;
218
225 Compomer removeAdduct(const Adduct& a) const;
226
233 Compomer removeAdduct(const Adduct& a, const UInt side) const;
234
241 StringList getLabels(const UInt side) const;
242
251 double getSideMass(const UInt side) const;
252
259 void add(const CompomerSide& add_side, UInt side);
260
273 friend OPENMS_DLLAPI bool operator<(const Compomer& c1, const Compomer& c2);
274
282 friend OPENMS_DLLAPI std::ostream& operator<<(std::ostream& os, const Compomer& cmp);
283
291 friend OPENMS_DLLAPI bool operator==(const Compomer& a, const Compomer& b);
292
293private:
294
297 double mass_;
300 double log_p_;
301 double rt_shift_;
303
304 }; // \Compomer
305
306} // namespace OpenMS
307
308// Hash function specialization for Compomer
309// Note: Only hash fields used in operator== (cmp_, net_charge_, mass_, pos_charges_, neg_charges_, log_p_, id_)
310// Do NOT hash rt_shift_ as it is not compared in operator==
311namespace std
312{
313 template<>
314 struct hash<OpenMS::Compomer>
315 {
316 std::size_t operator()(const OpenMS::Compomer& c) const noexcept
317 {
318 std::size_t seed = OpenMS::hash_int(c.getNetCharge());
319 OpenMS::hash_combine(seed, OpenMS::hash_float(c.getMass()));
320 OpenMS::hash_combine(seed, OpenMS::hash_int(c.getPositiveCharges()));
321 OpenMS::hash_combine(seed, OpenMS::hash_int(c.getNegativeCharges()));
322 OpenMS::hash_combine(seed, OpenMS::hash_float(c.getLogP()));
323 OpenMS::hash_combine(seed, OpenMS::hash_int(c.getID()));
324
325 // Hash the compomer components (vector<map<std::string, Adduct>>)
326 const auto& components = c.getComponent();
327 OpenMS::hash_combine(seed, OpenMS::hash_int(components.size()));
328 for (const auto& side : components)
329 {
330 OpenMS::hash_combine(seed, OpenMS::hash_int(side.size()));
331 for (const auto& [key, adduct] : side)
332 {
334 OpenMS::hash_combine(seed, std::hash<OpenMS::Adduct>{}(adduct));
335 }
336 }
337 return seed;
338 }
339 };
340} // namespace std
341
One elementary adduct contribution to a feature's ionization state.
Definition Adduct.h:87
Holds information on an edge connecting two features from a (putative) charge ladder.
Definition Compomer.h:50
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:297
double log_p_
Log probability of this adduct combination.
Definition Compomer.h:300
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:295
Int neg_charges_
Sum of negative charges.
Definition Compomer.h:299
Compomer removeAdduct(const Adduct &a) const
Remove all adducts of type a.
std::string getAdductsAsString() const
Get a string representation of all adducts in this compomer.
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.
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:298
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:301
Int net_charge_
Net charge (right - left)
Definition Compomer.h:296
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)
double getSideMass(const UInt side) const
Get total adduct mass on a specific side.
std::map< std::string, Adduct > CompomerSide
Type definition for one side of a compomer (maps adduct labels to Adduct objects)
Definition Compomer.h:62
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:71
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:302
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:59
Compomer()
Default Constructor.
std::string getAdductsAsString(UInt side) const
Get a string representation of adducts on a specific side.
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< std::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:316