1
// -*- mode: C++; tab-width: 2; -*-
4
// --------------------------------------------------------------------------
5
// OpenMS Mass Spectrometry Framework
6
// --------------------------------------------------------------------------
7
// Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
9
// This library is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU Lesser General Public
11
// License as published by the Free Software Foundation; either
12
// version 2.1 of the License, or (at your option) any later version.
14
// This library is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
// Lesser General Public License for more details.
19
// You should have received a copy of the GNU Lesser General Public
20
// License along with this library; if not, write to the Free Software
21
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
// --------------------------------------------------------------------------
24
// $Maintainer: Andreas Bertsch $
25
// $Authors: Andreas Bertsch $
26
// --------------------------------------------------------------------------
29
#include <OpenMS/CHEMISTRY/Residue.h>
30
#include <OpenMS/CHEMISTRY/ResidueModification.h>
31
#include <OpenMS/CHEMISTRY/ModificationsDB.h>
41
average_weight_(0.0f),
45
loss_average_weight_(0.0f),
46
loss_mono_weight_(0.0f),
53
Residue::Residue( const String& name,
54
const String& three_letter_code,
55
const String& one_letter_code,
56
const EmpiricalFormula& formula)
58
three_letter_code_(three_letter_code),
59
one_letter_code_(one_letter_code),
65
loss_average_weight_(0.0f),
66
loss_mono_weight_(0.0f),
76
internal_formula_ = formula_ - getInternalToFull();
80
Residue::Residue(const Residue& residue)
81
: name_(residue.name_),
82
short_name_(residue.short_name_),
83
synonyms_(residue.synonyms_),
84
three_letter_code_(residue.three_letter_code_),
85
one_letter_code_(residue.one_letter_code_),
86
formula_(residue.formula_),
87
internal_formula_(residue.internal_formula_),
88
average_weight_(residue.average_weight_),
89
mono_weight_(residue.mono_weight_),
90
is_modified_(residue.is_modified_),
91
pre_mod_name_(residue.pre_mod_name_),
92
modification_(residue.modification_),
93
loss_names_(residue.loss_names_),
94
loss_formulas_(residue.loss_formulas_),
95
NTerm_loss_names_(residue.NTerm_loss_names_),
96
NTerm_loss_formulas_(residue.NTerm_loss_formulas_),
97
loss_average_weight_(residue.loss_average_weight_),
98
loss_mono_weight_(residue.loss_mono_weight_),
99
low_mass_ions_(residue.low_mass_ions_),
103
gb_sc_(residue.gb_sc_),
104
gb_bb_l_(residue.gb_bb_l_),
105
gb_bb_r_(residue.gb_bb_r_),
106
residue_sets_(residue.residue_sets_)
114
Residue& Residue::operator = (const Residue& residue)
116
if (this != &residue)
118
name_ = residue.name_;
119
short_name_ = residue.short_name_;
120
synonyms_ = residue.synonyms_;
121
three_letter_code_ = residue.three_letter_code_;
122
one_letter_code_ = residue.one_letter_code_;
123
formula_ = residue.formula_;
124
internal_formula_ = residue.internal_formula_;
125
average_weight_ = residue.average_weight_;
126
mono_weight_ = residue.mono_weight_;
127
is_modified_ = residue.is_modified_;
128
pre_mod_name_ = residue.pre_mod_name_;
129
modification_ = residue.modification_;
130
loss_names_ = residue.loss_names_;
131
loss_formulas_ = residue.loss_formulas_;
132
NTerm_loss_names_ = residue.NTerm_loss_names_;
133
NTerm_loss_formulas_ = residue.NTerm_loss_formulas_;
134
loss_average_weight_ = residue.loss_average_weight_;
135
loss_mono_weight_ = residue.loss_mono_weight_;
136
low_mass_ions_ = residue.low_mass_ions_;
140
gb_sc_ = residue.gb_sc_;
141
gb_bb_l_ = residue.gb_bb_l_;
142
gb_bb_r_ = residue.gb_bb_r_;
143
residue_sets_ = residue.residue_sets_;
148
void Residue::setName(const String& name)
153
const String& Residue::getName() const
158
String Residue::getResidueTypeName(const Residue::ResidueType res_type)
165
case Residue::Internal:
167
case Residue::NTerminal:
169
case Residue::CTerminal:
177
case Residue::CIonMinusOne:
179
case Residue::CIonPlusOne:
181
case Residue::CIonPlusTwo:
189
case Residue::ZIonMinusOne:
191
case Residue::ZIonPlusOne:
193
case Residue::ZIonPlusTwo:
196
cerr << "Residue::getResidueTypeName: residue type has no name" << endl;
201
void Residue::setShortName(const String& short_name)
203
short_name_ = short_name;
206
const String& Residue::getShortName() const
211
void Residue::setSynonyms(const set<String>& synonyms)
213
synonyms_ = synonyms;
216
void Residue::addSynonym(const String& synonym)
218
synonyms_.insert(synonym);
221
const set<String>& Residue::getSynonyms() const
226
void Residue::setThreeLetterCode(const String& three_letter_code)
228
three_letter_code_ = three_letter_code;
231
const String& Residue::getThreeLetterCode() const
233
return three_letter_code_;
236
void Residue::setOneLetterCode(const String& one_letter_code)
238
one_letter_code_ = one_letter_code;
241
const String& Residue::getOneLetterCode() const
243
return one_letter_code_;
246
DoubleReal Residue::getPka() const
251
DoubleReal Residue::getPkb() const
256
DoubleReal Residue::getPkc() const
261
DoubleReal Residue::getPiValue() const
263
DoubleReal temp1 = 0.0;
264
DoubleReal temp2 = 0.0;
265
DoubleReal temp3 = 0.0;
272
if (temp3 >= 0 && temp3 < temp1)
274
pi = (temp3 + temp2) / 2;
276
else if (temp3 >= temp2)
278
pi = (temp1 + temp3) / 2;
282
pi = (temp1 + temp2) / 2;
288
void Residue::setPka(DoubleReal value)
293
void Residue::setPkb(DoubleReal value)
298
void Residue::setPkc(DoubleReal value)
303
void Residue::setLossFormulas(const vector<EmpiricalFormula>& loss_formulas)
305
loss_formulas_ = loss_formulas;
308
void Residue::addLossFormula(const EmpiricalFormula& loss_formula)
310
loss_formulas_.push_back(loss_formula);
313
const vector<EmpiricalFormula>& Residue::getLossFormulas() const
315
return loss_formulas_;
318
void Residue::addLossName(const String& name)
320
loss_names_.push_back(name);
323
void Residue::setLossNames(const vector<String>& names)
328
const vector<String>& Residue::getLossNames() const
334
void Residue::setNTermLossFormulas(const vector<EmpiricalFormula>& NTerm_loss_formulas)
336
NTerm_loss_formulas_ = NTerm_loss_formulas;
339
void Residue::addNTermLossFormula(const EmpiricalFormula& NTerm_loss_formula)
341
NTerm_loss_formulas_.push_back(NTerm_loss_formula);
344
const vector<EmpiricalFormula>& Residue::getNTermLossFormulas() const
346
return NTerm_loss_formulas_;
349
void Residue::addNTermLossName(const String& name)
351
NTerm_loss_names_.push_back(name);
354
void Residue::setNTermLossNames(const vector<String>& names)
356
NTerm_loss_names_ = names;
359
const vector<String>& Residue::getNTermLossNames() const
361
return NTerm_loss_names_;
365
void Residue::setFormula(const EmpiricalFormula& formula)
368
internal_formula_ = formula_ - getInternalToFull();
371
EmpiricalFormula Residue::getFormula(ResidueType res_type) const
378
return internal_formula_;
380
return formula_ - getNTerminalToFull();
382
return formula_ - getCTerminalToFull();
384
return formula_ - getBIonToFull();
386
return formula_ - getAIonToFull();
388
return formula_ - getCIonMinusOneToFull();
390
return formula_ - EmpiricalFormula("OH") + EmpiricalFormula("NH");
392
return formula_ + getXIonToFull();
394
return formula_ + getYIonToFull();
396
return formula_ - getZIonMinusOneToFull();
398
return formula_ - getZIonToFull();
400
return formula_ - getZIonPlusOneToFull();
402
return formula_ - getZIonPlusTwoToFull();
404
cerr << "Residue::getFormula: unknown ResidueType" << endl;
409
void Residue::setAverageWeight(DoubleReal weight)
411
average_weight_ = weight;
415
DoubleReal Residue::getAverageWeight(ResidueType res_type) const
420
return average_weight_;
422
return average_weight_ - getInternalToFullAverageWeight();
424
return average_weight_ - getNTerminalToFullAverageWeight();
426
return average_weight_ - getCTerminalToFullAverageWeight();
428
return average_weight_ - getBIonToFullAverageWeight();
430
return average_weight_ - getAIonToFullAverageWeight();
432
return average_weight_ - getCIonMinusOneToFullAverageWeight();
434
return average_weight_ - EmpiricalFormula("OH").getAverageWeight() + EmpiricalFormula("NH").getAverageWeight();
436
return average_weight_ - getCIonPlusOneToFullAverageWeight();
438
return average_weight_ - getCIonPlusTwoToFullAverageWeight();
440
return average_weight_ + getXIonToFullAverageWeight();
442
return average_weight_ + getYIonToFullAverageWeight();
444
return average_weight_ - getZIonMinusOneToFullAverageWeight();
446
return average_weight_ - getZIonToFullAverageWeight();
448
return average_weight_ - getZIonPlusOneToFullAverageWeight();
450
return average_weight_ - getZIonPlusTwoToFullAverageWeight();
452
cerr << "Residue::getAverageWeight: unknown ResidueType" << endl;
453
return average_weight_;
457
void Residue::setMonoWeight(DoubleReal weight)
459
mono_weight_ = weight;
463
DoubleReal Residue::getMonoWeight(ResidueType res_type) const
470
return mono_weight_ - getInternalToFullMonoWeight();
472
return mono_weight_ - getNTerminalToFullMonoWeight();
474
return mono_weight_ - getCTerminalToFullMonoWeight();
476
return mono_weight_ - getBIonToFullMonoWeight();
478
return mono_weight_ - getAIonToFullMonoWeight();
480
return mono_weight_ - getCIonMinusOneToFullMonoWeight();
482
return mono_weight_ - EmpiricalFormula("OH").getMonoWeight() + EmpiricalFormula("NH").getMonoWeight();
484
return mono_weight_ - getCIonPlusOneToFullMonoWeight();
486
return mono_weight_ - getCIonPlusTwoToFullMonoWeight();
488
return mono_weight_ + getXIonToFullMonoWeight();
490
return mono_weight_ + getYIonToFullMonoWeight();
492
return mono_weight_ - getZIonMinusOneToFullMonoWeight();
494
return mono_weight_ - getZIonToFullMonoWeight();
496
return mono_weight_ - getZIonPlusOneToFullMonoWeight();
498
return mono_weight_ - getZIonPlusTwoToFullMonoWeight();
500
cerr << "Residue::getMonoWeight: unknown ResidueType" << endl;
505
void Residue::setModification(const String& modification)
507
//modification_ = modification;
509
ModificationsDB* mod_db = ModificationsDB::getInstance();
510
ResidueModification mod = mod_db->getModification(one_letter_code_, modification, ResidueModification::ANYWHERE);
512
modification_ = mod.getId();
513
// update all the members
514
if (mod.getAverageMass() != 0)
516
average_weight_ = mod.getAverageMass();
518
if (mod.getMonoMass() != 0)
520
mono_weight_ = mod.getMonoMass();
523
bool updated_formula(false);
524
if (mod.getDiffFormula() != "")
526
updated_formula = true;
527
setFormula(getFormula() + mod.getDiffFormula());
529
if (mod.getFormula() != "" && !updated_formula)
531
updated_formula = true;
532
String formula = mod.getFormula();
533
formula.removeWhitespaces();
539
average_weight_ = formula_.getAverageWeight();
540
mono_weight_ = formula_.getMonoWeight();
544
if (mod.getAverageMass() != 0)
546
average_weight_ = mod.getAverageMass();
548
if (mod.getMonoMass() != 0)
550
mono_weight_ = mod.getMonoMass();
555
loss_formulas_.clear();
557
if (mod.hasNeutralLoss())
559
loss_formulas_.push_back(mod.getNeutralLossDiffFormula());
560
loss_names_.push_back(mod.getNeutralLossDiffFormula().getString());
566
const String& Residue::getModification() const
568
return modification_;
571
void Residue::setLowMassIons(const vector<EmpiricalFormula>& low_mass_ions)
573
low_mass_ions_ = low_mass_ions;
576
const vector<EmpiricalFormula>& Residue::getLowMassIons() const
578
return low_mass_ions_;
581
DoubleReal Residue::getBackboneBasicityRight() const
586
void Residue::setBackboneBasicityRight(DoubleReal gb_bb_r)
591
DoubleReal Residue::getBackboneBasicityLeft() const
596
void Residue::setBackboneBasicityLeft(DoubleReal gb_bb_l)
601
DoubleReal Residue::getSideChainBasicity() const
606
void Residue::setSideChainBasicity(DoubleReal gb_sc)
611
void Residue::setResidueSets(const set<String>& residue_sets)
613
residue_sets_ = residue_sets;
616
const set<String>& Residue::getResidueSets() const
618
return residue_sets_;
621
void Residue::addResidueSet(const String& residue_set)
623
residue_sets_.insert(residue_set);
626
bool Residue::isModified() const
631
bool Residue::hasNeutralLoss() const
633
return ( !loss_formulas_.empty() );
636
bool Residue::hasNTermNeutralLosses() const
638
return ( !NTerm_loss_formulas_.empty() );
641
bool Residue::operator == (const Residue& residue) const
643
return (name_ == residue.name_ &&
644
short_name_ == residue.short_name_ &&
645
synonyms_ == residue.synonyms_ &&
646
three_letter_code_ == residue.three_letter_code_ &&
647
one_letter_code_ == residue.one_letter_code_ &&
648
formula_ == residue.formula_ &&
649
average_weight_ == residue.average_weight_ &&
650
mono_weight_ == residue.mono_weight_ &&
651
is_modified_ == residue.is_modified_ &&
652
pre_mod_name_ == residue.pre_mod_name_ &&
653
modification_ == residue.modification_ &&
654
loss_names_ == residue.loss_names_ &&
655
loss_formulas_ == residue.loss_formulas_ &&
656
NTerm_loss_names_ == residue.NTerm_loss_names_ &&
657
NTerm_loss_formulas_ == residue.NTerm_loss_formulas_ &&
658
loss_average_weight_ == residue.loss_average_weight_ &&
659
loss_mono_weight_ == residue.loss_mono_weight_ &&
660
low_mass_ions_ == residue.low_mass_ions_ &&
661
pka_ == residue.pka_ &&
662
pkb_ == residue.pkb_ &&
663
pkc_ == residue.pkc_ &&
664
gb_sc_ == residue.gb_sc_ &&
665
gb_bb_l_ == residue.gb_bb_l_ &&
666
gb_bb_r_ == residue.gb_bb_r_ &&
667
residue_sets_ == residue.residue_sets_);
670
bool Residue::operator == (char one_letter_code) const
672
return one_letter_code_[0] == one_letter_code;
675
bool Residue::operator != (char one_letter_code) const
677
return one_letter_code_[0] != one_letter_code;
680
bool Residue::operator != (const Residue& residue) const
682
return !(*this == residue);
685
bool Residue::isInResidueSet(const String& residue_set)
687
return residue_sets_.find(residue_set) != residue_sets_.end();
690
ostream& operator << (ostream& os, const Residue& residue)
692
os << residue.name_ << " "
693
<< residue.three_letter_code_ << " "
694
<< residue.one_letter_code_ << " "