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 std::string& id);
140
142 const std::string& getId() const;
143
151 void setFullId(const std::string& full_id = "");
152
154
163 const std::string& getFullId() const;
164
166 void setUniModRecordId(const Int& id);
167
169 const Int& getUniModRecordId() const;
170
172 const std::string getUniModAccession() const;
173
175 void setPSIMODAccession(const std::string& id);
176
178 const std::string& getPSIMODAccession() const;
179
181 void setFullName(const std::string& full_name);
182
184 const std::string& getFullName() const;
185
187 void setName(const std::string& name);
188
190 const std::string& getName() const;
191
198
206 void setTermSpecificity(const std::string& name);
207
210
217 std::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 std::string& classification);
234
237
240
242 std::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 std::string& composition);
270
272 const std::string& getFormula() const;
273
275 void setDiffFormula(const EmpiricalFormula& diff_formula);
276
279
281 void setSynonyms(const std::set<std::string>& synonyms);
282
284 void addSynonym(const std::string& synonym);
285
287 const std::set<std::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
337 static const ResidueModification* createUnknownFromMassString(const std::string& mod,
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
371 std::string toString() const;
372
375 static std::string getDiffMonoMassString(const double diff_mono_mass);
376
378 static std::string getDiffMonoMassWithBracket(const double diff_mono_mass);
379
381 static std::string getMonoMassWithBracket(const double mono_mass);
382
383protected:
384 std::string id_;
385
386 std::string full_id_;
387
389
390 // The UniMod record id (an integer)
392
393 std::string full_name_;
394
395 std::string name_;
396
398
400
402
404
406
408
410
411 std::string formula_;
412
414
415 std::set<std::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<std::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:62
Representation of a modification on an amino acid residue.
Definition ResidueModification.h:55
const std::string & getPSIMODAccession() const
returns the PSI-MOD accession if available
double average_mass_
Definition ResidueModification.h:403
void setSourceClassification(const std::string &classification)
classification as defined by the PSI-MOD
void setFullId(const std::string &full_id="")
Sets the full identifier (Unimod Accession + origin, if available)
void setDiffFormula(const EmpiricalFormula &diff_formula)
sets diff formula (no masses will be changed)
std::string toString() const
const EmpiricalFormula & getDiffFormula() const
returns the diff formula if one was set
static const ResidueModification * createUnknownFromMassString(const std::string &mod, const double mass, const bool delta_mass, const TermSpecificity specificity, const Residue *residue=nullptr)
ResidueModification & operator=(ResidueModification &&) &=default
Move assignment operator.
ResidueModification(ResidueModification &&)=default
Move constructor.
void setId(const std::string &id)
set the identifier of the modification
static std::string getDiffMonoMassWithBracket(const double diff_mono_mass)
return a string of the form '[+>mass<] (the '+' might be a '-', if mass is negative).
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::set< std::string > synonyms_
Definition ResidueModification.h:415
const std::string getUniModAccession() const
returns the unimod accession if available
std::vector< double > getNeutralLossAverageMasses() const
returns the neutral loss average weight
void setSynonyms(const std::set< std::string > &synonyms)
sets the synonyms of that modification
bool hasNeutralLoss() const
returns true if a neutral loss formula is set
const std::string & getId() const
returns the identifier of the modification
const std::string & getName() const
returns the PSI-MS-label if available; e.g. Mascot uses this name
void setSourceClassification(SourceClassification classification)
sets the source classification
void setDiffAverageMass(double mass)
set the difference average mass
std::string full_name_
Definition ResidueModification.h:393
Int unimod_record_id_
Definition ResidueModification.h:391
std::string name_
Definition ResidueModification.h:395
void setNeutralLossMonoMasses(std::vector< double > mono_masses)
set the neutral loss mono weight
void addSynonym(const std::string &synonym)
adds a synonym to the unique list
std::string full_id_
Definition ResidueModification.h:386
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
double diff_average_mass_
Definition ResidueModification.h:407
TermSpecificity
Position where the modification is allowed to occur.
Definition ResidueModification.h:74
void setFormula(const std::string &composition)
set the formula (no masses will be changed)
void setPSIMODAccession(const std::string &id)
set the MOD:XXXXX accession of PSI-MOD
static std::string getDiffMonoMassString(const double diff_mono_mass)
void setDiffMonoMass(double mass)
sets the difference monoisotopic mass
TermSpecificity term_spec_
Definition ResidueModification.h:397
const std::string & getFullName() const
returns the full name of the modification
void setNeutralLossDiffFormulas(const std::vector< EmpiricalFormula > &diff_formulas)
sets the neutral loss formula
ResidueModification()
Default constructor.
bool operator<(const ResidueModification &modification) const
less operator
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
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
double diff_mono_mass_
Definition ResidueModification.h:409
void setName(const std::string &name)
sets the name of modification
std::vector< double > getNeutralLossMonoMasses() const
returns the neutral loss mono weight
std::string getSourceClassificationName(SourceClassification classification=NUMBER_OF_SOURCE_CLASSIFICATIONS) const
returns the classification
void setUniModRecordId(const Int &id)
sets the unimod record id
const std::string & getFullId() const
returns the full identifier of the mod (Unimod accession + origin, if available)
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::string psi_mod_accession_
Definition ResidueModification.h:388
double getMonoMass() const
return the monoisotopic mass, or 0.0 if not set
std::string formula_
Definition ResidueModification.h:411
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,...
void setFullName(const std::string &full_name)
sets the full name of the modification; must NOT contain the origin (or . for terminals!...
double getAverageMass() const
returns the average mass if set
std::string id_
Definition ResidueModification.h:384
static std::string getMonoMassWithBracket(const double mono_mass)
return a string of the form '[>mass<]
const std::set< std::string > & getSynonyms() const
returns the set of synonyms
void setTermSpecificity(const std::string &name)
Sets the terminal specificity using a name.
void setTermSpecificity(TermSpecificity term_spec)
Sets the term specificity.
EmpiricalFormula diff_formula_
Definition ResidueModification.h:413
std::string getTermSpecificityName(TermSpecificity term_spec=NUMBER_OF_TERM_SPECIFICITY) const
Returns the name of the terminal specificity.
double getDiffAverageMass() const
returns the difference average mass, or 0.0 if not set
const Int & getUniModRecordId() const
gets the unimod record id
const std::string & getFormula() const
returns the chemical formula if set
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:41
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