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
// --------------------------------------------------------------------------
28
#include <OpenMS/CHEMISTRY/ResidueModification.h>
29
#include <OpenMS/FORMAT/HANDLERS/UnimodXMLHandler.h>
30
#include <xercesc/sax2/Attributes.hpp>
33
using namespace xercesc;
40
UnimodXMLHandler::UnimodXMLHandler(vector<ResidueModification*>& mods, const String& filename)
41
: XMLHandler(filename, "2.0"),
50
UnimodXMLHandler::~UnimodXMLHandler()
55
void UnimodXMLHandler::startElement(const XMLCh* const /*uri*/, const XMLCh* const /*local_name*/, const XMLCh* const qname, const Attributes& attributes)
58
tag_ = String(sm_.convert(qname));
61
if (tag_ == "umod:mod" || tag_ == "mod")
64
modification_ = new ResidueModification();
65
String title(attributeAsString_(attributes, "title"));
66
modification_->setId(title);
68
String full_name(attributeAsString_(attributes, "full_name"));
69
// full_name.substitute("®", ""); // remove damn character (will be interpreted differently across platforms)
70
// deleted this in the unimod.xml file
71
modification_->setFullName(full_name);
73
String record_id(attributeAsString_(attributes, "record_id"));
74
modification_->setUniModAccession("UniMod:" + record_id);
78
// which residues are allowed?
79
if (tag_ == "umod:specificity" || tag_ == "specificity")
81
// classification of mod
82
// TODO do this for all mods, do not overwrite for each specificity
83
String classification(attributeAsString_(attributes, "classification"));
84
modification_->setSourceClassification(classification);
87
String site(attributeAsString_(attributes, "site"));
88
//sites_.push_back(site);
91
ResidueModification::Term_Specificity position = ResidueModification::ANYWHERE;
92
String pos(attributeAsString_(attributes, "position"));
93
if (pos == "Anywhere")
95
position = ResidueModification::ANYWHERE;
99
if (pos == "Protein N-term")
101
position = ResidueModification::N_TERM;
105
if (pos == "Protein C-term")
107
position = ResidueModification::C_TERM;
111
if (pos == "Any C-term")
113
position = ResidueModification::C_TERM;
117
if (pos == "Any N-term")
119
position = ResidueModification::N_TERM;
123
warning(LOAD, String("Don't know allowed position called: '") + pos + "' - setting to anywhere");
130
if (!pos.hasSubstring("Protein"))
132
term_specs_.push_back(position);
133
sites_.push_back(site);
139
if (tag_ == "umod:NeutralLoss" || tag_ == "NeutralLoss")
141
// mono_mass="97.976896" avge_mass="97.9952" flag="false"
142
// composition="H(3) O(4) P">
146
// delta mass defintions?
147
if (tag_ == "umod:delta" || tag_ == "delta")
149
// avge_mass="-0.9848" mono_mass="-0.984016" composition="H N O(-1)" >
150
avge_mass_ = String(sm_.convert(attributes.getValue(attributes.getIndex(sm_.convert("avge_mass"))))).toDouble();
151
mono_mass_ = String(sm_.convert(attributes.getValue(attributes.getIndex(sm_.convert("mono_mass"))))).toDouble();
155
// <umod:element symbol="H" number="1"/>
156
if (tag_ == "umod:element")
158
String symbol = sm_.convert(attributes.getValue(attributes.getIndex(sm_.convert("symbol"))));
159
String num = sm_.convert(attributes.getValue(attributes.getIndex(sm_.convert("number"))));
160
String isotope, tmp_symbol;
161
for (Size i = 0; i != symbol.size(); ++i)
163
if (isdigit(symbol[i]))
165
isotope += symbol[i];
169
tmp_symbol += symbol[i];
176
formula = '(' + isotope + ')' + tmp_symbol + String(num);
180
formula = tmp_symbol + num;
182
diff_formula_ += formula;
188
void UnimodXMLHandler::endElement(const XMLCh* const /*uri*/, const XMLCh* const /*local_name*/, const XMLCh* const qname)
190
tag_ = String(sm_.convert(qname));
192
// write the modifications to vector
193
if (tag_ == "umod:mod" || tag_ == "mod")
195
modification_->setDiffAverageMass(avge_mass_);
196
modification_->setDiffMonoMass(mono_mass_);
197
modification_->setDiffFormula(diff_formula_);
198
for (Size i = 0; i != sites_.size(); ++i)
200
ResidueModification* new_mod = new ResidueModification(*modification_);
201
new_mod->setOrigin(sites_[i]);
202
new_mod->setTermSpecificity(term_specs_[i]);
203
modifications_.push_back(new_mod);
208
diff_formula_ = EmpiricalFormula();
212
delete modification_;
216
if (tag_ == "umod:NeutralLoss" || tag_ == "NeutralLoss")
218
// now diff_formula_ contains the neutral loss diff formula
219
modification_->setNeutralLossDiffFormula(diff_formula_);
220
modification_->setNeutralLossMonoMass(mono_mass_);
221
modification_->setNeutralLossAverageMass(avge_mass_);
224
diff_formula_ = EmpiricalFormula();
228
void UnimodXMLHandler::characters(const XMLCh* const /*chars*/, const XMLSize_t /*length*/)
230
// nothing to do here
233
} // namespace Internal
234
} // namespace OpenMS