OpenMS
Loading...
Searching...
No Matches
ResidueModification.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: Andreas Bertsch $
7// --------------------------------------------------------------------------
8//
9
10#pragma once
11
15
16#include <functional>
17#include <set>
18
19namespace OpenMS
20{
21 // forward declaration
22 class Residue;
23
54 class OPENMS_DLLAPI ResidueModification
55 {
56public:
57
74 {
75 ANYWHERE = 0,
76 C_TERM = 1,
77 N_TERM = 2,
78 PROTEIN_C_TERM = 3,
79 PROTEIN_N_TERM = 4,
80 NUMBER_OF_TERM_SPECIFICITY
81 };
82
106
110
113
116
119
123
127
130
134
139 void setId(const String& id);
140
142 const String& getId() const;
143
151 void setFullId(const String& full_id = "");
152
154
163 const String& getFullId() const;
164
166 void setUniModRecordId(const Int& id);
167
169 const Int& getUniModRecordId() const;
170
173
175 void setPSIMODAccession(const String& id);
176
179
181 void setFullName(const String& full_name);
182
184 const String& getFullName() const;
185
187 void setName(const String& name);
188
190 const String& getName() const;
191
198
206 void setTermSpecificity(const String& name);
207
210
217 String getTermSpecificityName(TermSpecificity term_spec = NUMBER_OF_TERM_SPECIFICITY) const;
218
227 void setOrigin(char origin);
228
230 char getOrigin() const;
231
233 void setSourceClassification(const String& classification);
234
237
240
242 String getSourceClassificationName(SourceClassification classification = NUMBER_OF_SOURCE_CLASSIFICATIONS) const;
243
245 void setAverageMass(double mass);
246
248 double getAverageMass() const;
249
251 void setMonoMass(double mass);
252
254 double getMonoMass() const;
255
257 void setDiffAverageMass(double mass);
258
260 double getDiffAverageMass() const;
261
263 void setDiffMonoMass(double mass);
264
266 double getDiffMonoMass() const;
267
269 void setFormula(const String& composition);
270
272 const String& getFormula() const;
273
275 void setDiffFormula(const EmpiricalFormula& diff_formula);
276
279
281 void setSynonyms(const std::set<String>& synonyms);
282
284 void addSynonym(const String& synonym);
285
287 const std::set<String>& getSynonyms() const;
288
290 void setNeutralLossDiffFormulas(const std::vector<EmpiricalFormula>& diff_formulas);
291
293 const std::vector<EmpiricalFormula>& getNeutralLossDiffFormulas() const;
294
296 void setNeutralLossMonoMasses(std::vector<double> mono_masses);
297
299 std::vector<double> getNeutralLossMonoMasses() const;
300
302 void setNeutralLossAverageMasses(std::vector<double> average_masses);
303
305 std::vector<double> getNeutralLossAverageMasses() const;
307
312 bool hasNeutralLoss() const;
313
315 bool isUserDefined() const;
316
318 bool operator==(const ResidueModification& modification) const;
319
321 bool operator!=(const ResidueModification& modification) const;
322
324 bool operator<(const ResidueModification& modification) const;
325
327
330
338 const double mass,
339 const bool delta_mass,
340 const TermSpecificity specificity,
341 const Residue* residue = nullptr);
342
360 const std::set<const ResidueModification*>& addons,
361 bool allow_unknown_masses = false,
362 const Residue* residue = nullptr);
363
372
375 static String getDiffMonoMassString(const double diff_mono_mass);
376
378 static String getDiffMonoMassWithBracket(const double diff_mono_mass);
379
381 static String getMonoMassWithBracket(const double mono_mass);
382
383protected:
385
387
389
390 // The UniMod record id (an integer)
392
394
396
398
400
402
404
406
408
410
412
414
415 std::set<String> synonyms_;
416
417 std::vector<EmpiricalFormula> neutral_loss_diff_formulas_;
418
419 std::vector<double> neutral_loss_mono_masses_;
420
421 std::vector<double> neutral_loss_average_masses_;
422 };
423} // namespace OpenMS
424
425// Hash function specialization for ResidueModification
426// Placed in std namespace to allow use with std::unordered_map/set
427namespace std
428{
439 template<>
440 struct hash<OpenMS::ResidueModification>
441 {
442 std::size_t operator()(const OpenMS::ResidueModification& mod) const noexcept
443 {
444 // Hash string fields
445 std::size_t seed = OpenMS::fnv1a_hash_string(mod.getId());
446 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(mod.getFullId()));
447 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(mod.getPSIMODAccession()));
448 OpenMS::hash_combine(seed, OpenMS::hash_int(mod.getUniModRecordId()));
449 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(mod.getFullName()));
451
452 // Hash enum fields (as integers)
453 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(mod.getTermSpecificity())));
454 OpenMS::hash_combine(seed, OpenMS::hash_char(mod.getOrigin()));
455 OpenMS::hash_combine(seed, OpenMS::hash_int(static_cast<int>(mod.getSourceClassification())));
456
457 // Hash mass fields
458 OpenMS::hash_combine(seed, OpenMS::hash_float(mod.getAverageMass()));
459 OpenMS::hash_combine(seed, OpenMS::hash_float(mod.getMonoMass()));
460 OpenMS::hash_combine(seed, OpenMS::hash_float(mod.getDiffAverageMass()));
461 OpenMS::hash_combine(seed, OpenMS::hash_float(mod.getDiffMonoMass()));
462
463 // Hash formula fields
464 OpenMS::hash_combine(seed, OpenMS::fnv1a_hash_string(mod.getFormula()));
465 OpenMS::hash_combine(seed, std::hash<OpenMS::EmpiricalFormula>{}(mod.getDiffFormula()));
466
467 // Hash synonyms (set<String>)
468 const auto& synonyms = mod.getSynonyms();
469 OpenMS::hash_combine(seed, OpenMS::hash_int(synonyms.size()));
470 for (const auto& syn : synonyms)
471 {
473 }
474
475 // Hash neutral loss diff formulas (vector<EmpiricalFormula>)
476 const auto& nl_formulas = mod.getNeutralLossDiffFormulas();
477 OpenMS::hash_combine(seed, OpenMS::hash_int(nl_formulas.size()));
478 for (const auto& nlf : nl_formulas)
479 {
480 OpenMS::hash_combine(seed, std::hash<OpenMS::EmpiricalFormula>{}(nlf));
481 }
482
483 // Hash neutral loss mono masses (vector<double>)
484 const auto& nl_mono = mod.getNeutralLossMonoMasses();
485 OpenMS::hash_combine(seed, OpenMS::hash_int(nl_mono.size()));
486 for (double mass : nl_mono)
487 {
489 }
490
491 // Hash neutral loss average masses (vector<double>)
492 const auto& nl_avg = mod.getNeutralLossAverageMasses();
493 OpenMS::hash_combine(seed, OpenMS::hash_int(nl_avg.size()));
494 for (double mass : nl_avg)
495 {
497 }
498
499 return seed;
500 }
501 };
502} // namespace std
Representation of an empirical formula.
Definition EmpiricalFormula.h:63
Representation of a modification on an amino acid residue.
Definition ResidueModification.h:55
static String getDiffMonoMassString(const double diff_mono_mass)
double average_mass_
Definition ResidueModification.h:403
const String & getFormula() const
returns the chemical formula if set
void setDiffFormula(const EmpiricalFormula &diff_formula)
sets diff formula (no masses will be changed)
const EmpiricalFormula & getDiffFormula() const
returns the diff formula if one was set
ResidueModification & operator=(ResidueModification &&) &=default
Move assignment operator.
ResidueModification(ResidueModification &&)=default
Move constructor.
std::vector< EmpiricalFormula > neutral_loss_diff_formulas_
Definition ResidueModification.h:417
SourceClassification getSourceClassification() const
returns the source classification, if none was set, it is unspecific
std::vector< double > getNeutralLossAverageMasses() const
returns the neutral loss average weight
const String & getFullId() const
returns the full identifier of the mod (Unimod accession + origin, if available)
bool hasNeutralLoss() const
returns true if a neutral loss formula is set
void setSourceClassification(SourceClassification classification)
sets the source classification
void setDiffAverageMass(double mass)
set the difference average mass
Int unimod_record_id_
Definition ResidueModification.h:391
String name_
Definition ResidueModification.h:395
static String getDiffMonoMassWithBracket(const double diff_mono_mass)
return a string of the form '[+>mass<] (the '+' might be a '-', if mass is negative).
String formula_
Definition ResidueModification.h:411
void setNeutralLossMonoMasses(std::vector< double > mono_masses)
set the neutral loss mono weight
std::vector< double > neutral_loss_average_masses_
Definition ResidueModification.h:421
std::vector< double > neutral_loss_mono_masses_
Definition ResidueModification.h:419
double mono_mass_
Definition ResidueModification.h:405
void setPSIMODAccession(const String &id)
set the MOD:XXXXX accession of PSI-MOD
String psi_mod_accession_
Definition ResidueModification.h:388
double diff_average_mass_
Definition ResidueModification.h:407
void setSynonyms(const std::set< String > &synonyms)
sets the synonyms of that modification
TermSpecificity
Position where the modification is allowed to occur.
Definition ResidueModification.h:74
void setDiffMonoMass(double mass)
sets the difference monoisotopic mass
TermSpecificity term_spec_
Definition ResidueModification.h:397
void setNeutralLossDiffFormulas(const std::vector< EmpiricalFormula > &diff_formulas)
sets the neutral loss formula
ResidueModification()
Default constructor.
bool operator<(const ResidueModification &modification) const
less operator
const std::set< String > & getSynonyms() const
returns the set of synonyms
void setName(const String &name)
sets the name of modification
String full_name_
Definition ResidueModification.h:393
ResidueModification & operator=(const ResidueModification &)=default
Assignment operator.
void setAverageMass(double mass)
sets the average mass
ResidueModification(const ResidueModification &)=default
Copy constructor.
bool operator!=(const ResidueModification &modification) const
inequality operator
double getDiffMonoMass() const
returns the diff monoisotopic mass, or 0.0 if not set
SourceClassification
Classification of the modification.
Definition ResidueModification.h:86
@ NATURAL
A natural modification.
Definition ResidueModification.h:89
@ POSTTRANSLATIONAL
A post-translational modification.
Definition ResidueModification.h:90
@ COTRANSLATIONAL
A co-translational modification.
Definition ResidueModification.h:100
@ OTHER_GLYCOSYLATION
Other glycosylation (i.e. neither N nor O-linked)
Definition ResidueModification.h:95
@ NLINKED_GLYCOSYLATION
N-linked glycosylation.
Definition ResidueModification.h:96
@ UNKNOWN
An unknown modification.
Definition ResidueModification.h:102
@ HYPOTHETICAL
A hypothetical modification.
Definition ResidueModification.h:88
@ PRETRANSLATIONAL
A pre-translational modification.
Definition ResidueModification.h:94
@ CHEMICAL_DERIVATIVE
A chemical derivative.
Definition ResidueModification.h:92
@ AA_SUBSTITUTION
An amino acid substitution that presents like a modification.
Definition ResidueModification.h:97
@ MULTIPLE
A combination of multiple modifications.
Definition ResidueModification.h:91
@ ISOTOPIC_LABEL
A chemical label (artificial)
Definition ResidueModification.h:93
@ OLINKED_GLYCOSYLATION
A O-linked glycosylation.
Definition ResidueModification.h:101
@ OTHER
Other modification.
Definition ResidueModification.h:98
@ NONSTANDARD_RESIDUE
A non-standard amino acid.
Definition ResidueModification.h:99
TermSpecificity getTermSpecificity() const
returns terminal specificity
String full_id_
Definition ResidueModification.h:386
SourceClassification classification_
Definition ResidueModification.h:401
const std::vector< EmpiricalFormula > & getNeutralLossDiffFormulas() const
returns the neutral loss diff formula (if available)
char origin_
Definition ResidueModification.h:399
const String & getName() const
returns the PSI-MS-label if available; e.g. Mascot uses this name
void setTermSpecificity(const String &name)
Sets the terminal specificity using a name.
void setFullId(const String &full_id="")
Sets the full identifier (Unimod Accession + origin, if available)
double diff_mono_mass_
Definition ResidueModification.h:409
std::vector< double > getNeutralLossMonoMasses() const
returns the neutral loss mono weight
void setUniModRecordId(const Int &id)
sets the unimod record id
static String getMonoMassWithBracket(const double mono_mass)
return a string of the form '[>mass<]
void setFormula(const String &composition)
set the formula (no masses will be changed)
bool isUserDefined() const
returns true if it is a user-defined modification (empty id)
virtual ~ResidueModification()
Destructor.
char getOrigin() const
Returns the origin (i.e. modified amino acid)
std::set< String > synonyms_
Definition ResidueModification.h:415
void setSourceClassification(const String &classification)
classification as defined by the PSI-MOD
const String getUniModAccession() const
returns the unimod accession if available
const String & getId() const
returns the identifier of the modification
double getMonoMass() const
return the monoisotopic mass, or 0.0 if not set
void setOrigin(char origin)
Sets the origin (i.e. modified amino acid)
bool operator==(const ResidueModification &modification) const
equality operator
static const ResidueModification * combineMods(const ResidueModification *base, const std::set< const ResidueModification * > &addons, bool allow_unknown_masses=false, const Residue *residue=nullptr)
Merge a set of mods to a given modification (usually the one which is already present,...
String getTermSpecificityName(TermSpecificity term_spec=NUMBER_OF_TERM_SPECIFICITY) const
Returns the name of the terminal specificity.
double getAverageMass() const
returns the average mass if set
const String & getPSIMODAccession() const
returns the PSI-MOD accession if available
void addSynonym(const String &synonym)
adds a synonym to the unique list
void setFullName(const String &full_name)
sets the full name of the modification; must NOT contain the origin (or . for terminals!...
String id_
Definition ResidueModification.h:384
static const ResidueModification * createUnknownFromMassString(const String &mod, const double mass, const bool delta_mass, const TermSpecificity specificity, const Residue *residue=nullptr)
void setTermSpecificity(TermSpecificity term_spec)
Sets the term specificity.
void setId(const String &id)
set the identifier of the modification
EmpiricalFormula diff_formula_
Definition ResidueModification.h:413
String getSourceClassificationName(SourceClassification classification=NUMBER_OF_SOURCE_CLASSIFICATIONS) const
returns the classification
double getDiffAverageMass() const
returns the difference average mass, or 0.0 if not set
const Int & getUniModRecordId() const
gets the unimod record id
const String & getFullName() const
returns the full name of the modification
void setNeutralLossAverageMasses(std::vector< double > average_masses)
set the neutral loss average weight
void setMonoMass(double mass)
sets the monoisotopic mass (this must include the weight of the residue itself!)
Representation of an amino acid residue.
Definition Residue.h:40
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_char(char c) noexcept
Hash for a character.
Definition HashUtils.h:119
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::ResidueModification &mod) const noexcept
Definition ResidueModification.h:442