Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
MzXMLHandler.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2013.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Andreas Bertsch $
32 // $Authors: Marc Sturm $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_FORMAT_HANDLERS_MZXMLHANDLER_H
36 #define OPENMS_FORMAT_HANDLERS_MZXMLHANDLER_H
37 
39 #include <OpenMS/FORMAT/Base64.h>
44 
45 #include <stack>
46 
47 namespace OpenMS
48 {
49  class MetaInfoInterface;
50 
51  namespace Internal
52  {
59  template <typename MapType>
60  class MzXMLHandler :
61  public XMLHandler
62  {
63 public:
66  MzXMLHandler(MapType& exp, const String& filename, const String& version, ProgressLogger& logger) :
68  XMLHandler(filename, version),
69  exp_(&exp),
70  cexp_(0),
71  decoder_(),
72  peak_count_(0),
73  char_rest_(),
74  skip_spectrum_(false),
76  logger_(logger)
77  {
78  init_();
79  }
80 
82  MzXMLHandler(const MapType& exp, const String& filename, const String& version, const ProgressLogger& logger) :
83  XMLHandler(filename, version),
84  exp_(0),
85  cexp_(&exp),
86  decoder_(),
87  peak_count_(0),
88  char_rest_(),
89  skip_spectrum_(false),
91  logger_(logger)
92  {
93  init_();
94  }
95 
97  virtual ~MzXMLHandler()
98  {
99  }
100 
102 
103  // Docu in base class
104  virtual void endElement(const XMLCh* const uri, const XMLCh* const local_name, const XMLCh* const qname);
105 
106  // Docu in base class
107  virtual void startElement(const XMLCh* const uri, const XMLCh* const local_name, const XMLCh* const qname, const xercesc::Attributes& attributes);
108 
109  // Docu in base class
110  virtual void characters(const XMLCh* const chars, const XMLSize_t length);
111 
113  void writeTo(std::ostream& os);
114 
116  void setOptions(const PeakFileOptions& options)
117  {
118  options_ = options;
119  }
120 
121 private:
122  // initialize members (call from C'tor)
123  void init_()
124  {
125  cv_terms_.resize(6);
126  //Polarity
127  String("any;+;-").split(';', cv_terms_[0]);
128  //Scan type
129  // is no longer used cv_terms_[1] is empty now
130  //Ionization method
131  String(";ESI;EI;CI;FAB;;;;;;;;;;;;;APCI;;;;;;;;MALDI").split(';', cv_terms_[2]);
133  //Mass analyzer
134  String(";Quadrupole;Quadrupole Ion Trap;;;TOF;Magnetic Sector;FT-ICR;").split(';', cv_terms_[3]);
136  //Detector
137  String(";EMT;;;Faraday Cup;;;;;Channeltron;Daly;Microchannel plate").split(';', cv_terms_[4]);
139  //Resolution method
140  String(";FWHM;TenPercentValley;Baseline").split(';', cv_terms_[5]);
142  /* // OLD:
143  cv_terms_.resize(6);
144  //Polarity
145  String("any;+;-").split(';',cv_terms_[0]);
146  //Scan type
147  // is no longer used cv_terms_[1] is empty now
148  //Ionization method
149  String(";ESI;EI;CI;FAB;TSP;MALDI;FD;FI;PD;SI;TI;API;ISI;CID;CAD;HN;APCI;APPI;ICP").split(';',cv_terms_[2]);
150  //Mass analyzer
151  String(";Quadrupole;Quadrupole Ion Trap;;;TOF;Magnetic Sector;FT-ICR;").split(';',cv_terms_[3]);
152  //Detector
153  String(";EMT;Daly;;Faraday Cup;;;;Channeltron").split(';',cv_terms_[4]);
154  //Resolution method
155  String(";FWHM;TenPercentValley;Baseline").split(';',cv_terms_[5]);
156  */
157  }
158 
159 protected:
160 
162  typedef typename MapType::PeakType PeakType;
165 
167 
169  MapType* exp_;
171  const MapType* cexp_;
172 
175 
184 
187 
190 
193 
195  inline void writeUserParam_(std::ostream& os, const MetaInfoInterface& meta, int indent = 4, String tag = "nameValue")
196  {
197  std::vector<String> keys; // Vector to hold keys to meta info
198  meta.getKeys(keys);
199 
200  for (std::vector<String>::const_iterator it = keys.begin(); it != keys.end(); ++it)
201  {
202  if ((*it)[0] != '#') // internally used meta info start with '#'
203  {
204  os << String(indent, '\t') << "<" << tag << " name=\"" << *it << "\" value=\"" << meta.getMetaValue(*it) << "\"/>\n";
205  }
206  }
207  }
208 
210  std::vector<DataProcessing> data_processing_;
211 
212 private:
214  MzXMLHandler();
215 
216  static const XMLCh* s_value_;
217  static const XMLCh* s_count_;
218  static const XMLCh* s_type_;
219  static const XMLCh* s_name_;
220  static const XMLCh* s_version_;
221  static const XMLCh* s_filename_;
222  static const XMLCh* s_filetype_;
223  static const XMLCh* s_filesha1_;
224  static const XMLCh* s_completiontime_;
225  static const XMLCh* s_precision_;
226  static const XMLCh* s_byteorder_;
227  static const XMLCh* s_pairorder_;
228  static const XMLCh* s_compressionType_;
229  static const XMLCh* s_precursorintensity_;
230  static const XMLCh* s_precursorcharge_;
231  static const XMLCh* s_windowwideness_;
232  static const XMLCh* s_mslevel_;
233  static const XMLCh* s_peakscount_;
234  static const XMLCh* s_polarity_;
235  static const XMLCh* s_scantype_;
236  static const XMLCh* s_retentiontime_;
237  static const XMLCh* s_startmz_;
238  static const XMLCh* s_endmz_;
239  static const XMLCh* s_first_;
240  static const XMLCh* s_last_;
241  static const XMLCh* s_phone_;
242  static const XMLCh* s_email_;
243  static const XMLCh* s_uri_;
244  static const XMLCh* s_num_;
245  static const XMLCh* s_intensitycutoff_;
246  static const XMLCh* s_centroided_;
247  static const XMLCh* s_deisotoped_;
248  static const XMLCh* s_chargedeconvoluted_;
249 
250  // init all the static members, which is necessary because otherwise the undefined order will cause problems
252  {
253  static bool init(false);
254  if (!init)
255  {
256  s_value_ = xercesc::XMLString::transcode("value");
257  s_count_ = xercesc::XMLString::transcode("scanCount");
258  s_type_ = xercesc::XMLString::transcode("type");
259  s_name_ = xercesc::XMLString::transcode("name");
260  s_version_ = xercesc::XMLString::transcode("version");
261  s_filename_ = xercesc::XMLString::transcode("fileName");
262  s_filetype_ = xercesc::XMLString::transcode("fileType");
263  s_filesha1_ = xercesc::XMLString::transcode("fileSha1");
264  s_completiontime_ = xercesc::XMLString::transcode("completionTime");
265  s_precision_ = xercesc::XMLString::transcode("precision");
266  s_byteorder_ = xercesc::XMLString::transcode("byteOrder");
267  s_pairorder_ = xercesc::XMLString::transcode("pairOrder");
268  s_compressionType_ = xercesc::XMLString::transcode("compressionType");
269  s_precursorintensity_ = xercesc::XMLString::transcode("precursorIntensity");
270  s_precursorcharge_ = xercesc::XMLString::transcode("precursorCharge");
271  s_windowwideness_ = xercesc::XMLString::transcode("windowWideness");
272  s_mslevel_ = xercesc::XMLString::transcode("msLevel");
273  s_peakscount_ = xercesc::XMLString::transcode("peaksCount");
274  s_polarity_ = xercesc::XMLString::transcode("polarity");
275  s_scantype_ = xercesc::XMLString::transcode("scanType");
276  s_retentiontime_ = xercesc::XMLString::transcode("retentionTime");
277  s_startmz_ = xercesc::XMLString::transcode("startMz");
278  s_endmz_ = xercesc::XMLString::transcode("endMz");
279  s_first_ = xercesc::XMLString::transcode("first");
280  s_last_ = xercesc::XMLString::transcode("last");
281  s_phone_ = xercesc::XMLString::transcode("phone");
282  s_email_ = xercesc::XMLString::transcode("email");
283  s_uri_ = xercesc::XMLString::transcode("URI");
284  s_num_ = xercesc::XMLString::transcode("num");
285  s_intensitycutoff_ = xercesc::XMLString::transcode("intensityCutoff");
286  s_centroided_ = xercesc::XMLString::transcode("centroided");
287  s_deisotoped_ = xercesc::XMLString::transcode("deisotoped");
288  s_chargedeconvoluted_ = xercesc::XMLString::transcode("chargeDeconvoluted");
289 
290  init = true;
291  }
292  return;
293  }
294 
295  };
296 
297  //--------------------------------------------------------------------------------
298 
299  // this cannot be moved into a function as VS2008 does not allow more than 31 static members in a function .. don't ask...
300  template <typename MapType>
301  const XMLCh * MzXMLHandler<MapType>::s_value_ = 0;
302  template <typename MapType>
303  const XMLCh * MzXMLHandler<MapType>::s_count_ = 0;
304  template <typename MapType>
305  const XMLCh * MzXMLHandler<MapType>::s_type_ = 0;
306  template <typename MapType>
307  const XMLCh * MzXMLHandler<MapType>::s_name_ = 0;
308  template <typename MapType>
309  const XMLCh * MzXMLHandler<MapType>::s_version_ = 0;
310  template <typename MapType>
311  const XMLCh * MzXMLHandler<MapType>::s_filename_ = 0;
312  template <typename MapType>
313  const XMLCh * MzXMLHandler<MapType>::s_filetype_ = 0;
314  template <typename MapType>
315  const XMLCh * MzXMLHandler<MapType>::s_filesha1_ = 0;
316  template <typename MapType>
318  template <typename MapType>
319  const XMLCh * MzXMLHandler<MapType>::s_precision_ = 0;
320  template <typename MapType>
321  const XMLCh * MzXMLHandler<MapType>::s_byteorder_ = 0;
322  template <typename MapType>
323  const XMLCh * MzXMLHandler<MapType>::s_pairorder_ = 0;
324  template <typename MapType>
326  template <typename MapType>
328  template <typename MapType>
330  template <typename MapType>
332  template <typename MapType>
333  const XMLCh * MzXMLHandler<MapType>::s_mslevel_ = 0;
334  template <typename MapType>
335  const XMLCh * MzXMLHandler<MapType>::s_peakscount_ = 0;
336  template <typename MapType>
337  const XMLCh * MzXMLHandler<MapType>::s_polarity_ = 0;
338  template <typename MapType>
339  const XMLCh * MzXMLHandler<MapType>::s_scantype_ = 0;
340  template <typename MapType>
341  const XMLCh * MzXMLHandler<MapType>::s_retentiontime_ = 0;
342  template <typename MapType>
343  const XMLCh * MzXMLHandler<MapType>::s_startmz_ = 0;
344  template <typename MapType>
345  const XMLCh * MzXMLHandler<MapType>::s_endmz_ = 0;
346  template <typename MapType>
347  const XMLCh * MzXMLHandler<MapType>::s_first_ = 0;
348  template <typename MapType>
349  const XMLCh * MzXMLHandler<MapType>::s_last_ = 0;
350  template <typename MapType>
351  const XMLCh * MzXMLHandler<MapType>::s_phone_ = 0;
352  template <typename MapType>
353  const XMLCh * MzXMLHandler<MapType>::s_email_ = 0;
354  template <typename MapType>
355  const XMLCh * MzXMLHandler<MapType>::s_uri_ = 0;
356  template <typename MapType>
357  const XMLCh * MzXMLHandler<MapType>::s_num_ = 0;
358  template <typename MapType>
360  template <typename MapType>
361  const XMLCh * MzXMLHandler<MapType>::s_centroided_ = 0;
362  template <typename MapType>
363  const XMLCh * MzXMLHandler<MapType>::s_deisotoped_ = 0;
364  template <typename MapType>
366 
367  template <typename MapType>
368  void MzXMLHandler<MapType>::startElement(const XMLCh* const /*uri*/, const XMLCh* const /*local_name*/, const XMLCh* const qname, const xercesc::Attributes& attributes)
369  {
370  static bool init_static_members(false);
371  if (!init_static_members)
372  {
373  initStaticMembers_();
374  }
375 
376  static UInt scan_count = 0;
377 
378  String tag = sm_.convert(qname);
379  open_tags_.push_back(tag);
380  //std::cout << " -- Start -- "<< tag << " -- " << "\n";
381 
382  //Skip all tags until the the next scan
383  if (skip_spectrum_ && tag != "scan")
384  return;
385 
386  if (tag == "msRun")
387  {
388  Int count = 0;
389  optionalAttributeAsInt_(count, attributes, s_count_);
390  exp_->reserve(count);
391  logger_.startProgress(0, count, "loading mzXML file");
392  scan_count = 0;
393  data_processing_.clear();
394  //start and end time are xs:duration. This makes no senes => ignore them
395  }
396  else if (tag == "parentFile")
397  {
398  SourceFile sf;
399  sf.setNameOfFile(attributeAsString_(attributes, s_filename_));
400  sf.setFileType(attributeAsString_(attributes, s_filetype_));
401  sf.setChecksum(attributeAsString_(attributes, s_filesha1_), SourceFile::SHA1);
402  exp_->getSourceFiles().push_back(sf);
403  }
404  else if (tag == "software")
405  {
406  String& parent_tag = *(open_tags_.end() - 2);
407  if (parent_tag == "dataProcessing")
408  {
409  data_processing_.back().getSoftware().setVersion(attributeAsString_(attributes, s_version_));
410  data_processing_.back().getSoftware().setName(attributeAsString_(attributes, s_name_));
411  data_processing_.back().setMetaValue("#type", String(attributeAsString_(attributes, s_type_)));
412 
413  String time;
414  optionalAttributeAsString_(time, attributes, s_completiontime_);
415  data_processing_.back().setCompletionTime(asDateTime_(time));
416  }
417  else if (parent_tag == "msInstrument")
418  {
419  exp_->getInstrument().getSoftware().setVersion(attributeAsString_(attributes, s_version_));
420  exp_->getInstrument().getSoftware().setName(attributeAsString_(attributes, s_name_));
421  }
422  }
423  else if (tag == "peaks")
424  {
425  //precision
426  precision_ = "32";
427  optionalAttributeAsString_(precision_, attributes, s_precision_);
428  if (precision_ != "32" && precision_ != "64")
429  {
430  error(LOAD, String("Invalid precision '") + precision_ + "' in element 'peaks'");
431  }
432  //byte order
433  String byte_order = "network";
434  optionalAttributeAsString_(byte_order, attributes, s_byteorder_);
435  if (byte_order != "network")
436  {
437  error(LOAD, String("Invalid or missing byte order '") + byte_order + "' in element 'peaks'. Must be 'network'!");
438  }
439  //pair order
440  String pair_order = "m/z-int";
441  optionalAttributeAsString_(pair_order, attributes, s_pairorder_);
442  if (pair_order != "m/z-int")
443  {
444  error(LOAD, String("Invalid or missing pair order '") + pair_order + "' in element 'peaks'. Must be 'm/z-int'!");
445  }
446  //compressionType
447  compressionType_ = "none";
448  optionalAttributeAsString_(compressionType_, attributes, s_compressionType_);
449  if (compressionType_ != "none" && compressionType_ != "zlib")
450  {
451  error(LOAD, String("Invalid compression type ") + compressionType_ + "in elements 'peaks'. Must be 'none' or 'zlib'! ");
452  }
453  }
454  else if (tag == "precursorMz")
455  {
456  //add new precursor
457  exp_->getSpectra().back().getPrecursors().push_back(Precursor());
458  //intensity
459  try
460  {
461  exp_->getSpectra().back().getPrecursors().back().setIntensity(attributeAsDouble_(attributes, s_precursorintensity_));
462  }
463  catch (Exception::ParseError& /*e*/)
464  {
465  error(LOAD, "Mandatory attribute 'precursorIntensity' of tag 'precursorMz' not found! Setting precursor intensity to zero!");
466  }
467  //charge
468  Int charge = 0;
469  if (optionalAttributeAsInt_(charge, attributes, s_precursorcharge_))
470  {
471  exp_->getSpectra().back().getPrecursors().back().setCharge(charge);
472  }
473  //window bounds (here only the width is stored in both fields - this is corrected when we parse the m/z position)
474  DoubleReal window = 0.0;
475  if (optionalAttributeAsDouble_(window, attributes, s_windowwideness_))
476  {
477  exp_->getSpectra().back().getPrecursors().back().setIsolationWindowLowerOffset(window);
478  }
479  }
480  else if (tag == "scan")
481  {
482  skip_spectrum_ = false;
483 
484  if (options_.getMetadataOnly())
485  throw EndParsingSoftly(__FILE__, __LINE__, __PRETTY_FUNCTION__);
486 
487  // check if the scan is in the desired MS / RT range
488  UInt ms_level = attributeAsInt_(attributes, s_mslevel_);
489  if (ms_level == 0)
490  {
491  warning(LOAD, String("Invalid 'msLevel' attribute with value '0' in 'scan' element found. Assuming ms level 1!"));
492  ms_level = 1;
493  }
494 
495  //parse retention time and convert it from xs:duration to seconds
496  DoubleReal retention_time = 0.0;
497  String time_string = "";
498  if (optionalAttributeAsString_(time_string, attributes, s_retentiontime_))
499  {
500  time_string = time_string.suffix('T');
501  //std::cout << "Initial trim: " << time_string << "\n";
502  if (time_string.has('H'))
503  {
504  retention_time += 3600 * asDouble_(time_string.prefix('H'));
505  time_string = time_string.suffix('H');
506  //std::cout << "After H: " << time_string << "\n";
507  }
508  if (time_string.has('M'))
509  {
510  retention_time += 60 * asDouble_(time_string.prefix('M'));
511  time_string = time_string.suffix('M');
512  //std::cout << "After M: " << time_string << "\n";
513  }
514  if (time_string.has('S'))
515  {
516  retention_time += asDouble_(time_string.prefix('S'));
517  time_string = time_string.suffix('S');
518  //std::cout << "After S: " << time_string << "\n";
519  }
520  }
521 
522  logger_.setProgress(scan_count);
523 
524  if ((options_.hasRTRange() && !options_.getRTRange().encloses(DPosition<1>(retention_time)))
525  || (options_.hasMSLevels() && !options_.containsMSLevel(ms_level)))
526  {
527  // skip this tag
528  skip_spectrum_ = true;
529  ++scan_count;
530  return;
531  }
532 
533  //Add a new spectrum and set MS level and RT
534  exp_->resize(exp_->size() + 1);
535  exp_->getSpectra().back().setMSLevel(ms_level);
536  exp_->getSpectra().back().setRT(retention_time);
537  exp_->getSpectra().back().setNativeID(String("scan=") + attributeAsString_(attributes, s_num_));
538  //peak count == twice the scan size
539  peak_count_ = attributeAsInt_(attributes, s_peakscount_);
540  exp_->getSpectra().back().reserve(peak_count_ / 2 + 1);
541  exp_->getSpectra().back().setDataProcessing(data_processing_);
542 
543  //centroided, chargeDeconvoluted, deisotoped, collisionEnergy are ignored
544 
545  //other optional attributes
546  ScanWindow window;
547  optionalAttributeAsDouble_(window.begin, attributes, s_startmz_);
548  optionalAttributeAsDouble_(window.end, attributes, s_endmz_);
549  if (window.begin != 0.0 || window.end != 0.0)
550  {
551  exp_->getSpectra().back().getInstrumentSettings().getScanWindows().push_back(window);
552  }
553 
554  String polarity = "any";
555  optionalAttributeAsString_(polarity, attributes, s_polarity_);
556  exp_->getSpectra().back().getInstrumentSettings().setPolarity((IonSource::Polarity) cvStringToEnum_(0, polarity, "polarity"));
557 
558  String type = "";
559  optionalAttributeAsString_(type, attributes, s_scantype_);
560  if (type == "")
561  {
562  //unknown/unset => do nothing here => no warning in the end
563  }
564  else if (type == "zoom")
565  {
566  exp_->getSpectra().back().getInstrumentSettings().setZoomScan(true);
567  exp_->getSpectra().back().getInstrumentSettings().setScanMode(InstrumentSettings::MASSSPECTRUM);
568  }
569  else if (type == "Full")
570  {
571  if (ms_level > 1)
572  exp_->getSpectra().back().getInstrumentSettings().setScanMode(InstrumentSettings::MSNSPECTRUM);
573  else
574  exp_->getSpectra().back().getInstrumentSettings().setScanMode(InstrumentSettings::MASSSPECTRUM);
575  }
576  else if (type == "SIM")
577  {
578  exp_->getSpectra().back().getInstrumentSettings().setScanMode(InstrumentSettings::SIM);
579  }
580  else if (type == "SRM" || type == "MRM")
581  {
582  exp_->getSpectra().back().getInstrumentSettings().setScanMode(InstrumentSettings::SRM);
583  }
584  else if (type == "CRM")
585  {
586  exp_->getSpectra().back().getInstrumentSettings().setScanMode(InstrumentSettings::CRM);
587  }
588  else if (type == "Q1")
589  {
590  exp_->getSpectra().back().getInstrumentSettings().setScanMode(InstrumentSettings::MASSSPECTRUM);
591  }
592  else if (type == "Q3")
593  {
594  exp_->getSpectra().back().getInstrumentSettings().setScanMode(InstrumentSettings::MASSSPECTRUM);
595  }
596  else if (type == "EMS") //Non-standard type: Enhanced MS (ABI - Sashimi converter)
597  {
598  exp_->getSpectra().back().getInstrumentSettings().setScanMode(InstrumentSettings::MASSSPECTRUM);
599  }
600  else if (type == "EPI") //Non-standard type: Enhanced Product Ion (ABI - Sashimi converter)
601  {
602  exp_->getSpectra().back().getInstrumentSettings().setScanMode(InstrumentSettings::MASSSPECTRUM);
603  exp_->getSpectra().back().setMSLevel(2);
604  }
605  else if (type == "ER") // Non-standard type: Enhanced Resolution (ABI - Sashimi converter)
606  {
607  exp_->getSpectra().back().getInstrumentSettings().setZoomScan(true);
608  exp_->getSpectra().back().getInstrumentSettings().setScanMode(InstrumentSettings::MASSSPECTRUM);
609  }
610  else
611  {
612  exp_->getSpectra().back().getInstrumentSettings().setScanMode(InstrumentSettings::MASSSPECTRUM);
613  warning(LOAD, String("Unknown scan mode '") + type + "'. Assuming full scan");
614  }
615 
616  ++scan_count;
617  }
618  else if (tag == "operator")
619  {
620  exp_->getContacts().resize(1);
621  exp_->getContacts().back().setFirstName(attributeAsString_(attributes, s_first_));
622  exp_->getContacts().back().setLastName(attributeAsString_(attributes, s_last_));
623 
624  String tmp = "";
625  optionalAttributeAsString_(tmp, attributes, s_email_);
626  exp_->getContacts().back().setEmail(tmp);
627 
628  tmp = "";
629  optionalAttributeAsString_(tmp, attributes, s_phone_);
630  if (tmp != "")
631  {
632  exp_->getContacts().back().setMetaValue("#phone", tmp);
633  }
634 
635  tmp = "";
636  optionalAttributeAsString_(tmp, attributes, s_uri_);
637  exp_->getContacts().back().setURL(tmp);
638  }
639  else if (tag == "msManufacturer")
640  {
641  exp_->getInstrument().setVendor(attributeAsString_(attributes, s_value_));
642  }
643  else if (tag == "msModel")
644  {
645  exp_->getInstrument().setModel(attributeAsString_(attributes, s_value_));
646  }
647  else if (tag == "msIonisation")
648  {
649  exp_->getInstrument().getIonSources().resize(1);
650  exp_->getInstrument().getIonSources()[0].setIonizationMethod((IonSource::IonizationMethod) cvStringToEnum_(2, attributeAsString_(attributes, s_value_), "msIonization"));
651  }
652  else if (tag == "msMassAnalyzer")
653  {
654  exp_->getInstrument().getMassAnalyzers().resize(1);
655  exp_->getInstrument().getMassAnalyzers()[0].setType((MassAnalyzer::AnalyzerType) cvStringToEnum_(3, attributeAsString_(attributes, s_value_), "msMassAnalyzer"));
656  }
657  else if (tag == "msDetector")
658  {
659  exp_->getInstrument().getIonDetectors().resize(1);
660  exp_->getInstrument().getIonDetectors()[0].setType((IonDetector::Type) cvStringToEnum_(4, attributeAsString_(attributes, s_value_), "msDetector"));
661  }
662  else if (tag == "msResolution")
663  {
664  exp_->getInstrument().getMassAnalyzers()[0].setResolutionMethod((MassAnalyzer::ResolutionMethod) cvStringToEnum_(5, attributeAsString_(attributes, s_value_), "msResolution"));
665  }
666  else if (tag == "dataProcessing")
667  {
668  data_processing_.push_back(DataProcessing());
669 
670  String boolean = "";
671  optionalAttributeAsString_(boolean, attributes, s_deisotoped_);
672  if (boolean == "true" || boolean == "1")
673  {
674  data_processing_.back().getProcessingActions().insert(DataProcessing::DEISOTOPING);
675  }
676 
677  boolean = "";
678  optionalAttributeAsString_(boolean, attributes, s_chargedeconvoluted_);
679  if (boolean == "true" || boolean == "1")
680  {
681  data_processing_.back().getProcessingActions().insert(DataProcessing::CHARGE_DECONVOLUTION);
682  }
683 
684  DoubleReal cutoff = 0.0;
685  optionalAttributeAsDouble_(cutoff, attributes, s_intensitycutoff_);
686  if (cutoff != 0.0)
687  {
688  data_processing_.back().setMetaValue("#intensity_cutoff", cutoff);
689  }
690 
691  boolean = "";
692  optionalAttributeAsString_(boolean, attributes, s_centroided_);
693  if (boolean == "true" || boolean == "1")
694  {
695  data_processing_.back().getProcessingActions().insert(DataProcessing::PEAK_PICKING);
696  }
697  }
698  else if (tag == "nameValue")
699  {
700  String name = "";
701  optionalAttributeAsString_(name, attributes, s_name_);
702  if (name == "")
703  return;
704 
705  String value = "";
706  optionalAttributeAsString_(value, attributes, s_value_);
707 
708  String& parent_tag = *(open_tags_.end() - 2);
709 
710  if (parent_tag == "msInstrument")
711  {
712  exp_->getInstrument().setMetaValue(name, value);
713  }
714  else if (parent_tag == "scan")
715  {
716  exp_->getSpectra().back().setMetaValue(name, value);
717  }
718  else
719  {
720  std::cout << " Warning: Unexpected tag 'nameValue' in tag '" << parent_tag << "'" << "\n";
721  }
722  }
723  else if (tag == "processingOperation")
724  {
725  String name = "";
726  optionalAttributeAsString_(name, attributes, s_name_);
727  if (name == "")
728  return;
729 
730  String value = "";
731  optionalAttributeAsString_(value, attributes, s_value_);
732 
733  data_processing_.back().setMetaValue(name, value);
734  }
735 
736  //std::cout << " -- !Start -- " << "\n";
737  }
738 
739  template <typename MapType>
740  void MzXMLHandler<MapType>::endElement(const XMLCh* const /*uri*/, const XMLCh* const /*local_name*/, const XMLCh* const qname)
741  {
742  //std::cout << " -- End -- " << sm_.convert(qname) << " -- " << "\n";
743 
744  static const XMLCh* s_mzxml = xercesc::XMLString::transcode("mzXML");
745  static const XMLCh* s_peaks = xercesc::XMLString::transcode("peaks");
746 
747  open_tags_.pop_back();
748 
749  //abort if this scan should be skipped
750  if (skip_spectrum_)
751  return;
752 
753  if (equal_(qname, s_mzxml))
754  {
755  logger_.endProgress();
756  }
757  else if (equal_(qname, s_peaks))
758  {
759  //std::cout << "reading scan" << "\n";
760  if (char_rest_ == "") // no peaks
761  {
762  return;
763  }
764 
765  //remove whitespaces from binary data
766  //this should not be necessary, but linebreaks inside the base64 data are unfortunately no exception
767  char_rest_.removeWhitespaces();
768 
769  if (precision_ == "64")
770  {
771  std::vector<DoubleReal> data;
772  if (compressionType_ == "zlib")
773  {
774  decoder_.decode(char_rest_, Base64::BYTEORDER_BIGENDIAN, data, true);
775  }
776  else
777  {
778  decoder_.decode(char_rest_, Base64::BYTEORDER_BIGENDIAN, data);
779  }
780  char_rest_ = "";
781  PeakType peak;
782  //push_back the peaks into the container
783  for (Size n = 0; n < (2 * peak_count_); n += 2)
784  {
785  // check if peak in in the specified m/z and intensity range
786  if ((!options_.hasMZRange() || options_.getMZRange().encloses(DPosition<1>(data[n])))
787  && (!options_.hasIntensityRange() || options_.getIntensityRange().encloses(DPosition<1>(data[n + 1]))))
788  {
789  peak.setMZ(data[n]);
790  peak.setIntensity(data[n + 1]);
791  exp_->getSpectra().back().push_back(peak);
792  }
793  }
794  }
795  else //precision 32
796  {
797  std::vector<Real> data;
798  if (compressionType_ == "zlib")
799  {
800  decoder_.decode(char_rest_, Base64::BYTEORDER_BIGENDIAN, data, true);
801  }
802  else
803  {
804  decoder_.decode(char_rest_, Base64::BYTEORDER_BIGENDIAN, data);
805  }
806  char_rest_ = "";
807  PeakType peak;
808  //push_back the peaks into the container
809  for (Size n = 0; n < (2 * peak_count_); n += 2)
810  {
811  if ((!options_.hasMZRange() || options_.getMZRange().encloses(DPosition<1>(data[n])))
812  && (!options_.hasIntensityRange() || options_.getIntensityRange().encloses(DPosition<1>(data[n + 1]))))
813  {
814  peak.setMZ(data[n]);
815  peak.setIntensity(data[n + 1]);
816  exp_->getSpectra().back().push_back(peak);
817  }
818  }
819  }
820  }
821  //std::cout << " -- End -- " << "\n";
822  sm_.clear();
823  }
824 
825  template <typename MapType>
826  void MzXMLHandler<MapType>::characters(const XMLCh* const chars, const XMLSize_t /*length*/)
827  {
828  //Abort if this spectrum should be skipped
829  if (skip_spectrum_)
830  return;
831 
832  char* transcoded_chars = sm_.convert(chars);
833 
834  if (open_tags_.back() == "peaks")
835  {
836  //chars may be split to several chunks => concatenate them
837  char_rest_ += transcoded_chars;
838  }
839  else if (open_tags_.back() == "offset" || open_tags_.back() == "indexOffset" || open_tags_.back() == "sha1")
840  {
841 
842  }
843  else if (open_tags_.back() == "precursorMz")
844  {
845  DoubleReal mz_pos = asDouble_(transcoded_chars);
846  //precursor m/z
847  exp_->getSpectra().back().getPrecursors().back().setMZ(mz_pos);
848  //update window bounds - center them around the m/z pos
849  DoubleReal window_width = exp_->getSpectra().back().getPrecursors().back().getIsolationWindowLowerOffset();
850  if (window_width != 0.0)
851  {
852  exp_->getSpectra().back().getPrecursors().back().setIsolationWindowLowerOffset(mz_pos - 0.5 * window_width);
853  exp_->getSpectra().back().getPrecursors().back().setIsolationWindowUpperOffset(mz_pos + 0.5 * window_width);
854  }
855  }
856  else if (open_tags_.back() == "comment")
857  {
858  String parent_tag = *(open_tags_.end() - 2);
859  //std::cout << "- Comment of parent " << parent_tag << "\n";
860 
861  if (parent_tag == "msInstrument")
862  {
863  exp_->getInstrument().setMetaValue("#comment", String(transcoded_chars));
864  }
865  else if (parent_tag == "dataProcessing")
866  {
867  //this is currently ignored
868  }
869  else if (parent_tag == "scan")
870  {
871  exp_->getSpectra().back().setComment(transcoded_chars);
872  }
873  else if (String(transcoded_chars).trim() != "")
874  {
875  warning(LOAD, String("Unhandled comment '") + transcoded_chars + "' in element '" + open_tags_.back() + "'");
876  }
877  }
878  else if (String(transcoded_chars).trim() != "")
879  {
880  warning(LOAD, String("Unhandled character content '") + transcoded_chars + "' in element '" + open_tags_.back() + "'");
881  }
882  }
883 
884  template <typename MapType>
885  void MzXMLHandler<MapType>::writeTo(std::ostream& os)
886  {
887  //determine how many spectra there are (count only those with peaks)
888  UInt count_tmp_ = 0;
889  for (Size s = 0; s < cexp_->size(); s++)
890  {
891  const SpectrumType& spec = (*cexp_)[s];
892  if (spec.size() != 0)
893  ++count_tmp_;
894  }
895  if (count_tmp_ == 0)
896  ++count_tmp_;
897  logger_.startProgress(0, cexp_->size(), "storing mzXML file");
898  os << "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
899  << "<mzXML xmlns=\"http://sashimi.sourceforge.net/schema_revision/mzXML_2.1\" "
900  << "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
901  << "xsi:schemaLocation=\"http://sashimi.sourceforge.net/schema_revision/mzXML_2.1 "
902  << "http://sashimi.sourceforge.net/schema_revision/mzXML_2.1/mzXML_idx_2.1.xsd\">\n"
903  << "\t<msRun scanCount=\"" << count_tmp_ << "\">\n";
904 
905  //----------------------------------------------------------------------------------------
906  // parent files
907  //----------------------------------------------------------------------------------------
908  if (cexp_->getSourceFiles().empty())
909  {
910  os << "\t\t<parentFile fileName=\"\" fileType=\"processedData\" fileSha1=\"0000000000000000000000000000000000000000\"/>\n";
911  }
912  else
913  {
914  for (Size i = 0; i < cexp_->getSourceFiles().size(); ++i)
915  {
916  const SourceFile& sf = cexp_->getSourceFiles()[i];
917  os << "\t\t<parentFile fileName=\"" << sf.getNameOfFile() << "\" fileType=\"";
918  //file type is an enum in mzXML => search for 'raw' string
919  String tmp_string = sf.getFileType();
920  tmp_string.toLower();
921  if (tmp_string.hasSubstring("raw"))
922  {
923  os << "RAWData";
924  }
925  else
926  {
927  os << "processedData";
928  }
929  //Sha1 checksum must have 40 characters => create a fake if it is unknown
930  os << "\" fileSha1=\"";
931  tmp_string = sf.getChecksum();
932  if (sf.getChecksum().size() != 40 || sf.getChecksumType() != SourceFile::SHA1)
933  {
934  os << "0000000000000000000000000000000000000000";
935  }
936  else
937  {
938  os << sf.getChecksum();
939  }
940  os << "\"/>\n";
941  }
942  }
943 
944  //----------------------------------------------------------------------------------------
945  //instrument
946  //----------------------------------------------------------------------------------------
947  if (cexp_->getInstrument() != Instrument() || cexp_->getContacts().size() != 0)
948  {
949  const Instrument& inst = cexp_->getInstrument();
950  os << "\t\t<msInstrument>\n"
951  << "\t\t\t<msManufacturer category=\"msManufacturer\" value=\"" << inst.getVendor() << "\"/>\n" << "\t\t\t<msModel category=\"msModel\" value=\"" << inst.getModel() << "\"/>\n";
952  if (inst.getIonSources().empty() || !inst.getIonSources()[0].getIonizationMethod())
953  {
954  os << "\t\t\t<msIonisation category=\"msIonisation\" value=\"\"/>\n";
955  }
956  else
957  {
958  os << "\t\t\t<msIonisation category=\"msIonisation\" value=\"" << cv_terms_[2][inst.getIonSources()[0].getIonizationMethod()] << "\"/>\n";
959  }
960  const std::vector<MassAnalyzer>& analyzers = inst.getMassAnalyzers();
961  if (analyzers.empty() || !analyzers[0].getResolutionMethod())
962  {
963  os << "\t\t\t<msMassAnalyzer category=\"msMassAnalyzer\" value=\"\"/>\n";
964  }
965  else
966  {
967  os << "\t\t\t<msMassAnalyzer category=\"msMassAnalyzer\" value=\"" << cv_terms_[3][analyzers[0].getType()] << "\"/>\n";
968  }
969  if (inst.getIonDetectors().empty() || !inst.getIonDetectors()[0].getType())
970  {
971  os << "\t\t\t<msDetector category=\"msDetector\" value=\"\"/>\n";
972  }
973  else
974  {
975  os << "\t\t\t<msDetector category=\"msDetector\" value=\"" << cv_terms_[4][inst.getIonDetectors()[0].getType()] << "\"/>\n";
976  }
977  os << "\t\t\t<software type=\"acquisition\" name=\"" << inst.getSoftware().getName() << "\" version=\"" << inst.getSoftware().getVersion() << "\"/>\n";
978  if (analyzers.empty() || !analyzers[0].getResolutionMethod())
979  {
980  os << "\t\t\t<msResolution category=\"msResolution\" value=\"\"/>\n";
981  }
982  else
983  {
984  os << "\t\t\t<msResolution category=\"msResolution\" value=\"" << cv_terms_[5][analyzers[0].getResolutionMethod()] << "\"/>\n";
985  }
986 
987  if (cexp_->getContacts().size() > 0)
988  {
989  const ContactPerson& cont = cexp_->getContacts()[0];
990 
991  os << "\t\t\t<operator first=\"" << cont.getFirstName() << "\" last=\"" << cont.getLastName() << "\"";
992 
993  if (cont.getEmail() != "")
994  {
995  os << " email=\"" << cont.getEmail() << "\"";
996  }
997 
998  if (cont.getURL() != "")
999  {
1000  os << " URI=\"" << cont.getURL() << "\"";
1001  }
1002 
1003  if (cont.metaValueExists("#phone"))
1004  {
1005  os << " phone=\"" << (String)(cont.getMetaValue("#phone")) << "\"";
1006  }
1007 
1008  os << "/>\n";
1009  }
1010  writeUserParam_(os, inst, 3);
1011 
1012  if (inst.metaValueExists("#comment"))
1013  {
1014  os << "\t\t\t<comment>" << inst.getMetaValue("#comment") << "</comment>\n";
1015  }
1016 
1017  os << "\t\t</msInstrument>\n";
1018  }
1019 
1020  //----------------------------------------------------------------------------------------
1021  //data processing (the information of the first spectrum is assigned to the whole file)
1022  //----------------------------------------------------------------------------------------
1023  if (cexp_->size() == 0 || (*cexp_)[0].getDataProcessing().empty())
1024  {
1025  os << "\t\t<dataProcessing>\n"
1026  << "\t\t\t<software type=\"processing\" name=\"\" version=\"\"/>\n"
1027  << "\t\t</dataProcessing>\n";
1028  }
1029  else
1030  {
1031  for (Size i = 0; i < (*cexp_)[0].getDataProcessing().size(); ++i)
1032  {
1033  const DataProcessing& data_processing = (*cexp_)[0].getDataProcessing()[i];
1034  os << "\t\t<dataProcessing deisotoped=\""
1035  << data_processing.getProcessingActions().count(DataProcessing::DEISOTOPING)
1036  << "\" chargeDeconvoluted=\""
1038  << "\" centroided=\""
1039  << data_processing.getProcessingActions().count(DataProcessing::PEAK_PICKING)
1040  << "\"";
1041  if (data_processing.metaValueExists("#intensity_cutoff"))
1042  {
1043  os << " intensityCutoff=\"" << data_processing.getMetaValue("#intensity_cutoff").toString() << "\"";
1044  }
1045  os << ">\n"
1046  << "\t\t\t<software type=\"";
1047  if (data_processing.metaValueExists("#type"))
1048  {
1049  os << data_processing.getMetaValue("#type").toString();
1050  }
1051  else
1052  {
1053  os << "processing";
1054  }
1055 
1056  os << "\" name=\"" << data_processing.getSoftware().getName()
1057  << "\" version=\"" << data_processing.getSoftware().getVersion();
1058 
1059  if (data_processing.getCompletionTime() != DateTime())
1060  {
1061  os << "\" completionTime=\"" << data_processing.getCompletionTime().get().substitute(' ', 'T');
1062  }
1063  os << "\"/>\n";
1064  writeUserParam_(os, data_processing, 3, "processingOperation");
1065 
1066  os << "\t\t</dataProcessing>\n";
1067  }
1068  }
1069 
1070  //check if the nativeID of all spectra are numbers or numbers prefixed with 'scan='
1071  //If not we need to renumber all spectra.
1072  bool all_numbers = true;
1073  bool all_empty = true;
1074  bool all_prefixed_numbers = true;
1075  for (Size s = 0; s < cexp_->size(); s++)
1076  {
1077  String native_id = (*cexp_)[s].getNativeID();
1078  if (!native_id.hasPrefix("scan="))
1079  {
1080  all_prefixed_numbers = false;
1081  }
1082  else
1083  {
1084  native_id = native_id.substr(5);
1085  }
1086  try
1087  {
1088  native_id.toInt();
1089  }
1091  {
1092  all_numbers = false;
1093  all_prefixed_numbers = false;
1094  if (native_id != "")
1095  {
1096  all_empty = false;
1097  }
1098  }
1099  }
1100  //If we need to renumber and the nativeIDs were not empty, warn the user
1101  if (!all_numbers && !all_empty)
1102  {
1103  warning(STORE, "Not all spectrum native IDs are numbers or correctly prefixed with 'scan='. The spectra are renumbered and the native IDs are lost!");
1104  }
1105 
1106  // write scans
1107  std::stack<UInt> open_scans;
1108  for (Size s = 0; s < cexp_->size(); s++)
1109  {
1110  logger_.setProgress(s);
1111  const SpectrumType& spec = (*cexp_)[s];
1112 
1113  UInt ms_level = spec.getMSLevel();
1114  open_scans.push(ms_level);
1115 
1116  Size spectrum_id = s + 1;
1117  if (all_prefixed_numbers)
1118  {
1119  spectrum_id = spec.getNativeID().substr(5).toInt();
1120  }
1121  else if (all_numbers)
1122  {
1123  spectrum_id = spec.getNativeID().toInt();
1124  }
1125 
1126  os << String(ms_level + 1, '\t')
1127  << "<scan num=\"" << spectrum_id << "\" msLevel=\""
1128  << ms_level << "\" peaksCount=\""
1129  << spec.size() << "\" polarity=\"";
1131  {
1132  os << "+";
1133  }
1135  {
1136  os << "-";
1137  }
1138  else
1139  {
1140  os << "any";
1141  }
1142 
1143  //scan type
1144  switch (spec.getInstrumentSettings().getScanMode())
1145  {
1147  break;
1148 
1152  if (spec.getInstrumentSettings().getZoomScan())
1153  {
1154  os << "\" scanType=\"zoom";
1155  }
1156  else
1157  {
1158  os << "\" scanType=\"Full";
1159  }
1160  break;
1161 
1163  os << "\" scanType=\"SIM";
1164  break;
1165 
1167  os << "\" scanType=\"SRM";
1168  break;
1169 
1171  os << "\" scanType=\"CRM";
1172  break;
1173 
1174  default:
1175  os << "\" scanType=\"Full";
1176  warning(STORE, String("Scan type '") + InstrumentSettings::NamesOfScanMode[spec.getInstrumentSettings().getScanMode()] + "' not supported by mzXML. Using 'Full' scan mode!");
1177  }
1178 
1179  os << "\" retentionTime=\"";
1180  if (spec.getRT() < 0)
1181  os << "-";
1182  os << "PT" << std::fabs(spec.getRT()) << "S\"";
1183  if (!spec.getInstrumentSettings().getScanWindows().empty())
1184  {
1185  os << " startMz=\"" << spec.getInstrumentSettings().getScanWindows()[0].begin << "\" endMz=\"" << spec.getInstrumentSettings().getScanWindows()[0].end << "\"";
1186  }
1187  if (spec.getInstrumentSettings().getScanWindows().size() > 1)
1188  {
1189  warning(STORE, "The MzXML format can store only one scan window for each scan. Only the first one is stored!");
1190  }
1191  os << ">\n";
1192 
1193 
1194  for (Size i = 0; i < spec.getPrecursors().size(); ++i)
1195  {
1196  const Precursor& precursor = spec.getPrecursors()[i];
1197  //intensity
1198  os << String(ms_level + 2, '\t') << "<precursorMz precursorIntensity=\"" << precursor.getIntensity();
1199  //charge
1200  if (precursor.getCharge() != 0)
1201  os << "\" precursorCharge=\"" << precursor.getCharge();
1202  //window size
1203  if (precursor.getIsolationWindowLowerOffset() != precursor.getIsolationWindowUpperOffset())
1204  os << "\" windowWideness=\"" << (precursor.getIsolationWindowUpperOffset() - precursor.getIsolationWindowLowerOffset());
1205  //m/z
1206  os << "\">" << precursor.getMZ() << "</precursorMz>\n";
1207  }
1208 
1209  if (!spec.empty())
1210  {
1211  os << String(ms_level + 2, '\t') << "<peaks precision=\"32\"" << " byteOrder=\"network\" pairOrder=\"m/z-int\">";
1212 
1213  //std::cout << "Writing scan " << s << "\n";
1214  std::vector<Real> tmp;
1215  for (Size i = 0; i < spec.size(); i++)
1216  {
1217  tmp.push_back(spec[i].getMZ());
1218  tmp.push_back(spec[i].getIntensity());
1219  }
1220 
1221  String encoded;
1222  decoder_.encode(tmp, Base64::BYTEORDER_BIGENDIAN, encoded);
1223  os << encoded << "</peaks>\n";
1224  }
1225  else
1226  {
1227  os << String(ms_level + 2, '\t') << "<peaks precision=\"32\"" << " byteOrder=\"network\" pairOrder=\"m/z-int\" xsi:nil=\"true\"/>\n";
1228  }
1229 
1230  writeUserParam_(os, spec, ms_level + 2);
1231  if (spec.getComment() != "")
1232  {
1233  os << String(ms_level + 2, '\t') << "<comment>" << spec.getComment() << "</comment>\n";
1234  }
1235 
1236  //check MS level of next scan and close scans (scans can be nested)
1237  UInt next_ms_level = 0;
1238  if (s < cexp_->size() - 1)
1239  {
1240  next_ms_level = ((*cexp_)[s + 1]).getMSLevel();
1241  }
1242  //std::cout << "scan: " << s << " this: " << ms_level << " next: " << next_ms_level << "\n";
1243  if (next_ms_level <= ms_level)
1244  {
1245  for (Size i = 0; i <= ms_level - next_ms_level && !open_scans.empty(); ++i)
1246  {
1247  os << String(ms_level - i + 1, '\t') << "</scan>\n";
1248  open_scans.pop();
1249  }
1250  }
1251  }
1252 
1253  os << "\t</msRun>\n"
1254  << "\t<indexOffset>0</indexOffset>\n"
1255  << "</mzXML>\n";
1256 
1257  logger_.endProgress();
1258  spec_write_counter_ = 1;
1259  }
1260 
1261  } // namespace Internal
1262 
1263 } // namespace OpenMS
1264 
1265 #endif
Deisotoping.
Definition: DataProcessing.h:62
const DataValue & getMetaValue(const String &name) const
returns the value corresponding to a string
Descripton of the applied preprocessing steps.
Definition: DataProcessing.h:51
String compressionType_
Definition: MzXMLHandler.h:181
ChecksumType getChecksumType() const
returns the checksum type
void writeUserParam_(std::ostream &os, const MetaInfoInterface &meta, int indent=4, String tag="nameValue")
write metaInfo to xml (usually in nameValue-tag)
Definition: MzXMLHandler.h:195
Big endian type.
Definition: Base64.h:78
Description of a MS instrument.
Definition: Instrument.h:64
const String & getNameOfFile() const
returns the file name
const Software & getSoftware() const
returns a const reference to the instrument software
static const XMLCh * s_count_
Definition: MzXMLHandler.h:217
A more convenient string class.
Definition: String.h:56
Precursor meta information.
Definition: Precursor.h:56
Class to encode and decode Base64.
Definition: Base64.h:64
String precision_
Definition: MzXMLHandler.h:180
Exception that is thrown if the parsing is ended by some event (e.g. if only a prefix of the XML file...
Definition: XMLHandler.h:94
const std::vector< IonSource > & getIonSources() const
returns a const reference to the ion source list
static const XMLCh * s_peakscount_
Definition: MzXMLHandler.h:233
UInt getMSLevel() const
Returns the MS level.
Definition: MSSpectrum.h:231
static const XMLCh * s_name_
Definition: MzXMLHandler.h:219
IntensityType getIntensity() const
Definition: Peak1D.h:103
static const XMLCh * s_first_
Definition: MzXMLHandler.h:239
static const XMLCh * s_phone_
Definition: MzXMLHandler.h:241
static const XMLCh * s_centroided_
Definition: MzXMLHandler.h:246
UInt spec_write_counter_
spectrum counter (spectra without peaks are not written)
Definition: MzXMLHandler.h:189
const std::set< ProcessingAction > & getProcessingActions() const
returns a const reference to the applied processing actions
static const XMLCh * s_precursorcharge_
Definition: MzXMLHandler.h:230
static const XMLCh * s_filesha1_
Definition: MzXMLHandler.h:223
SpectrumType::Iterator PeakIterator
Definition: MzXMLHandler.h:166
Contact person information.
Definition: ContactPerson.h:50
const String & getComment() const
returns the free-text comment
Negative polarity.
Definition: IonSource.h:144
const std::vector< MassAnalyzer > & getMassAnalyzers() const
returns a const reference to the mass analyer list
String toString() const
Conversion to String.
DoubleReal end
End of the window.
Definition: ScanWindow.h:64
Peak2D PeakType
Definition: MassTrace.h:49
void setFileType(const String &file_type)
sets the file type
XML handlers for MzXMLFile.
Definition: MzXMLHandler.h:60
CoordinateType getMZ() const
Non-mutable access to m/z.
Definition: Peak1D.h:108
Positive polarity.
Definition: IonSource.h:143
Definition: MassAnalyzer.h:70
Int getCharge() const
Non-mutable access to the charge.
virtual void startElement(const XMLCh *const uri, const XMLCh *const local_name, const XMLCh *const qname, const xercesc::Attributes &attributes)
Parsing method for opening tags.
Definition: MzXMLHandler.h:368
Base class for XML handlers.
Definition: XMLHandler.h:89
const std::vector< IonDetector > & getIonDetectors() const
returns a const reference to the ion detector list
Description of a file location, used to store the origin of (meta) data.
Definition: SourceFile.h:47
static const XMLCh * s_retentiontime_
Definition: MzXMLHandler.h:236
XMLHandler()
Not implemented.
bool has(Byte byte) const
true if String contains the byte, false otherwise
DoubleReal begin
Begin of the window.
Definition: ScanWindow.h:62
MS2+ mass spectrum, is a &quot;mass spectrum&quot;.
Definition: InstrumentSettings.h:58
ContainerType::iterator Iterator
Mutable iterator.
Definition: MSSpectrum.h:123
Type
Detector type.
Definition: IonDetector.h:52
Selected reaction monitoring scan Synonyms: &#39;Multiple reaction monitoring scan&#39;, &#39;SRM scan&#39;, &#39;MRM scan&#39;.
Definition: InstrumentSettings.h:60
void setChecksum(const String &checksum, ChecksumType type)
sets the file&#39;s checksum
static const XMLCh * s_scantype_
Definition: MzXMLHandler.h:235
const MapType * cexp_
map pointer for writing
Definition: MzXMLHandler.h:171
bool getZoomScan() const
return if this scan is a zoom (enhanced resolution) scan
ScanMode getScanMode() const
returns the scan mode
Definition: IonDetector.h:76
void get(UInt &month, UInt &day, UInt &year, UInt &hour, UInt &minute, UInt &second) const
Fills the arguments with the date and the time.
ResolutionMethod
resolution method
Definition: MassAnalyzer.h:80
static const XMLCh * s_polarity_
Definition: MzXMLHandler.h:234
virtual ~MzXMLHandler()
Destructor.
Definition: MzXMLHandler.h:97
Int toInt() const
Conversion to int.
void init_()
Definition: MzXMLHandler.h:123
const std::vector< ScanWindow > & getScanWindows() const
returns a const reference to the m/z scan windows
static const XMLCh * s_byteorder_
Definition: MzXMLHandler.h:226
static const XMLCh * s_completiontime_
Definition: MzXMLHandler.h:224
String & toLower()
Converts the string to lowercase.
bool hasSubstring(const String &string) const
true if String contains the string, false otherwise
PeakFileOptions options_
Options for loading and storing.
Definition: MzXMLHandler.h:174
static const XMLCh * s_num_
Definition: MzXMLHandler.h:244
const String & getModel() const
returns the instrument model
String & trim()
removes whitespaces (space, tab, line feed, carriage return) at the beginning and the end of the stri...
Scan window description.
Definition: ScanWindow.h:47
const String & getVendor() const
returns the instrument vendor
String char_rest_
Definition: MzXMLHandler.h:182
void setOptions(const PeakFileOptions &options)
Sets the options.
Definition: MzXMLHandler.h:116
static const XMLCh * s_value_
Definition: MzXMLHandler.h:216
full scan mass spectrum, is a &quot;mass spectrum&quot; Synonyms: &#39;full spectrum&#39;, &#39;Q1 spectrum&#39;, &#39;Q3 spectrum&#39;, &#39;Single-Stage Mass Spectrometry&#39;
Definition: InstrumentSettings.h:57
void getKeys(std::vector< String > &keys) const
fills the given vector with a list of all keys for which a value is set
DoubleReal getIsolationWindowUpperOffset() const
returns the upper offset from the target m/z
const Software & getSoftware() const
returns a const reference to the software used for processing
IonizationMethod
ionization method
Definition: IonSource.h:80
const String & getName() const
returns the name of the software
static const XMLCh * s_pairorder_
Definition: MzXMLHandler.h:227
Selected ion monitoring scan Synonyms: &#39;Multiple ion monitoring scan&#39;, &#39;SIM scan&#39;, &#39;MIM scan&#39;.
Definition: InstrumentSettings.h:59
UInt peak_count_
Definition: MzXMLHandler.h:179
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition: MetaInfoInterface.h:61
std::vector< DataProcessing > data_processing_
data processing auxilary variable
Definition: MzXMLHandler.h:210
Invalid conversion exception.
Definition: Exception.h:363
void setNameOfFile(const String &name_of_file)
sets the file name
static const XMLCh * s_version_
Definition: MzXMLHandler.h:220
const String & getFileType() const
returns the file type
MapType::PeakType PeakType
Peak type.
Definition: MzXMLHandler.h:162
Secure Hash Algorithm-1.
Definition: SourceFile.h:55
const String & getURL() const
returns the email address
static const XMLCh * s_last_
Definition: MzXMLHandler.h:240
Consecutive reaction monitoring scan Synonyms: &#39;CRM scan&#39;.
Definition: InstrumentSettings.h:61
const String & getFirstName() const
returns the first name of the person
const String & getVersion() const
returns the software version
const DateTime & getCompletionTime() const
returns the time of completition of the processing
IonSource::Polarity getPolarity() const
returns the polarity
MzXMLHandler(const MapType &exp, const String &filename, const String &version, const ProgressLogger &logger)
Constructor for a write-only handler.
Definition: MzXMLHandler.h:82
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:144
MSSpectrum< PeakType > SpectrumType
Spectrum type.
Definition: MzXMLHandler.h:164
Unknown scan method.
Definition: InstrumentSettings.h:55
String prefix(SizeType length) const
returns the prefix of length length
const String & getChecksum() const
returns the file&#39;s checksum
DateTime Class.
Definition: DateTime.h:55
Base class for all classes that want to report their progess.
Definition: ProgressLogger.h:56
String substr(size_t pos=0, size_t n=npos) const
Wrapper for the STL substr() method. Returns a String object with its contents initialized to a subst...
bool skip_spectrum_
Flag that indicates whether this spectrum should be skipped (due to options)
Definition: MzXMLHandler.h:186
const InstrumentSettings & getInstrumentSettings() const
returns a const reference to the instrument settings of the current spectrum
Peak picking (conversion from raw to peak data)
Definition: DataProcessing.h:67
static const XMLCh * s_startmz_
Definition: MzXMLHandler.h:237
Base64 decoder_
Definition: MzXMLHandler.h:178
static const XMLCh * s_type_
Definition: MzXMLHandler.h:218
general spectrum type
Definition: InstrumentSettings.h:56
DoubleReal getRT() const
Definition: MSSpectrum.h:215
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
Options for loading files containing peak data.
Definition: PeakFileOptions.h:47
std::vector< std::vector< String > > cv_terms_
Array of CV term lists (one sublist denotes one term and it&#39;s children)
Definition: XMLHandler.h:192
AnalyzerType
analyzer type
Definition: MassAnalyzer.h:53
virtual void endElement(const XMLCh *const uri, const XMLCh *const local_name, const XMLCh *const qname)
Parsing method for closing tags.
Definition: MzXMLHandler.h:740
const ProgressLogger & logger_
Progress logging class.
Definition: MzXMLHandler.h:192
static const std::string NamesOfScanMode[SIZE_OF_SCANMODE]
Names of scan modes.
Definition: InstrumentSettings.h:74
const String & getNativeID() const
returns the native identifier for the spectrum, used by the acquisition software. ...
bool metaValueExists(const String &name) const
returns if this MetaInfo is set
static const XMLCh * s_filename_
Definition: MzXMLHandler.h:221
virtual void characters(const XMLCh *const chars, const XMLSize_t length)
Parsing method for character data.
Definition: MzXMLHandler.h:826
String suffix(SizeType length) const
returns the suffix of length length
void initStaticMembers_()
Definition: MzXMLHandler.h:251
const String & getLastName() const
returns the last name of the person
int Int
Signed integer type.
Definition: Types.h:100
MapType * exp_
map pointer for reading
Definition: MzXMLHandler.h:169
static const XMLCh * s_endmz_
Definition: MzXMLHandler.h:238
static const XMLCh * s_deisotoped_
Definition: MzXMLHandler.h:247
bool split(const char splitter, std::vector< String > &substrings, bool quote_protect=false) const
Splits a string into substrings using splitter as delimiter.
const String & getEmail() const
returns the email address
static const XMLCh * s_uri_
Definition: MzXMLHandler.h:243
Charge deconvolution.
Definition: DataProcessing.h:61
MzXMLHandler()
Not implemented.
void writeTo(std::ostream &os)
Write the contents to a stream.
Definition: MzXMLHandler.h:885
DoubleReal getIsolationWindowLowerOffset() const
returns the lower offset from the target m/z
static const XMLCh * s_filetype_
Definition: MzXMLHandler.h:222
static const XMLCh * s_intensitycutoff_
Definition: MzXMLHandler.h:245
static const XMLCh * s_mslevel_
Definition: MzXMLHandler.h:232
static const XMLCh * s_email_
Definition: MzXMLHandler.h:242
Polarity
Polarity of the ion source.
Definition: IonSource.h:140
static const XMLCh * s_precursorintensity_
Definition: MzXMLHandler.h:229
static const XMLCh * s_compressionType_
Definition: MzXMLHandler.h:228
bool hasPrefix(const String &string) const
true if String begins with string, false otherwise
Parse Error exception.
Definition: Exception.h:608
static const XMLCh * s_windowwideness_
Definition: MzXMLHandler.h:231
static const XMLCh * s_chargedeconvoluted_
Definition: MzXMLHandler.h:248
static const XMLCh * s_precision_
Definition: MzXMLHandler.h:225

OpenMS / TOPP release 1.11.1 Documentation generated on Thu Nov 14 2013 11:19:18 using doxygen 1.8.5