Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
MzMLHandler.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-2016.
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_MZMLHANDLER_H
36 #define OPENMS_FORMAT_HANDLERS_MZMLHANDLER_H
37 
41 
43 
45 
47 
52 #include <OpenMS/FORMAT/Base64.h>
58 #include <OpenMS/CONCEPT/Helpers.h>
59 
60 #include <OpenMS/SYSTEM/File.h>
61 
62 #include <sstream>
63 #include <boost/shared_ptr.hpp>
64 #include <iostream>
65 
66 #include <QRegExp>
67 
68 //MISSING:
69 // - more than one selected ion per precursor (warning if more than one)
70 // - scanWindowList for each acquisition separately (currently for the whole spectrum only)
71 // - instrumentConfigurationRef attribute for scan (why should the instrument change between scans? - warning if used)
72 // - scanSettingsRef attribute for instrumentConfiguration tag (currently no information there because of missing mapping file entry - warning if used)
73 
74 // xs:id/xs:idref prefix list
75 // - sf_ru : sourceFile (run)
76 // - sf_sp : sourceFile (spectrum)
77 // - sf_pr : sourceFile (precursor)
78 // - sf_ac : sourceFile (acquisition)
79 // - sa : sample
80 // - ic : instrumentConfiguration
81 // - so_dp : software (data processing)
82 // - so_in : software (instrument)
83 // - dp_sp : dataProcessing (spectrum)
84 // - dp_bi : dataProcessing (binary data array)
85 // - dp_ch : dataProcessing (chromatogram)
86 
87 namespace OpenMS
88 {
89  class ControlledVocabulary;
90  namespace Internal
91  {
92 
109  template <typename MapType>
110  class MzMLHandler :
111  public XMLHandler
112  {
113 public:
116 
118  MzMLHandler(MapType& exp, const String& filename, const String& version, ProgressLogger& logger) :
119  XMLHandler(filename, version),
120  exp_(&exp),
121  cexp_(0),
122  options_(),
123  spec_(),
124  chromatogram_(),
125  data_(),
127  in_spectrum_list_(false),
128  decoder_(),
129  logger_(logger),
130  consumer_(NULL),
131  scan_count(0),
133  skip_chromatogram_(false),
134  skip_spectrum_(false),
135  rt_set_(false) /* ,
136  validator_(mapping_, cv_) */
137  {
138  cv_.loadFromOBO("MS", File::find("/CV/psi-ms.obo"));
139  cv_.loadFromOBO("PATO", File::find("/CV/quality.obo"));
140  cv_.loadFromOBO("UO", File::find("/CV/unit.obo"));
141  cv_.loadFromOBO("BTO", File::find("/CV/brenda.obo"));
142  cv_.loadFromOBO("GO", File::find("/CV/goslim_goa.obo"));
143 
144  CVMappingFile().load(File::find("/MAPPING/ms-mapping.xml"), mapping_);
145  //~ validator_ = Internal::MzMLValidator(mapping_, cv_);
146 
147  // check the version number of the mzML handler
149  {
150  LOG_ERROR << "MzMLHandler was initialized with an invalid version number: " << version_ << std::endl;
151  }
152  }
153 
155  MzMLHandler(const MapType& exp, const String& filename, const String& version, const ProgressLogger& logger) :
156  XMLHandler(filename, version),
157  exp_(0),
158  cexp_(&exp),
159  options_(),
160  spec_(),
161  chromatogram_(),
162  data_(),
164  in_spectrum_list_(false),
165  decoder_(),
166  logger_(logger),
167  consumer_(NULL),
168  scan_count(0),
170  skip_chromatogram_(false),
171  skip_spectrum_(false),
172  rt_set_(false) /* ,
173  validator_(mapping_, cv_) */
174  {
175  cv_.loadFromOBO("MS", File::find("/CV/psi-ms.obo"));
176  cv_.loadFromOBO("PATO", File::find("/CV/quality.obo"));
177  cv_.loadFromOBO("UO", File::find("/CV/unit.obo"));
178  cv_.loadFromOBO("BTO", File::find("/CV/brenda.obo"));
179  cv_.loadFromOBO("GO", File::find("/CV/goslim_goa.obo"));
180 
181  CVMappingFile().load(File::find("/MAPPING/ms-mapping.xml"), mapping_);
182  //~ validator_ = Internal::MzMLValidator(mapping_, cv_);
183 
184  // check the version number of the mzML handler
186  {
187  LOG_ERROR << "MzMLHandler was initialized with an invalid version number: " << version_ << std::endl;
188  }
189  }
190 
192  virtual ~MzMLHandler() {}
194 
197 
198  // Docu in base class
199  virtual void endElement(const XMLCh* const /*uri*/, const XMLCh* const /*local_name*/, const XMLCh* const qname);
200 
201  // Docu in base class
202  virtual void startElement(const XMLCh* const /*uri*/, const XMLCh* const /*local_name*/, const XMLCh* const qname, const xercesc::Attributes& attributes);
203 
204  // Docu in base class
205  virtual void characters(const XMLCh* const chars, const XMLSize_t length);
206 
207  //Docu in base class
208  virtual void writeTo(std::ostream& os);
209 
211 
222 
224  void setOptions(const PeakFileOptions& opt)
225  {
226  options_ = opt;
229  }
230 
233  {
234  return options_;
235  }
236 
238 
240  void getCounts(Size& spectra_counts, Size& chromatogram_counts)
241  {
242  spectra_counts = scan_count;
243  chromatogram_counts = chromatogram_count;
244  }
245 
248  {
249  consumer_ = consumer;
250  }
251 
252 protected:
253 
255  typedef typename MapType::PeakType PeakType;
262 
264 
265  void writeSpectrum_(std::ostream& os, const SpectrumType& spec, Size s,
266  Internal::MzMLValidator& validator, bool renew_native_ids,
267  std::vector<std::vector< ConstDataProcessingPtr > >& dps);
268 
269  void writeChromatogram_(std::ostream& os, const ChromatogramType& chromatogram, Size c, Internal::MzMLValidator& validator);
270 
271  template <typename ContainerT>
272  void writeContainerData(std::ostream& os, const PeakFileOptions& pf_options_, const ContainerT& container, String array_type)
273  {
274 
275  bool is32Bit = ((array_type == "intensity" && pf_options_.getIntensity32Bit()) || pf_options_.getMz32Bit());
277  {
278  std::vector<double> data_to_encode(container.size());
279  if (array_type == "intensity")
280  {
281  for (Size p = 0; p < container.size(); ++p)
282  {
283  data_to_encode[p] = container[p].getIntensity();
284  }
285  }
286  else
287  {
288  for (Size p = 0; p < container.size(); ++p)
289  {
290  data_to_encode[p] = container[p].getMZ();
291  }
292  }
293  writeBinaryDataArray(os, pf_options_, data_to_encode, false, array_type);
294  }
295  else
296  {
297  std::vector<float> data_to_encode(container.size());
298 
299  if (array_type == "intensity")
300  {
301  for (Size p = 0; p < container.size(); ++p)
302  {
303  data_to_encode[p] = container[p].getIntensity();
304  }
305  }
306  else
307  {
308  for (Size p = 0; p < container.size(); ++p)
309  {
310  data_to_encode[p] = container[p].getMZ();
311  }
312  }
313  writeBinaryDataArray(os, pf_options_, data_to_encode, true, array_type);
314  }
315 
316  }
317 
325  {
326 
327  // Whether spectrum should be populated with data
328  if (options_.getFillData())
329  {
330  size_t errCount = 0;
331 #ifdef _OPENMP
332 #pragma omp parallel for
333 #endif
334  for (SignedSize i = 0; i < (SignedSize)spectrum_data_.size(); i++)
335  {
336  // parallel exception catching and re-throwing business
337  if (!errCount) // no need to parse further if already an error was encountered
338  {
339  try
340  {
342  spectrum_data_[i].default_array_length, options_,
343  spectrum_data_[i].spectrum);
344  if (options_.getSortSpectraByMZ() && !spectrum_data_[i].spectrum.isSorted())
345  {
346  spectrum_data_[i].spectrum.sortByPosition();
347  }
348  }
349  catch (...)
350  {
351 #pragma omp critical(HandleException)
352  ++errCount;
353  }
354  }
355  }
356  if (errCount != 0)
357  {
358  throw Exception::ParseError(__FILE__, __LINE__, __PRETTY_FUNCTION__, file_, "Error during parsing of binary data.");
359  }
360  }
361 
362  // Append all spectra to experiment / consumer
363  for (Size i = 0; i < spectrum_data_.size(); i++)
364  {
365  if (consumer_ != NULL)
366  {
367  consumer_->consumeSpectrum(spectrum_data_[i].spectrum);
369  {
370  exp_->addSpectrum(spectrum_data_[i].spectrum);
371  }
372  }
373  else
374  {
375  exp_->addSpectrum(spectrum_data_[i].spectrum);
376  }
377  }
378 
379  // Delete batch
380  spectrum_data_.clear();
381  }
382 
390  {
391  // Whether chromatogram should be populated with data
392  if (options_.getFillData())
393  {
394  size_t errCount = 0;
395 #ifdef _OPENMP
396 #pragma omp parallel for
397 #endif
398  for (SignedSize i = 0; i < (SignedSize)chromatogram_data_.size(); i++)
399  {
400  // parallel exception catching and re-throwing business
401  try
402  {
404  chromatogram_data_[i].default_array_length, options_,
405  chromatogram_data_[i].chromatogram);
406  if (options_.getSortChromatogramsByRT() && !chromatogram_data_[i].chromatogram.isSorted())
407  {
408  chromatogram_data_[i].chromatogram.sortByPosition();
409  }
410  }
411  catch (...)
412  {++errCount; }
413  }
414  if (errCount != 0)
415  {
416  throw Exception::ParseError(__FILE__, __LINE__, __PRETTY_FUNCTION__, file_, "Error during parsing of binary data.");
417  }
418 
419  }
420 
421  // Append all chromatograms to experiment / consumer
422  for (Size i = 0; i < chromatogram_data_.size(); i++)
423  {
424  if (consumer_ != NULL)
425  {
426  consumer_->consumeChromatogram(chromatogram_data_[i].chromatogram);
428  {
429  exp_->addChromatogram(chromatogram_data_[i].chromatogram);
430  }
431  }
432  else
433  {
434  exp_->addChromatogram(chromatogram_data_[i].chromatogram);
435  }
436  }
437 
438  // Delete batch
439  chromatogram_data_.clear();
440  }
441 
442  template <typename SpectrumType>
443  void addSpectrumMetaData_(const std::vector<MzMLHandlerHelper::BinaryData>& input_data,
444  const Size n, SpectrumType& spectrum) const
445  {
446 
447  //add meta data
448  UInt meta_float_array_index = 0;
449  UInt meta_int_array_index = 0;
450  UInt meta_string_array_index = 0;
451  for (Size i = 0; i < input_data.size(); i++) //loop over all binary data arrays
452  {
453  if (input_data[i].meta.getName() != "m/z array" && input_data[i].meta.getName() != "intensity array") // is meta data array?
454  {
455  if (input_data[i].data_type == MzMLHandlerHelper::BinaryData::DT_FLOAT)
456  {
457  if (n < input_data[i].size)
458  {
459  double value = (input_data[i].precision == MzMLHandlerHelper::BinaryData::PRE_64) ? input_data[i].floats_64[n] : input_data[i].floats_32[n];
460  spectrum.getFloatDataArrays()[meta_float_array_index].push_back(value);
461  }
462  ++meta_float_array_index;
463  }
464  else if (input_data[i].data_type == MzMLHandlerHelper::BinaryData::DT_INT)
465  {
466  if (n < input_data[i].size)
467  {
468  Int64 value = (input_data[i].precision == MzMLHandlerHelper::BinaryData::PRE_64) ? input_data[i].ints_64[n] : input_data[i].ints_32[n];
469  spectrum.getIntegerDataArrays()[meta_int_array_index].push_back(value);
470  }
471  ++meta_int_array_index;
472  }
473  else if (input_data[i].data_type == MzMLHandlerHelper::BinaryData::DT_STRING)
474  {
475  if (n < input_data[i].decoded_char.size())
476  {
477  String value = input_data[i].decoded_char[n];
478  spectrum.getStringDataArrays()[meta_string_array_index].push_back(value);
479  }
480  ++meta_string_array_index;
481  }
482  }
483  }
484  }
485 
496  template <typename SpectrumType>
497  void populateSpectraWithData_(std::vector<MzMLHandlerHelper::BinaryData>& input_data,
498  Size& default_arr_length, const PeakFileOptions& peak_file_options,
499  SpectrumType& spectrum)
500  {
501  typedef typename SpectrumType::PeakType PeakType;
502 
503  //decode all base64 arrays
505 
506  //look up the precision and the index of the intensity and m/z array
507  bool mz_precision_64 = true;
508  bool int_precision_64 = true;
509  SignedSize mz_index = -1;
510  SignedSize int_index = -1;
511  MzMLHandlerHelper::computeDataProperties_(input_data, mz_precision_64, mz_index, "m/z array");
512  MzMLHandlerHelper::computeDataProperties_(input_data, int_precision_64, int_index, "intensity array");
513 
514  //Abort if no m/z or intensity array is present
515  if (int_index == -1 || mz_index == -1)
516  {
517  //if defaultArrayLength > 0 : warn that no m/z or int arrays is present
518  if (default_arr_length != 0)
519  {
520  warning(LOAD, String("The m/z or intensity array of spectrum '") + spectrum.getNativeID() + "' is missing and default_arr_length is " + default_arr_length + ".");
521  }
522  return;
523  }
524 
525  // Error if intensity or m/z is encoded as int32|64 - they should be float32|64!
526  if ((input_data[mz_index].ints_32.size() > 0) || (input_data[mz_index].ints_64.size() > 0))
527  {
528  fatalError(LOAD, "Encoding m/z array as integer is not allowed!");
529  }
530  if ((input_data[int_index].ints_32.size() > 0) || (input_data[int_index].ints_64.size() > 0))
531  {
532  fatalError(LOAD, "Encoding intensity array as integer is not allowed!");
533  }
534 
535  // Warn if the decoded data has a different size than the defaultArrayLength
536  Size mz_size = mz_precision_64 ? input_data[mz_index].floats_64.size() : input_data[mz_index].floats_32.size();
537  Size int_size = int_precision_64 ? input_data[int_index].floats_64.size() : input_data[int_index].floats_32.size();
538  // Check if int-size and mz-size are equal
539  if (mz_size != int_size)
540  {
541  fatalError(LOAD, String("The length of m/z and integer values of spectrum '") + spectrum.getNativeID() + "' differ (mz-size: " + mz_size + ", int-size: " + int_size + "! Not reading spectrum!");
542  }
543  bool repair_array_length = false;
544  if (default_arr_length != mz_size)
545  {
546  warning(LOAD, String("The m/z array of spectrum '") + spectrum.getNativeID() + "' has the size " + mz_size + ", but it should have size " + default_arr_length + " (defaultArrayLength).");
547  repair_array_length = true;
548  }
549  if (default_arr_length != int_size)
550  {
551  warning(LOAD, String("The intensity array of spectrum '") + spectrum.getNativeID() + "' has the size " + int_size + ", but it should have size " + default_arr_length + " (defaultArrayLength).");
552  repair_array_length = true;
553  }
554  if (repair_array_length)
555  {
556  default_arr_length = int_size;
557  warning(LOAD, String("Fixing faulty defaultArrayLength to ") + default_arr_length + ".");
558  }
559 
560  //create meta data arrays and reserve enough space for the content
561  if (input_data.size() > 2)
562  {
563  for (Size i = 0; i < input_data.size(); i++)
564  {
565  if (input_data[i].meta.getName() != "m/z array" && input_data[i].meta.getName() != "intensity array")
566  {
567  if (input_data[i].data_type == MzMLHandlerHelper::BinaryData::DT_FLOAT)
568  {
569  //create new array
570  spectrum.getFloatDataArrays().resize(spectrum.getFloatDataArrays().size() + 1);
571  //reserve space in the array
572  spectrum.getFloatDataArrays().back().reserve(input_data[i].size);
573  //copy meta info into MetaInfoDescription
574  spectrum.getFloatDataArrays().back().MetaInfoDescription::operator=(input_data[i].meta);
575  }
576  else if (input_data[i].data_type == MzMLHandlerHelper::BinaryData::DT_INT)
577  {
578  //create new array
579  spectrum.getIntegerDataArrays().resize(spectrum.getIntegerDataArrays().size() + 1);
580  //reserve space in the array
581  spectrum.getIntegerDataArrays().back().reserve(input_data[i].size);
582  //copy meta info into MetaInfoDescription
583  spectrum.getIntegerDataArrays().back().MetaInfoDescription::operator=(input_data[i].meta);
584  }
585  else if (input_data[i].data_type == MzMLHandlerHelper::BinaryData::DT_STRING)
586  {
587  //create new array
588  spectrum.getStringDataArrays().resize(spectrum.getStringDataArrays().size() + 1);
589  //reserve space in the array
590  spectrum.getStringDataArrays().back().reserve(input_data[i].decoded_char.size());
591  //copy meta info into MetaInfoDescription
592  spectrum.getStringDataArrays().back().MetaInfoDescription::operator=(input_data[i].meta);
593  }
594  }
595  }
596  }
597 
598  // Copy meta data from m/z and intensity binary
599  // We don't have this as a separate location => store it in spectrum
600  for (Size i = 0; i < input_data.size(); i++)
601  {
602  if (input_data[i].meta.getName() == "m/z array" || input_data[i].meta.getName() == "intensity array")
603  {
604  std::vector<UInt> keys;
605  input_data[i].meta.getKeys(keys);
606  for (Size k = 0; k < keys.size(); ++k)
607  {
608  spectrum.setMetaValue(keys[k], input_data[i].meta.getMetaValue(keys[k]));
609  }
610  }
611  }
612 
613  // We found that the push back approach is about 5% faster than using
614  // iterators (e.g. spectrum iterator that gets updated)
615 
616  //add the peaks and the meta data to the container (if they pass the restrictions)
617  PeakType tmp;
618  spectrum.reserve(default_arr_length);
619 
620  // the most common case: no ranges, 64 / 32 precision
621  // -> this saves about 10 % load time
622  if ( mz_precision_64 && !int_precision_64 &&
623  input_data.size() == 2 &&
624  !peak_file_options.hasMZRange() &&
625  !peak_file_options.hasIntensityRange()
626  )
627  {
628  std::vector< double >::iterator mz_it = input_data[mz_index].floats_64.begin();
629  std::vector< float >::iterator int_it = input_data[int_index].floats_32.begin();
630  for (Size n = 0; n < default_arr_length; n++)
631  {
632  //add peak
633  tmp.setIntensity(*int_it);
634  tmp.setMZ(*mz_it);
635  ++mz_it;
636  ++int_it;
637  spectrum.push_back(tmp);
638  }
639  return;
640  }
641 
642  for (Size n = 0; n < default_arr_length; n++)
643  {
644  double mz = mz_precision_64 ? input_data[mz_index].floats_64[n] : input_data[mz_index].floats_32[n];
645  double intensity = int_precision_64 ? input_data[int_index].floats_64[n] : input_data[int_index].floats_32[n];
646  if ((!peak_file_options.hasMZRange() || peak_file_options.getMZRange().encloses(DPosition<1>(mz)))
647  && (!peak_file_options.hasIntensityRange() || peak_file_options.getIntensityRange().encloses(DPosition<1>(intensity))))
648  {
649  //add peak
650  tmp.setIntensity(intensity);
651  tmp.setMZ(mz);
652  spectrum.push_back(tmp);
653 
654  // Only if there are more than 2 data arrays, we need to check
655  // for meta data (as there will always be an m/z and intensity
656  // array)
657  if (input_data.size() > 2)
658  {
659  addSpectrumMetaData_(input_data, n, spectrum);
660  }
661  }
662  }
663  }
664 
672  template <typename ChromatogramType>
673  void populateChromatogramsWithData_(std::vector<MzMLHandlerHelper::BinaryData>& input_data,
674  Size& default_arr_length, const PeakFileOptions& peak_file_options,
675  ChromatogramType& inp_chromatogram)
676  {
678 
679  //decode all base64 arrays
681 
682  //look up the precision and the index of the intensity and m/z array
683  bool int_precision_64 = true;
684  bool rt_precision_64 = true;
685  SignedSize int_index = -1;
686  SignedSize rt_index = -1;
687  MzMLHandlerHelper::computeDataProperties_(input_data, rt_precision_64, rt_index, "time array");
688  MzMLHandlerHelper::computeDataProperties_(input_data, int_precision_64, int_index, "intensity array");
689 
690  //Abort if no m/z or intensity array is present
691  if (int_index == -1 || rt_index == -1)
692  {
693  //if defaultArrayLength > 0 : warn that no m/z or int arrays is present
694  if (default_arr_length != 0)
695  {
696  warning(LOAD, String("The m/z or intensity array of chromatogram '") + inp_chromatogram.getNativeID() + "' is missing and default_arr_length is " + default_arr_length + ".");
697  }
698  return;
699  }
700 
701  //Warn if the decoded data has a different size than the defaultArrayLength
702  Size rt_size = rt_precision_64 ? input_data[rt_index].floats_64.size() : input_data[rt_index].floats_32.size();
703  if (default_arr_length != rt_size)
704  {
705  warning(LOAD, String("The base64-decoded rt array of chromatogram '") + inp_chromatogram.getNativeID() + "' has the size " + rt_size + ", but it should have size " + default_arr_length + " (defaultArrayLength).");
706  }
707  Size int_size = int_precision_64 ? input_data[int_index].floats_64.size() : input_data[int_index].floats_32.size();
708  if (default_arr_length != int_size)
709  {
710  warning(LOAD, String("The base64-decoded intensity array of chromatogram '") + inp_chromatogram.getNativeID() + "' has the size " + int_size + ", but it should have size " + default_arr_length + " (defaultArrayLength).");
711  }
712 
713  //create meta data arrays and reserve enough space for the content
714  if (input_data.size() > 2)
715  {
716  for (Size i = 0; i < input_data.size(); i++)
717  {
718  if (input_data[i].meta.getName() != "intensity array" && input_data[i].meta.getName() != "time array")
719  {
720  if (input_data[i].data_type == MzMLHandlerHelper::BinaryData::DT_FLOAT)
721  {
722  //create new array
723  inp_chromatogram.getFloatDataArrays().resize(inp_chromatogram.getFloatDataArrays().size() + 1);
724  //reserve space in the array
725  inp_chromatogram.getFloatDataArrays().back().reserve(input_data[i].size);
726  //copy meta info into MetaInfoDescription
727  inp_chromatogram.getFloatDataArrays().back().MetaInfoDescription::operator=(input_data[i].meta);
728  }
729  else if (input_data[i].data_type == MzMLHandlerHelper::BinaryData::DT_INT)
730  {
731  //create new array
732  inp_chromatogram.getIntegerDataArrays().resize(inp_chromatogram.getIntegerDataArrays().size() + 1);
733  //reserve space in the array
734  inp_chromatogram.getIntegerDataArrays().back().reserve(input_data[i].size);
735  //copy meta info into MetaInfoDescription
736  inp_chromatogram.getIntegerDataArrays().back().MetaInfoDescription::operator=(input_data[i].meta);
737  }
738  else if (input_data[i].data_type == MzMLHandlerHelper::BinaryData::DT_STRING)
739  {
740  //create new array
741  inp_chromatogram.getStringDataArrays().resize(inp_chromatogram.getStringDataArrays().size() + 1);
742  //reserve space in the array
743  inp_chromatogram.getStringDataArrays().back().reserve(input_data[i].decoded_char.size());
744  //copy meta info into MetaInfoDescription
745  inp_chromatogram.getStringDataArrays().back().MetaInfoDescription::operator=(input_data[i].meta);
746  }
747  }
748  }
749  }
750 
751  //copy meta data from time and intensity binary
752  //We don't have this as a separate location => store it in spectrum
753  for (Size i = 0; i < input_data.size(); i++)
754  {
755  if (input_data[i].meta.getName() == "time array" || input_data[i].meta.getName() == "intensity array")
756  {
757  std::vector<UInt> keys;
758  input_data[i].meta.getKeys(keys);
759  for (Size k = 0; k < keys.size(); ++k)
760  {
761  inp_chromatogram.setMetaValue(keys[k], input_data[i].meta.getMetaValue(keys[k]));
762  }
763  }
764  }
765 
766  //add the peaks and the meta data to the container (if they pass the restrictions)
767  inp_chromatogram.reserve(default_arr_length);
768  ChromatogramPeakType tmp;
769  for (Size n = 0; n < default_arr_length; n++)
770  {
771  double rt = rt_precision_64 ? input_data[rt_index].floats_64[n] : input_data[rt_index].floats_32[n];
772  double intensity = int_precision_64 ? input_data[int_index].floats_64[n] : input_data[int_index].floats_32[n];
773  if ((!peak_file_options.hasRTRange() || peak_file_options.getRTRange().encloses(DPosition<1>(rt)))
774  && (!peak_file_options.hasIntensityRange() || peak_file_options.getIntensityRange().encloses(DPosition<1>(intensity))))
775  {
776  //add peak
777  tmp.setIntensity(intensity);
778  tmp.setRT(rt);
779  inp_chromatogram.push_back(tmp);
780 
781  //add meta data
782  UInt meta_float_array_index = 0;
783  UInt meta_int_array_index = 0;
784  UInt meta_string_array_index = 0;
785  for (Size i = 0; i < input_data.size(); i++) //loop over all binary data arrays
786  {
787  if (input_data[i].meta.getName() != "intensity array" && input_data[i].meta.getName() != "time array") // is meta data array?
788  {
789  if (input_data[i].data_type == MzMLHandlerHelper::BinaryData::DT_FLOAT)
790  {
791  if (n < input_data[i].size)
792  {
793  double value = (input_data[i].precision == MzMLHandlerHelper::BinaryData::PRE_64) ? input_data[i].floats_64[n] : input_data[i].floats_32[n];
794  inp_chromatogram.getFloatDataArrays()[meta_float_array_index].push_back(value);
795  }
796  ++meta_float_array_index;
797  }
798  else if (input_data[i].data_type == MzMLHandlerHelper::BinaryData::DT_INT)
799  {
800  if (n < input_data[i].size)
801  {
802  Int64 value = (input_data[i].precision == MzMLHandlerHelper::BinaryData::PRE_64) ? input_data[i].ints_64[n] : input_data[i].ints_32[n];
803  inp_chromatogram.getIntegerDataArrays()[meta_int_array_index].push_back(value);
804  }
805  ++meta_int_array_index;
806  }
807  else if (input_data[i].data_type == MzMLHandlerHelper::BinaryData::DT_STRING)
808  {
809  if (n < input_data[i].decoded_char.size())
810  {
811  String value = input_data[i].decoded_char[n];
812  inp_chromatogram.getStringDataArrays()[meta_string_array_index].push_back(value);
813  }
814  ++meta_string_array_index;
815  }
816  }
817  }
818  }
819  }
820  }
821 
822  template <typename DataType>
823  void writeBinaryDataArray(std::ostream& os, const PeakFileOptions& pf_options_, std::vector<DataType> data_to_encode, bool is32bit, String array_type)
824  {
825  String encoded_string;
826  bool no_numpress = true;
827 
828  // Compute the array-type and the compression CV term
829  String cv_term_type;
830  String compression_term;
831  String compression_term_no_np;
833  if (array_type == "mz")
834  {
835  cv_term_type = "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000514\" name=\"m/z array\" unitAccession=\"MS:1000040\" unitName=\"m/z\" unitCvRef=\"MS\" />\n";
836  compression_term = MzMLHandlerHelper::getCompressionTerm_(pf_options_, pf_options_.getNumpressConfigurationMassTime(), true);
837  compression_term_no_np = MzMLHandlerHelper::getCompressionTerm_(pf_options_, pf_options_.getNumpressConfigurationMassTime(), false);
838  np_config = pf_options_.getNumpressConfigurationMassTime();
839  }
840  else if (array_type == "time")
841  {
842  cv_term_type = "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000595\" name=\"time array\" unitAccession=\"UO:0000010\" unitName=\"second\" unitCvRef=\"MS\" />\n";
843  compression_term = MzMLHandlerHelper::getCompressionTerm_(pf_options_, pf_options_.getNumpressConfigurationMassTime(), true);
844  compression_term_no_np = MzMLHandlerHelper::getCompressionTerm_(pf_options_, pf_options_.getNumpressConfigurationMassTime(), false);
845  np_config = pf_options_.getNumpressConfigurationMassTime();
846  }
847  else if (array_type == "intensity")
848  {
849  cv_term_type = "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000515\" name=\"intensity array\" unitAccession=\"MS:1000131\" unitName=\"number of detector counts\" unitCvRef=\"MS\"/>\n";
850  compression_term = MzMLHandlerHelper::getCompressionTerm_(pf_options_, pf_options_.getNumpressConfigurationIntensity(), true);
851  compression_term_no_np = MzMLHandlerHelper::getCompressionTerm_(pf_options_, pf_options_.getNumpressConfigurationIntensity(), false);
852  np_config = pf_options_.getNumpressConfigurationIntensity();
853  }
854  else
855  {
856  throw Exception::InvalidValue(__FILE__, __LINE__, __PRETTY_FUNCTION__, "Unknown array type", array_type);
857  }
858 
859  // Try numpress encoding (if it is enabled) and fall back to regular encoding if it fails
860  if (np_config.np_compression != MSNumpressCoder::NONE)
861  {
862  MSNumpressCoder().encodeNP(data_to_encode, encoded_string, pf_options_.getCompression(), np_config);
863  if (!encoded_string.empty())
864  {
865  // numpress succeeded
866  no_numpress = false;
867  os << "\t\t\t\t\t<binaryDataArray encodedLength=\"" << encoded_string.size() << "\">\n";
868  os << cv_term_type;
869  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000523\" name=\"64-bit float\" />\n";
870  }
871  }
872 
873  // Regular DataArray without numpress (either 32 or 64 bit encoded)
874  if (is32bit && no_numpress)
875  {
876  compression_term = compression_term_no_np; // select the no-numpress term
877  decoder_.encode(data_to_encode, Base64::BYTEORDER_LITTLEENDIAN, encoded_string, pf_options_.getCompression());
878  os << "\t\t\t\t\t<binaryDataArray encodedLength=\"" << encoded_string.size() << "\">\n";
879  os << cv_term_type;
880  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000521\" name=\"32-bit float\" />\n";
881  }
882  else if (!is32bit && no_numpress)
883  {
884  compression_term = compression_term_no_np; // select the no-numpress term
885  decoder_.encode(data_to_encode, Base64::BYTEORDER_LITTLEENDIAN, encoded_string, pf_options_.getCompression());
886  os << "\t\t\t\t\t<binaryDataArray encodedLength=\"" << encoded_string.size() << "\">\n";
887  os << cv_term_type;
888  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000523\" name=\"64-bit float\" />\n";
889  }
890 
891  os << "\t\t\t\t\t\t" << compression_term << "\n";
892  os << "\t\t\t\t\t\t<binary>" << encoded_string << "</binary>\n";
893  os << "\t\t\t\t\t</binaryDataArray>\n";
894  }
895 
896  void writeHeader_(std::ostream& os, const MapType& exp, std::vector<std::vector< ConstDataProcessingPtr > >& dps, Internal::MzMLValidator& validator);
897 
901  const MapType* cexp_;
902 
905 
908  SpectrumType spec_;
911  ChromatogramType chromatogram_;
913  std::vector<BinaryData> data_;
934 
943  {
944  std::vector<BinaryData> data;
946  SpectrumType spectrum;
947  bool skip_data;
948  };
949 
951  std::vector<SpectrumData> spectrum_data_;
952 
961  {
962  std::vector<BinaryData> data;
964  ChromatogramType chromatogram;
965  };
966 
968  std::vector<ChromatogramData> chromatogram_data_;
969 
971 
973  std::vector<std::pair<std::string, long> > spectra_offsets;
974  std::vector<std::pair<std::string, long> > chromatograms_offsets;
976 
979 
982 
985 
989 
993 
994  // Remember whether the RT of the spectrum was set or not
995  bool rt_set_;
996 
1000  //~ Internal::MzMLValidator validator_;
1001 
1004 
1005  /*
1007  void fillData_();
1008  */
1009 
1011  void fillChromatogramData_();
1012 
1014  void handleCVParam_(const String& parent_parent_tag, const String& parent_tag, /* const String & cvref, */ const String& accession, const String& name, const String& value, const String& unit_accession = "");
1015 
1017  void handleUserParam_(const String& parent_parent_tag, const String& parent_tag, const String& name, const String& type, const String& value);
1018 
1020  void writeUserParam_(std::ostream& os, const MetaInfoInterface& meta, UInt indent, String path, Internal::MzMLValidator& validator) const;
1021 
1023  ControlledVocabulary::CVTerm getChildWithName_(const String& parent_accession, const String& name) const;
1024 
1026  void writeSoftware_(std::ostream& os, const String& id, const Software& software, Internal::MzMLValidator& validator);
1027 
1029  void writeSourceFile_(std::ostream& os, const String& id, const SourceFile& software, Internal::MzMLValidator& validator);
1030 
1032  void writeDataProcessing_(std::ostream& os, const String& id, const std::vector< ConstDataProcessingPtr >& dps, Internal::MzMLValidator& validator);
1033 
1035  void writePrecursor_(std::ostream& os, const Precursor& precursor, Internal::MzMLValidator& validator);
1036 
1038  void writeProduct_(std::ostream& os, const Product& product, Internal::MzMLValidator& validator);
1039 
1041  String writeCV_(const ControlledVocabulary::CVTerm& c, const DataValue& metaValue) const;
1042 
1044  bool validateCV_(const ControlledVocabulary::CVTerm& c, const String& path, const Internal::MzMLValidator& validator) const;
1045  };
1046 
1047  //--------------------------------------------------------------------------------
1048 
1049  template <typename MapType>
1050  void MzMLHandler<MapType>::characters(const XMLCh* const chars, const XMLSize_t length)
1051  {
1052 
1053  if (skip_spectrum_ || skip_chromatogram_)
1054  return;
1055 
1056  String& current_tag = open_tags_.back();
1057 
1058  if (current_tag == "binary")
1059  {
1060  // Since we convert a Base64 string here, it can only contain plain ASCII
1061  sm_.appendASCII(chars, length, data_.back().base64);
1062  }
1063  else if (current_tag == "offset" || current_tag == "indexListOffset" || current_tag == "fileChecksum")
1064  {
1065  //do nothing for
1066  // - index
1067  // - checksum
1068  // - binary chromatogram data
1069  }
1070  else
1071  {
1072  char* transcoded_chars = sm_.convert(chars);
1073  String transcoded_chars2 = transcoded_chars;
1074  transcoded_chars2.trim();
1075  if (transcoded_chars2 != "")
1076  warning(LOAD, String("Unhandled character content in tag '") + current_tag + "': " + transcoded_chars2);
1077  }
1078  }
1079 
1080  template <typename MapType>
1081  void MzMLHandler<MapType>::startElement(const XMLCh* const /*uri*/, const XMLCh* const /*local_name*/, const XMLCh* const qname, const xercesc::Attributes& attributes)
1082  {
1083  static const XMLCh* s_count = xercesc::XMLString::transcode("count");
1084  static const XMLCh* s_default_array_length = xercesc::XMLString::transcode("defaultArrayLength");
1085  static const XMLCh* s_array_length = xercesc::XMLString::transcode("arrayLength");
1086  static const XMLCh* s_accession = xercesc::XMLString::transcode("accession");
1087  static const XMLCh* s_name = xercesc::XMLString::transcode("name");
1088  static const XMLCh* s_type = xercesc::XMLString::transcode("type");
1089  static const XMLCh* s_value = xercesc::XMLString::transcode("value");
1090  static const XMLCh* s_unit_accession = xercesc::XMLString::transcode("unitAccession");
1091  static const XMLCh* s_id = xercesc::XMLString::transcode("id");
1092  static const XMLCh* s_spot_id = xercesc::XMLString::transcode("spotID");
1093  //~ static const XMLCh * s_cvref = xercesc::XMLString::transcode("cvRef"); TODO
1094  static const XMLCh* s_ref = xercesc::XMLString::transcode("ref");
1095  static const XMLCh* s_version = xercesc::XMLString::transcode("version");
1096  static const XMLCh* s_order = xercesc::XMLString::transcode("order");
1097  static const XMLCh* s_location = xercesc::XMLString::transcode("location");
1098  static const XMLCh* s_sample_ref = xercesc::XMLString::transcode("sampleRef");
1099  static const XMLCh* s_software_ref = xercesc::XMLString::transcode("softwareRef");
1100  static const XMLCh* s_source_file_ref = xercesc::XMLString::transcode("sourceFileRef");
1101  static const XMLCh* s_default_instrument_configuration_ref = xercesc::XMLString::transcode("defaultInstrumentConfigurationRef");
1102  static const XMLCh* s_instrument_configuration_ref = xercesc::XMLString::transcode("instrumentConfigurationRef");
1103  static const XMLCh* s_default_data_processing_ref = xercesc::XMLString::transcode("defaultDataProcessingRef");
1104  static const XMLCh* s_data_processing_ref = xercesc::XMLString::transcode("dataProcessingRef");
1105  static const XMLCh* s_start_time_stamp = xercesc::XMLString::transcode("startTimeStamp");
1106  static const XMLCh* s_external_spectrum_id = xercesc::XMLString::transcode("externalSpectrumID");
1107  static const XMLCh* s_default_source_file_ref = xercesc::XMLString::transcode("defaultSourceFileRef");
1108  static const XMLCh* s_scan_settings_ref = xercesc::XMLString::transcode("scanSettingsRef");
1109 
1110  String tag = sm_.convert(qname);
1111  open_tags_.push_back(tag);
1112 
1113  //determine parent tag
1114  String parent_tag;
1115  if (open_tags_.size() > 1)
1116  parent_tag = *(open_tags_.end() - 2);
1117  String parent_parent_tag;
1118  if (open_tags_.size() > 2)
1119  parent_parent_tag = *(open_tags_.end() - 3);
1120 
1121  //do nothing until a new spectrum is reached
1122  if (tag != "spectrum" && skip_spectrum_)
1123  return;
1124 
1125  if (tag != "chromatogram" && skip_chromatogram_)
1126  return;
1127 
1128  if (tag == "spectrum")
1129  {
1130  //number of peaks
1131  spec_ = SpectrumType();
1132  default_array_length_ = attributeAsInt_(attributes, s_default_array_length);
1133  //spectrum source file
1134  String source_file_ref;
1135  if (optionalAttributeAsString_(source_file_ref, attributes, s_source_file_ref))
1136  {
1137  spec_.setSourceFile(source_files_[source_file_ref]);
1138  }
1139  //native id
1140  spec_.setNativeID(attributeAsString_(attributes, s_id));
1141  //maldi spot id
1142  String maldi_spot_id;
1143  if (optionalAttributeAsString_(maldi_spot_id, attributes, s_spot_id))
1144  {
1145  spec_.setMetaValue("maldi_spot_id", maldi_spot_id);
1146  }
1147  //data processing
1148  String data_processing_ref;
1149  if (optionalAttributeAsString_(data_processing_ref, attributes, s_data_processing_ref))
1150  {
1151  spec_.setDataProcessing(processing_[data_processing_ref]);
1152  }
1153  else
1154  {
1155  spec_.setDataProcessing(processing_[default_processing_]);
1156  }
1157  }
1158  else if (tag == "chromatogram")
1159  {
1160  chromatogram_ = ChromatogramType();
1161  default_array_length_ = attributeAsInt_(attributes, s_default_array_length);
1162  String source_file_ref;
1163  if (optionalAttributeAsString_(source_file_ref, attributes, s_source_file_ref))
1164  {
1165  chromatogram_.setSourceFile(source_files_[source_file_ref]);
1166  }
1167  // native id
1168  chromatogram_.setNativeID(attributeAsString_(attributes, s_id));
1169  // data processing
1170  String data_processing_ref;
1171  if (optionalAttributeAsString_(data_processing_ref, attributes, s_data_processing_ref))
1172  {
1173  chromatogram_.setDataProcessing(processing_[data_processing_ref]);
1174  }
1175  else
1176  {
1177  chromatogram_.setDataProcessing(processing_[default_processing_]);
1178  }
1179  }
1180  else if (tag == "spectrumList")
1181  {
1182  //default data processing
1183  default_processing_ = attributeAsString_(attributes, s_default_data_processing_ref);
1184 
1185  //Abort if we need meta data only
1186  if (options_.getMetadataOnly())
1187  throw EndParsingSoftly(__FILE__, __LINE__, __PRETTY_FUNCTION__);
1188 
1189  UInt count = attributeAsInt_(attributes, s_count);
1190  exp_->reserveSpaceSpectra(count);
1191  logger_.startProgress(0, count, "loading spectra list");
1192  in_spectrum_list_ = true;
1193  }
1194  else if (tag == "chromatogramList")
1195  {
1196  // default data processing
1197  default_processing_ = attributeAsString_(attributes, s_default_data_processing_ref);
1198 
1199  //Abort if we need meta data only
1200  if (options_.getMetadataOnly())
1201  throw EndParsingSoftly(__FILE__, __LINE__, __PRETTY_FUNCTION__);
1202 
1203  UInt count = attributeAsInt_(attributes, s_count);
1204  exp_->reserveSpaceChromatograms(count);
1205  logger_.startProgress(0, count, "loading chromatogram list");
1206  in_spectrum_list_ = false;
1207  }
1208  else if (tag == "binaryDataArrayList" /* && in_spectrum_list_*/)
1209  {
1210  data_.reserve(attributeAsInt_(attributes, s_count));
1211  }
1212  else if (tag == "binaryDataArray" /* && in_spectrum_list_*/)
1213  {
1214  data_.push_back(BinaryData());
1215  data_.back().np_compression = MSNumpressCoder::NONE; // ensure that numpress compression is initially set to none ...
1216  data_.back().compression = false; // ensure that zlib compression is initially set to none ...
1217 
1218  //array length
1219  Int array_length = (Int) default_array_length_;
1220  optionalAttributeAsInt_(array_length, attributes, s_array_length);
1221  data_.back().size = array_length;
1222 
1223  //data processing
1224  String data_processing_ref;
1225  if (optionalAttributeAsString_(data_processing_ref, attributes, s_data_processing_ref))
1226  {
1227  data_.back().meta.setDataProcessing(processing_[data_processing_ref]);
1228  }
1229  }
1230  else if (tag == "cvParam")
1231  {
1232  String value = "";
1233  optionalAttributeAsString_(value, attributes, s_value);
1234  String unit_accession = "";
1235  optionalAttributeAsString_(unit_accession, attributes, s_unit_accession);
1236  handleCVParam_(parent_parent_tag, parent_tag, /* attributeAsString_(attributes, s_cvref), */ attributeAsString_(attributes, s_accession), attributeAsString_(attributes, s_name), value, unit_accession);
1237  }
1238  else if (tag == "userParam")
1239  {
1240  String type = "";
1241  optionalAttributeAsString_(type, attributes, s_type);
1242  String value = "";
1243  optionalAttributeAsString_(value, attributes, s_value);
1244  handleUserParam_(parent_parent_tag, parent_tag, attributeAsString_(attributes, s_name), type, value);
1245  }
1246  else if (tag == "referenceableParamGroup")
1247  {
1248  current_id_ = attributeAsString_(attributes, s_id);
1249  }
1250  else if (tag == "sourceFile")
1251  {
1252  current_id_ = attributeAsString_(attributes, s_id);
1253  // Name of the source file, without reference to location (either URI or local path). e.g. "control.mzML"
1254  String name_of_file = attributeAsString_(attributes, s_name);
1255 
1256  //URI-formatted location where the file was retrieved.
1257  String path_to_file = attributeAsString_(attributes, s_location);
1258 
1259  // mzML files often deviate from the specification by storing e.g. the full path in the name attribute etc.
1260  // error: whole path is stored in file name. fix: split into path and file name
1261  if (path_to_file.empty() && !name_of_file.empty())
1262  {
1263  path_to_file = File::path(name_of_file);
1264  name_of_file = File::basename(name_of_file);
1265  if (path_to_file == ".") path_to_file = "file://./";
1266  }
1267 
1268  // format URI prefix as in mzML spec.
1269  if (path_to_file.hasPrefix("File://")) path_to_file.substitute("File://", "file://");
1270  if (path_to_file.hasPrefix("FILE://")) path_to_file.substitute("FILE://", "file://");
1271  if (path_to_file.hasPrefix("file:///.")) path_to_file.substitute("file:///.", "file://./");
1272 
1273  bool is_relative_path = path_to_file.hasPrefix("file://./") || path_to_file.hasPrefix("file://../");
1274 
1275  // ill formed absolute or relative path
1276  if (!is_relative_path && path_to_file.hasPrefix("file://") && !path_to_file.hasPrefix("file:///"))
1277  {
1278  warning(LOAD, "Ill formed absolute or relative sourceFile path: " + path_to_file);
1279  }
1280 
1281  // if possible convert relative path to absolute path
1282  if (is_relative_path && File::isDirectory(path_to_file))
1283  {
1284  String normal_path = String(path_to_file).substitute("file://", ""); // remove URI prefix
1285  path_to_file = String("file://") + File::absolutePath(normal_path); // on linux this e.g. file:///home... on win: file://C:/...
1286  }
1287 
1288  // absolute path to the root: remove additional / otherwise we will get file://// on concatenation
1289  if (!is_relative_path && path_to_file == "file:///")
1290  {
1291  path_to_file = "file://";
1292  }
1293 
1294  source_files_[current_id_].setNameOfFile(name_of_file);
1295  source_files_[current_id_].setPathToFile(path_to_file);
1296  }
1297  else if (tag == "referenceableParamGroupRef")
1298  {
1299  //call handleCVParam_ with the parent tag for each parameter in the group
1300  String ref = attributeAsString_(attributes, s_ref);
1301  for (Size i = 0; i < ref_param_[ref].size(); ++i)
1302  {
1303  handleCVParam_(parent_parent_tag, parent_tag, /* attributeAsString_(attributes, s_cvref), */ ref_param_[ref][i].accession, ref_param_[ref][i].name, ref_param_[ref][i].value, ref_param_[ref][i].unit_accession);
1304  }
1305  }
1306  else if (tag == "scan")
1307  {
1308  Acquisition tmp;
1309  //source file => meta data
1310  String source_file_ref;
1311  if (optionalAttributeAsString_(source_file_ref, attributes, s_source_file_ref))
1312  {
1313  tmp.setMetaValue("source_file_name", source_files_[source_file_ref].getNameOfFile());
1314  tmp.setMetaValue("source_file_path", source_files_[source_file_ref].getPathToFile());
1315  }
1316  //external spectrum id => meta data
1317  String external_spectrum_id;
1318  if (optionalAttributeAsString_(external_spectrum_id, attributes, s_external_spectrum_id))
1319  {
1320  tmp.setIdentifier(external_spectrum_id);
1321  }
1322 
1323  //spectrumRef - not really needed
1324 
1325  //instrumentConfigurationRef - not really needed: why should a scan have a different instrument?
1326  String instrument_configuration_ref;
1327  if (optionalAttributeAsString_(instrument_configuration_ref, attributes, s_instrument_configuration_ref))
1328  {
1329  warning(LOAD, "Unhandled attribute 'instrumentConfigurationRef' in 'scan' tag.");
1330  }
1331 
1332  spec_.getAcquisitionInfo().push_back(tmp);
1333  }
1334  else if (tag == "mzML")
1335  {
1336  scan_count = 0;
1337  chromatogram_count = 0;
1338 
1339  //check file version against schema version
1340  String file_version = attributeAsString_(attributes, s_version);
1341 
1342  VersionInfo::VersionDetails current_version = VersionInfo::VersionDetails::create(file_version);
1343  static VersionInfo::VersionDetails mzML_min_version = VersionInfo::VersionDetails::create("1.1.0");
1344 
1345  if (current_version == VersionInfo::VersionDetails::EMPTY)
1346  {
1347  warning(LOAD, String("Invalid mzML version string '") + file_version + "'. Assuming mzML version " + version_ + "!");
1348  }
1349  else
1350  {
1351  if (current_version < mzML_min_version)
1352  {
1353  fatalError(LOAD, String("Only mzML 1.1.0 or higher is supported! This file has version '") + file_version + "'.");
1354  }
1355  else if (current_version > VersionInfo::VersionDetails::create(version_))
1356  {
1357  warning(LOAD, "The mzML file version (" + file_version + ") is newer than the parser version (" + version_ + "). This might lead to undefined behavior.");
1358  }
1359  }
1360 
1361  //handle file accession
1362  String accession;
1363  if (optionalAttributeAsString_(accession, attributes, s_accession))
1364  {
1365  exp_->setIdentifier(accession);
1366  }
1367  //handle file id
1368  String id;
1369  if (optionalAttributeAsString_(id, attributes, s_id))
1370  {
1371  exp_->setMetaValue("mzml_id", id);
1372  }
1373  }
1374  else if (tag == "contact")
1375  {
1376  exp_->getContacts().push_back(ContactPerson());
1377  }
1378  else if (tag == "sample")
1379  {
1380  current_id_ = attributeAsString_(attributes, s_id);
1381  String name;
1382  if (optionalAttributeAsString_(name, attributes, s_name))
1383  {
1384  samples_[current_id_].setName(name);
1385  }
1386  }
1387  else if (tag == "run")
1388  {
1389  //sample
1390  String sample_ref;
1391  if (optionalAttributeAsString_(sample_ref, attributes, s_sample_ref))
1392  {
1393  exp_->setSample(samples_[sample_ref]);
1394  }
1395  //instrument
1396  String instrument_ref = attributeAsString_(attributes, s_default_instrument_configuration_ref);
1397  exp_->setInstrument(instruments_[instrument_ref]);
1398  //start time
1399  String start_time;
1400  if (optionalAttributeAsString_(start_time, attributes, s_start_time_stamp))
1401  {
1402  exp_->setDateTime(asDateTime_(start_time));
1403  }
1404  //defaultSourceFileRef
1405  String default_source_file_ref;
1406  if (optionalAttributeAsString_(default_source_file_ref, attributes, s_default_source_file_ref))
1407  {
1408  exp_->getSourceFiles().push_back(source_files_[default_source_file_ref]);
1409  }
1410  }
1411  else if (tag == "software")
1412  {
1413  current_id_ = attributeAsString_(attributes, s_id);
1414  software_[current_id_].setVersion(attributeAsString_(attributes, s_version));
1415  }
1416  else if (tag == "dataProcessing")
1417  {
1418  current_id_ = attributeAsString_(attributes, s_id);
1419  }
1420  else if (tag == "processingMethod")
1421  {
1423  // See ticket 452: Do NOT remove this try/catch block until foreign
1424  // software (e.g. ProteoWizard msconvert.exe) produces valid mzML.
1425  try
1426  {
1427  dp->setSoftware(software_[attributeAsString_(attributes, s_software_ref)]);
1428  }
1429  catch (Exception::ParseError& /*e*/)
1430  {
1431  LOG_ERROR << "Warning: Parsing error, \"processingMethod\" is missing the required attribute \"softwareRef\".\n" <<
1432  "The software tool which generated this mzML should be fixed. Please notify the maintainers." << std::endl;
1433  }
1434  processing_[current_id_].push_back(dp);
1435  //The order of processing methods is currently ignored
1436  }
1437  else if (tag == "instrumentConfiguration")
1438  {
1439  current_id_ = attributeAsString_(attributes, s_id);
1440 
1441  //scan settings
1442  String scan_settings_ref;
1443  if (optionalAttributeAsString_(scan_settings_ref, attributes, s_scan_settings_ref))
1444  {
1445  warning(LOAD, "Unhandled attribute 'scanSettingsRef' in 'instrumentConfiguration' tag.");
1446  }
1447  }
1448  else if (tag == "softwareRef")
1449  {
1450  //Set the software of the instrument
1451  instruments_[current_id_].setSoftware(software_[attributeAsString_(attributes, s_ref)]);
1452  }
1453  else if (tag == "source")
1454  {
1455  instruments_[current_id_].getIonSources().push_back(IonSource());
1456  instruments_[current_id_].getIonSources().back().setOrder(attributeAsInt_(attributes, s_order));
1457  }
1458  else if (tag == "analyzer")
1459  {
1460  instruments_[current_id_].getMassAnalyzers().push_back(MassAnalyzer());
1461  instruments_[current_id_].getMassAnalyzers().back().setOrder(attributeAsInt_(attributes, s_order));
1462  }
1463  else if (tag == "detector")
1464  {
1465  instruments_[current_id_].getIonDetectors().push_back(IonDetector());
1466  instruments_[current_id_].getIonDetectors().back().setOrder(attributeAsInt_(attributes, s_order));
1467  }
1468  else if (tag == "precursor")
1469  {
1470  if (in_spectrum_list_)
1471  {
1472  //initialize
1473  spec_.getPrecursors().push_back(Precursor());
1474 
1475  //source file => meta data
1476  String source_file_ref;
1477  if (optionalAttributeAsString_(source_file_ref, attributes, s_source_file_ref))
1478  {
1479  spec_.getPrecursors().back().setMetaValue("source_file_name", source_files_[source_file_ref].getNameOfFile());
1480  spec_.getPrecursors().back().setMetaValue("source_file_path", source_files_[source_file_ref].getPathToFile());
1481  }
1482  //external spectrum id => meta data
1483  String external_spectrum_id;
1484  if (optionalAttributeAsString_(external_spectrum_id, attributes, s_external_spectrum_id))
1485  {
1486  spec_.getPrecursors().back().setMetaValue("external_spectrum_id", external_spectrum_id);
1487  }
1488  //reset selected ion count
1489  selected_ion_count_ = 0;
1490  }
1491  else
1492  {
1493  chromatogram_.setPrecursor(Precursor());
1494 
1495  String source_file_ref;
1496  if (optionalAttributeAsString_(source_file_ref, attributes, s_source_file_ref))
1497  {
1498  chromatogram_.getPrecursor().setMetaValue("source_file_name", source_files_[source_file_ref].getNameOfFile());
1499  chromatogram_.getPrecursor().setMetaValue("source_file_path", source_files_[source_file_ref].getPathToFile());
1500  }
1501 
1502  String external_spectrum_id;
1503  if (optionalAttributeAsString_(external_spectrum_id, attributes, s_external_spectrum_id))
1504  {
1505  chromatogram_.getPrecursor().setMetaValue("external_spectrum_id", external_spectrum_id);
1506  }
1507  selected_ion_count_ = 0;
1508  }
1509  }
1510  else if (tag == "product")
1511  {
1512  //initialize
1513  if (in_spectrum_list_)
1514  {
1515  spec_.getProducts().push_back(Product());
1516  }
1517  else
1518  {
1519  chromatogram_.setProduct(Product());
1520  }
1521  }
1522  else if (tag == "selectedIon")
1523  {
1524  //increase selected ion count
1525  ++selected_ion_count_;
1526  }
1527  else if (tag == "selectedIonList")
1528  {
1529  //Warn if more than one selected ion is present
1530  if (attributeAsInt_(attributes, s_count) > 1)
1531  {
1532  warning(LOAD, "OpenMS can currently handle only one selection ion per precursor! Only the first ion is loaded!");
1533  }
1534  }
1535  else if (tag == "scanWindow")
1536  {
1537  spec_.getInstrumentSettings().getScanWindows().push_back(ScanWindow());
1538  }
1539  }
1540 
1541  template <typename MapType>
1542  void MzMLHandler<MapType>::endElement(const XMLCh* const /*uri*/, const XMLCh* const /*local_name*/, const XMLCh* const qname)
1543  {
1544  static const XMLCh* s_spectrum = xercesc::XMLString::transcode("spectrum");
1545  static const XMLCh* s_chromatogram = xercesc::XMLString::transcode("chromatogram");
1546  static const XMLCh* s_spectrum_list = xercesc::XMLString::transcode("spectrumList");
1547  static const XMLCh* s_chromatogram_list = xercesc::XMLString::transcode("chromatogramList");
1548  static const XMLCh* s_mzml = xercesc::XMLString::transcode("mzML");
1549 
1550  open_tags_.pop_back();
1551 
1552  if (equal_(qname, s_spectrum))
1553  {
1554 
1555  // catch errors stemming from confusion about elution time and scan time
1556  if (!rt_set_ && spec_.metaValueExists("elution time (seconds)"))
1557  {
1558  spec_.setRT(spec_.getMetaValue("elution time (seconds)"));
1559  }
1560  /* this is too hot (could be SRM as well? -- check!):
1561  // correct spectrum type if possible (i.e., make it more specific)
1562  if (spec_.getInstrumentSettings().getScanMode() == InstrumentSettings::MASSSPECTRUM)
1563  {
1564  if (spec_.getMSLevel() <= 1) spec_.getInstrumentSettings().setScanMode(InstrumentSettings::MS1SPECTRUM);
1565  else spec_.getInstrumentSettings().setScanMode(InstrumentSettings::MSNSPECTRUM);
1566  }
1567  */
1568 
1569  if (!skip_spectrum_)
1570  {
1571  spectrum_data_.push_back(SpectrumData());
1572  spectrum_data_.back().default_array_length = default_array_length_;
1573  spectrum_data_.back().spectrum = spec_;
1574  if (options_.getFillData())
1575  {
1576  spectrum_data_.back().data = data_;
1577  }
1578  }
1579 
1580  if (spectrum_data_.size() >= options_.getMaxDataPoolSize())
1581  {
1582  populateSpectraWithData();
1583  }
1584 
1585  skip_spectrum_ = false;
1586  rt_set_ = false;
1587  if (options_.getSizeOnly()) {skip_spectrum_ = true; }
1588  logger_.setProgress(++scan_count);
1589  data_.clear();
1590  default_array_length_ = 0;
1591  }
1592  else if (equal_(qname, s_chromatogram))
1593  {
1594 
1595  if (!skip_chromatogram_)
1596  {
1597  chromatogram_data_.push_back(ChromatogramData());
1598  chromatogram_data_.back().default_array_length = default_array_length_;
1599  chromatogram_data_.back().chromatogram = chromatogram_;
1600  if (options_.getFillData())
1601  {
1602  chromatogram_data_.back().data = data_;
1603  }
1604  }
1605 
1606  if (chromatogram_data_.size() >= options_.getMaxDataPoolSize())
1607  {
1608  populateChromatogramsWithData();
1609  }
1610 
1611  skip_chromatogram_ = false;
1612  if (options_.getSizeOnly()) {skip_chromatogram_ = true; }
1613  logger_.setProgress(++chromatogram_count);
1614  data_.clear();
1615  default_array_length_ = 0;
1616  }
1617  else if (equal_(qname, s_spectrum_list))
1618  {
1619  in_spectrum_list_ = false;
1620  logger_.endProgress();
1621  }
1622  else if (equal_(qname, s_chromatogram_list))
1623  {
1624  in_spectrum_list_ = false;
1625  logger_.endProgress();
1626  }
1627  else if (equal_(qname, s_mzml))
1628  {
1629  ref_param_.clear();
1630  current_id_ = "";
1631  source_files_.clear();
1632  samples_.clear();
1633  software_.clear();
1634  instruments_.clear();
1635  processing_.clear();
1636 
1637  // Flush the remaining data
1638  populateSpectraWithData();
1639  populateChromatogramsWithData();
1640  }
1641 
1642  sm_.clear();
1643  }
1644 
1645  template <typename MapType>
1646  void MzMLHandler<MapType>::handleCVParam_(const String& parent_parent_tag, const String& parent_tag, /* const String & cvref, */ const String& accession, const String& name, const String& value, const String& unit_accession)
1647  {
1648  // the actual value stored in the CVParam
1649  // we assume for now that it is a string value, we update the type later on
1650  DataValue termValue = value;
1651 
1652  //Abort on unknown terms
1653  if (!cv_.exists(accession))
1654  {
1655  //in 'sample' several external CVs are used (Brenda, GO, ...). Do not warn then.
1656  if (parent_tag != "sample")
1657  {
1658  warning(LOAD, String("Unknown cvParam '") + accession + "' in tag '" + parent_tag + "'.");
1659  return;
1660  }
1661  }
1662  else
1663  {
1664  const ControlledVocabulary::CVTerm& term = cv_.getTerm(accession);
1665 
1666  //obsolete CV terms
1667  if (term.obsolete)
1668  {
1669  warning(LOAD, String("Obsolete CV term '") + accession + " - " + term.name + "' used in tag '" + parent_tag + "'.");
1670  }
1671  //check if term name and parsed name match
1672  String parsed_name = name;
1673  parsed_name.trim();
1674  String correct_name = term.name;
1675  correct_name.trim();
1676  if (parsed_name != correct_name)
1677  {
1678  warning(LOAD, String("Name of CV term not correct: '") + term.id + " - " + parsed_name + "' should be '" + correct_name + "'");
1679  }
1680  if (term.obsolete)
1681  {
1682  warning(LOAD, String("Obsolete CV term '") + accession + " - " + term.name + "' used in tag '" + parent_tag + "'.");
1683  }
1684  //values used in wrong places and wrong value types
1685  if (value != "")
1686  {
1688  {
1689  //Quality CV does not state value type :(
1690  if (!accession.hasPrefix("PATO:"))
1691  {
1692  warning(LOAD, String("The CV term '") + accession + " - " + term.name + "' used in tag '" + parent_tag + "' must not have a value. The value is '" + value + "'.");
1693  }
1694  }
1695  else
1696  {
1697  switch (term.xref_type)
1698  {
1699  //string value can be anything
1701  break;
1702 
1703  //int value => try casting
1709  try
1710  {
1711  termValue = value.toInt();
1712  }
1714  {
1715  warning(LOAD, String("The CV term '") + accession + " - " + term.name + "' used in tag '" + parent_tag + "' must have an integer value. The value is '" + value + "'.");
1716  return;
1717  }
1718  break;
1719 
1720  //double value => try casting
1722  try
1723  {
1724  termValue = value.toDouble();
1725  }
1727  {
1728  warning(LOAD, String("The CV term '") + accession + " - " + term.name + "' used in tag '" + parent_tag + "' must have a floating-point value. The value is '" + value + "'.");
1729  return;
1730  }
1731  break;
1732 
1733  //date string => try conversion
1735  try
1736  {
1737  DateTime tmp;
1738  tmp.set(value);
1739  }
1740  catch (Exception::ParseError&)
1741  {
1742  warning(LOAD, String("The CV term '") + accession + " - " + term.name + "' used in tag '" + parent_tag + "' must be a valid date. The value is '" + value + "'.");
1743  return;
1744  }
1745  break;
1746 
1747  default:
1748  warning(LOAD, String("The CV term '") + accession + " - " + term.name + "' used in tag '" + parent_tag + "' has the unknown value type '" + ControlledVocabulary::CVTerm::getXRefTypeName(term.xref_type) + "'.");
1749  break;
1750  }
1751  }
1752  }
1753  //no value, although there should be a numerical value
1755  {
1756  warning(LOAD, String("The CV term '") + accession + " - " + term.name + "' used in tag '" + parent_tag + "' should have a numerical value. The value is '" + value + "'.");
1757  return;
1758  }
1759  }
1760 
1761  if (unit_accession != "") termValue.setUnit(unit_accession);
1762 
1763  //------------------------- run ----------------------------
1764  if (parent_tag == "run")
1765  {
1766  //MS:1000857 ! run attribute
1767  if (accession == "MS:1000858") //fraction identifier
1768  {
1769  exp_->setFractionIdentifier(value);
1770  }
1771  else
1772  warning(LOAD, String("Unhandled cvParam '") + accession + "' in tag '" + parent_tag + "'.");
1773  }
1774  //------------------------- binaryDataArray ----------------------------
1775  else if (parent_tag == "binaryDataArray")
1776  {
1777  if (!MzMLHandlerHelper::handleBinaryDataArrayCVParam(data_, accession, value, name))
1778  {
1779  if (cv_.isChildOf(accession, "MS:1000513")) //other array names as string
1780  {
1781  data_.back().meta.setName(cv_.getTerm(accession).name);
1782  }
1783  else
1784  {
1785  warning(LOAD, String("Unhandled cvParam '") + accession + "' in tag '" + parent_tag + "'.");
1786  }
1787  }
1788  }
1789  //------------------------- spectrum ----------------------------
1790  else if (parent_tag == "spectrum")
1791  {
1792  //spectrum type
1793  if (accession == "MS:1000294") //mass spectrum
1794  {
1795  spec_.getInstrumentSettings().setScanMode(InstrumentSettings::MASSSPECTRUM);
1796  }
1797  else if (accession == "MS:1000579") //MS1 spectrum
1798  {
1799  spec_.getInstrumentSettings().setScanMode(InstrumentSettings::MS1SPECTRUM);
1800  }
1801  else if (accession == "MS:1000580") //MSn spectrum
1802  {
1803  spec_.getInstrumentSettings().setScanMode(InstrumentSettings::MSNSPECTRUM);
1804  }
1805  else if (accession == "MS:1000581") //CRM spectrum
1806  {
1807  spec_.getInstrumentSettings().setScanMode(InstrumentSettings::CRM);
1808  }
1809  else if (accession == "MS:1000582") //SIM spectrum
1810  {
1811  spec_.getInstrumentSettings().setScanMode(InstrumentSettings::SIM);
1812  }
1813  else if (accession == "MS:1000583") //SRM spectrum
1814  {
1815  spec_.getInstrumentSettings().setScanMode(InstrumentSettings::SRM);
1816  }
1817  else if (accession == "MS:1000804") //electromagnetic radiation spectrum
1818  {
1819  spec_.getInstrumentSettings().setScanMode(InstrumentSettings::EMR);
1820  }
1821  else if (accession == "MS:1000805") //emission spectrum
1822  {
1823  spec_.getInstrumentSettings().setScanMode(InstrumentSettings::EMISSION);
1824  }
1825  else if (accession == "MS:1000806") //absorption spectrum
1826  {
1827  spec_.getInstrumentSettings().setScanMode(InstrumentSettings::ABSORBTION);
1828  }
1829  else if (accession == "MS:1000325") //constant neutral gain spectrum
1830  {
1831  spec_.getInstrumentSettings().setScanMode(InstrumentSettings::CNG);
1832  }
1833  else if (accession == "MS:1000326") //constant neutral loss spectrum
1834  {
1835  spec_.getInstrumentSettings().setScanMode(InstrumentSettings::CNL);
1836  }
1837  else if (accession == "MS:1000341") //precursor ion spectrum
1838  {
1839  spec_.getInstrumentSettings().setScanMode(InstrumentSettings::PRECURSOR);
1840  }
1841  else if (accession == "MS:1000789") //enhanced multiply charged spectrum
1842  {
1843  spec_.getInstrumentSettings().setScanMode(InstrumentSettings::EMC);
1844  }
1845  else if (accession == "MS:1000790") //time-delayed fragmentation spectrum
1846  {
1847  spec_.getInstrumentSettings().setScanMode(InstrumentSettings::TDF);
1848  }
1849  //spectrum representation
1850  else if (accession == "MS:1000127") //centroid spectrum
1851  {
1852  spec_.setType(SpectrumSettings::PEAKS);
1853  }
1854  else if (accession == "MS:1000128") //profile spectrum
1855  {
1856  spec_.setType(SpectrumSettings::RAWDATA);
1857  }
1858  else if (accession == "MS:1000525") //spectrum representation
1859  {
1860  spec_.setType(SpectrumSettings::UNKNOWN);
1861  }
1862  //spectrum attribute
1863  else if (accession == "MS:1000511") //ms level
1864  {
1865  spec_.setMSLevel(value.toInt());
1866 
1867  if (options_.hasMSLevels() && !options_.containsMSLevel(spec_.getMSLevel()))
1868  {
1869  skip_spectrum_ = true;
1870  }
1871  }
1872  else if (accession == "MS:1000497") //zoom scan
1873  {
1874  spec_.getInstrumentSettings().setZoomScan(true);
1875  }
1876  else if (accession == "MS:1000285") //total ion current
1877  {
1878  //No member => meta data
1879  spec_.setMetaValue("total ion current", termValue);
1880  }
1881  else if (accession == "MS:1000504") //base peak m/z
1882  {
1883  //No member => meta data
1884  spec_.setMetaValue("base peak m/z", termValue);
1885  }
1886  else if (accession == "MS:1000505") //base peak intensity
1887  {
1888  //No member => meta data
1889  spec_.setMetaValue("base peak intensity", termValue);
1890  }
1891  else if (accession == "MS:1000527") //highest observed m/z
1892  {
1893  //No member => meta data
1894  spec_.setMetaValue("highest observed m/z", termValue);
1895  }
1896  else if (accession == "MS:1000528") //lowest observed m/z
1897  {
1898  //No member => meta data
1899  spec_.setMetaValue("lowest observed m/z", termValue);
1900  }
1901  else if (accession == "MS:1000618") //highest observed wavelength
1902  {
1903  //No member => meta data
1904  spec_.setMetaValue("highest observed wavelength", termValue);
1905  }
1906  else if (accession == "MS:1000619") //lowest observed wavelength
1907  {
1908  //No member => meta data
1909  spec_.setMetaValue("lowest observed wavelength", termValue);
1910  }
1911  else if (accession == "MS:1000796") //spectrum title
1912  {
1913  //No member => meta data
1914  spec_.setMetaValue("spectrum title", termValue);
1915  }
1916  else if (accession == "MS:1000797") //peak list scans
1917  {
1918  //No member => meta data
1919  spec_.setMetaValue("peak list scans", termValue);
1920  }
1921  else if (accession == "MS:1000798") //peak list raw scans
1922  {
1923  //No member => meta data
1924  spec_.setMetaValue("peak list raw scans", termValue);
1925  }
1926  //scan polarity
1927  else if (accession == "MS:1000129") //negative scan
1928  {
1929  spec_.getInstrumentSettings().setPolarity(IonSource::NEGATIVE);
1930  }
1931  else if (accession == "MS:1000130") //positive scan
1932  {
1933  spec_.getInstrumentSettings().setPolarity(IonSource::POSITIVE);
1934  }
1935  else
1936  warning(LOAD, String("Unhandled cvParam '") + accession + "' in tag '" + parent_tag + "'.");
1937  }
1938  //------------------------- scanWindow ----------------------------
1939  else if (parent_tag == "scanWindow")
1940  {
1941  if (accession == "MS:1000501") //scan window lower limit
1942  {
1943  spec_.getInstrumentSettings().getScanWindows().back().begin = value.toDouble();
1944  }
1945  else if (accession == "MS:1000500") //scan window upper limit
1946  {
1947  spec_.getInstrumentSettings().getScanWindows().back().end = value.toDouble();
1948  }
1949  else
1950  warning(LOAD, String("Unhandled cvParam '") + accession + "' in tag '" + parent_tag + "'.");
1951  }
1952  //------------------------- referenceableParamGroup ----------------------------
1953  else if (parent_tag == "referenceableParamGroup")
1954  {
1956  term.accession = accession;
1957  term.name = name;
1958  term.value = value;
1959  term.unit_accession = unit_accession;
1960  ref_param_[current_id_].push_back(term);
1961  }
1962  //------------------------- selectedIon ----------------------------
1963  else if (parent_tag == "selectedIon")
1964  {
1965  //parse only the first selected ion
1966  if (selected_ion_count_ > 1)
1967  return;
1968 
1969  if (accession == "MS:1000744") //selected ion m/z
1970  {
1971  //this overwrites the m/z of the isolation window, as it is probably more accurate
1972  if (in_spectrum_list_)
1973  {
1974  spec_.getPrecursors().back().setMZ(value.toDouble());
1975  }
1976  else
1977  {
1978  chromatogram_.getPrecursor().setMZ(value.toDouble());
1979  }
1980  }
1981  else if (accession == "MS:1000041") //charge state
1982  {
1983  if (in_spectrum_list_)
1984  {
1985  spec_.getPrecursors().back().setCharge(value.toInt());
1986  }
1987  else
1988  {
1989  chromatogram_.getPrecursor().setCharge(value.toInt());
1990  }
1991  }
1992  else if (accession == "MS:1000042") //peak intensity
1993  {
1994  if (in_spectrum_list_)
1995  {
1996  spec_.getPrecursors().back().setIntensity(value.toDouble());
1997  }
1998  else
1999  {
2000  chromatogram_.getPrecursor().setIntensity(value.toDouble());
2001  }
2002  }
2003  else if (accession == "MS:1000633") //possible charge state
2004  {
2005  if (in_spectrum_list_)
2006  {
2007  spec_.getPrecursors().back().getPossibleChargeStates().push_back(value.toInt());
2008  }
2009  else
2010  {
2011  chromatogram_.getPrecursor().getPossibleChargeStates().push_back(value.toInt());
2012  }
2013  }
2014  else
2015  warning(LOAD, String("Unhandled cvParam '") + accession + "' in tag '" + parent_tag + "'.");
2016  }
2017  //------------------------- activation ----------------------------
2018  else if (parent_tag == "activation")
2019  {
2020  //precursor activation attribute
2021  if (in_spectrum_list_)
2022  {
2023  if (accession == "MS:1000245") //charge stripping
2024  {
2025  //No member => meta data
2026  spec_.getPrecursors().back().setMetaValue("charge stripping", String("true"));
2027  }
2028  else if (accession == "MS:1000045") //collision energy (ev)
2029  {
2030  //No member => meta data
2031  spec_.getPrecursors().back().setMetaValue("collision energy", termValue);
2032  }
2033  else if (accession == "MS:1000412") //buffer gas
2034  {
2035  //No member => meta data
2036  spec_.getPrecursors().back().setMetaValue("buffer gas", termValue);
2037  }
2038  else if (accession == "MS:1000419") //collision gas
2039  {
2040  //No member => meta data
2041  spec_.getPrecursors().back().setMetaValue("collision gas", termValue);
2042  }
2043  else if (accession == "MS:1000509") //activation energy (ev)
2044  {
2045  spec_.getPrecursors().back().setActivationEnergy(value.toDouble());
2046  }
2047  else if (accession == "MS:1000138") //percent collision energy
2048  {
2049  //No member => meta data
2050  spec_.getPrecursors().back().setMetaValue("percent collision energy", termValue);
2051  }
2052  else if (accession == "MS:1000869") //collision gas pressure
2053  {
2054  //No member => meta data
2055  spec_.getPrecursors().back().setMetaValue("collision gas pressure", termValue);
2056  }
2057  //dissociation method
2058  else if (accession == "MS:1000044") //dissociation method
2059  {
2060  //nothing to do here
2061  }
2062  else if (accession == "MS:1000133") //collision-induced dissociation
2063  {
2064  spec_.getPrecursors().back().getActivationMethods().insert(Precursor::CID);
2065  }
2066  else if (accession == "MS:1000134") //plasma desorption
2067  {
2068  spec_.getPrecursors().back().getActivationMethods().insert(Precursor::PD);
2069  }
2070  else if (accession == "MS:1000135") //post-source decay
2071  {
2072  spec_.getPrecursors().back().getActivationMethods().insert(Precursor::PSD);
2073  }
2074  else if (accession == "MS:1000136") //surface-induced dissociation
2075  {
2076  spec_.getPrecursors().back().getActivationMethods().insert(Precursor::SID);
2077  }
2078  else if (accession == "MS:1000242") //blackbody infrared radiative dissociation
2079  {
2080  spec_.getPrecursors().back().getActivationMethods().insert(Precursor::BIRD);
2081  }
2082  else if (accession == "MS:1000250") //electron capture dissociation
2083  {
2084  spec_.getPrecursors().back().getActivationMethods().insert(Precursor::ECD);
2085  }
2086  else if (accession == "MS:1000262") //infrared multiphoton dissociation
2087  {
2088  spec_.getPrecursors().back().getActivationMethods().insert(Precursor::IMD);
2089  }
2090  else if (accession == "MS:1000282") //sustained off-resonance irradiation
2091  {
2092  spec_.getPrecursors().back().getActivationMethods().insert(Precursor::SORI);
2093  }
2094  else if (accession == "MS:1000422") //high-energy collision-induced dissociation
2095  {
2096  spec_.getPrecursors().back().getActivationMethods().insert(Precursor::HCID);
2097  }
2098  else if (accession == "MS:1000433") //low-energy collision-induced dissociation
2099  {
2100  spec_.getPrecursors().back().getActivationMethods().insert(Precursor::LCID);
2101  }
2102  else if (accession == "MS:1000435") //photodissociation
2103  {
2104  spec_.getPrecursors().back().getActivationMethods().insert(Precursor::PHD);
2105  }
2106  else if (accession == "MS:1000598") //electron transfer dissociation
2107  {
2108  spec_.getPrecursors().back().getActivationMethods().insert(Precursor::ETD);
2109  }
2110  else if (accession == "MS:1000599") //pulsed q dissociation
2111  {
2112  spec_.getPrecursors().back().getActivationMethods().insert(Precursor::PQD);
2113  }
2114  else
2115  warning(LOAD, String("Unhandled cvParam '") + accession + "' in tag '" + parent_tag + "'.");
2116  }
2117  else
2118  {
2119  if (accession == "MS:1000245") //charge stripping
2120  {
2121  //No member => meta data
2122  chromatogram_.getPrecursor().setMetaValue("charge stripping", String("true"));
2123  }
2124  else if (accession == "MS:1000045") //collision energy (ev)
2125  {
2126  //No member => meta data
2127  chromatogram_.getPrecursor().setMetaValue("collision energy", termValue);
2128  }
2129  else if (accession == "MS:1000412") //buffer gas
2130  {
2131  //No member => meta data
2132  chromatogram_.getPrecursor().setMetaValue("buffer gas", termValue);
2133  }
2134  else if (accession == "MS:1000419") //collision gas
2135  {
2136  //No member => meta data
2137  chromatogram_.getPrecursor().setMetaValue("collision gas", termValue);
2138  }
2139  else if (accession == "MS:1000509") //activation energy (ev)
2140  {
2141  chromatogram_.getPrecursor().setActivationEnergy(value.toDouble());
2142  }
2143  else if (accession == "MS:1000138") //percent collision energy
2144  {
2145  //No member => meta data
2146  chromatogram_.getPrecursor().setMetaValue("percent collision energy", termValue);
2147  }
2148  else if (accession == "MS:1000869") //collision gas pressure
2149  {
2150  //No member => meta data
2151  chromatogram_.getPrecursor().setMetaValue("collision gas pressure", termValue);
2152  }
2153  //dissociation method
2154  else if (accession == "MS:1000044") //dissociation method
2155  {
2156  //nothing to do here
2157  }
2158  else if (accession == "MS:1000133") //collision-induced dissociation
2159  {
2160  chromatogram_.getPrecursor().getActivationMethods().insert(Precursor::CID);
2161  }
2162  else if (accession == "MS:1000134") //plasma desorption
2163  {
2164  chromatogram_.getPrecursor().getActivationMethods().insert(Precursor::PD);
2165  }
2166  else if (accession == "MS:1000135") //post-source decay
2167  {
2168  chromatogram_.getPrecursor().getActivationMethods().insert(Precursor::PSD);
2169  }
2170  else if (accession == "MS:1000136") //surface-induced dissociation
2171  {
2172  chromatogram_.getPrecursor().getActivationMethods().insert(Precursor::SID);
2173  }
2174  else if (accession == "MS:1000242") //blackbody infrared radiative dissociation
2175  {
2176  chromatogram_.getPrecursor().getActivationMethods().insert(Precursor::BIRD);
2177  }
2178  else if (accession == "MS:1000250") //electron capture dissociation
2179  {
2180  chromatogram_.getPrecursor().getActivationMethods().insert(Precursor::ECD);
2181  }
2182  else if (accession == "MS:1000262") //infrared multiphoton dissociation
2183  {
2184  chromatogram_.getPrecursor().getActivationMethods().insert(Precursor::IMD);
2185  }
2186  else if (accession == "MS:1000282") //sustained off-resonance irradiation
2187  {
2188  chromatogram_.getPrecursor().getActivationMethods().insert(Precursor::SORI);
2189  }
2190  else if (accession == "MS:1000422") //high-energy collision-induced dissociation
2191  {
2192  chromatogram_.getPrecursor().getActivationMethods().insert(Precursor::HCID);
2193  }
2194  else if (accession == "MS:1000433") //low-energy collision-induced dissociation
2195  {
2196  chromatogram_.getPrecursor().getActivationMethods().insert(Precursor::LCID);
2197  }
2198  else if (accession == "MS:1000435") //photodissociation
2199  {
2200  chromatogram_.getPrecursor().getActivationMethods().insert(Precursor::PHD);
2201  }
2202  else if (accession == "MS:1000598") //electron transfer dissociation
2203  {
2204  chromatogram_.getPrecursor().getActivationMethods().insert(Precursor::ETD);
2205  }
2206  else if (accession == "MS:1000599") //pulsed q dissociation
2207  {
2208  chromatogram_.getPrecursor().getActivationMethods().insert(Precursor::PQD);
2209  }
2210  else
2211  warning(LOAD, String("Unhandled cvParam '") + accession + "' in tag '" + parent_tag + "'.");
2212  }
2213  }
2214  //------------------------- isolationWindow ----------------------------
2215  else if (parent_tag == "isolationWindow")
2216  {
2217  if (parent_parent_tag == "precursor")
2218  {
2219  if (accession == "MS:1000827") //isolation window target m/z
2220  {
2221  if (in_spectrum_list_)
2222  {
2223  spec_.getPrecursors().back().setMZ(value.toDouble());
2224  }
2225  else
2226  {
2227  chromatogram_.getPrecursor().setMZ(value.toDouble());
2228  }
2229  }
2230  else if (accession == "MS:1000828") //isolation window lower offset
2231  {
2232  if (in_spectrum_list_)
2233  {
2234  spec_.getPrecursors().back().setIsolationWindowLowerOffset(value.toDouble());
2235  }
2236  else
2237  {
2238  chromatogram_.getPrecursor().setIsolationWindowLowerOffset(value.toDouble());
2239  }
2240  }
2241  else if (accession == "MS:1000829") //isolation window upper offset
2242  {
2243  if (in_spectrum_list_)
2244  {
2245  spec_.getPrecursors().back().setIsolationWindowUpperOffset(value.toDouble());
2246  }
2247  else
2248  {
2249  chromatogram_.getPrecursor().setIsolationWindowUpperOffset(value.toDouble());
2250  }
2251  }
2252  else
2253  warning(LOAD, String("Unhandled cvParam '") + accession + "' in tag '" + parent_tag + "'.");
2254  }
2255  else if (parent_parent_tag == "product")
2256  {
2257  if (accession == "MS:1000827") //isolation window target m/z
2258  {
2259  if (in_spectrum_list_)
2260  {
2261  spec_.getProducts().back().setMZ(value.toDouble());
2262  }
2263  else
2264  {
2265  chromatogram_.getProduct().setMZ(value.toDouble());
2266  }
2267  }
2268  else if (accession == "MS:1000829") //isolation window upper offset
2269  {
2270  if (in_spectrum_list_)
2271  {
2272  spec_.getProducts().back().setIsolationWindowUpperOffset(value.toDouble());
2273  }
2274  else
2275  {
2276  chromatogram_.getProduct().setIsolationWindowUpperOffset(value.toDouble());
2277  }
2278  }
2279  else if (accession == "MS:1000828") //isolation window lower offset
2280  {
2281  if (in_spectrum_list_)
2282  {
2283  spec_.getProducts().back().setIsolationWindowLowerOffset(value.toDouble());
2284  }
2285  else
2286  {
2287  chromatogram_.getProduct().setIsolationWindowLowerOffset(value.toDouble());
2288  }
2289  }
2290  else
2291  warning(LOAD, String("Unhandled cvParam '") + accession + "' in tag '" + parent_tag + "'.");
2292  }
2293  }
2294  //------------------------- scanList ----------------------------
2295  else if (parent_tag == "scanList")
2296  {
2297  if (cv_.isChildOf(accession, "MS:1000570")) //method of combination as string
2298  {
2299  spec_.getAcquisitionInfo().setMethodOfCombination(cv_.getTerm(accession).name);
2300  }
2301  else
2302  warning(LOAD, String("Unhandled cvParam '") + accession + "' in tag '" + parent_tag + "'.");
2303  }
2304  //------------------------- scan ----------------------------
2305  else if (parent_tag == "scan")
2306  {
2307  //scan attributes
2308  if (accession == "MS:1000502") //dwell time
2309  {
2310  //No member => meta data
2311  spec_.setMetaValue("dwell time", termValue);
2312  }
2313  else if (accession == "MS:1000011") //mass resolution
2314  {
2315  //No member => meta data
2316  spec_.setMetaValue("mass resolution", termValue);
2317  }
2318  else if (accession == "MS:1000015") //scan rate
2319  {
2320  //No member => meta data
2321  spec_.setMetaValue("scan rate", termValue);
2322  }
2323  else if (accession == "MS:1000016") //scan start time
2324  {
2325  if (unit_accession == "UO:0000031") //minutes
2326  {
2327  spec_.setRT(60.0 * value.toDouble());
2328  rt_set_ = true;
2329  }
2330  else //seconds
2331  {
2332  spec_.setRT(value.toDouble());
2333  rt_set_ = true;
2334  }
2335  if (options_.hasRTRange() && !options_.getRTRange().encloses(DPosition<1>(spec_.getRT())))
2336  {
2337  skip_spectrum_ = true;
2338  }
2339  }
2340  else if (accession == "MS:1000826") //elution time
2341  {
2342  if (unit_accession == "UO:0000031") //minutes
2343  {
2344  spec_.setMetaValue("elution time (seconds)", 60.0 * value.toDouble());
2345  }
2346  else //seconds
2347  {
2348  spec_.setMetaValue("elution time (seconds)", value.toDouble());
2349  }
2350  }
2351  else if (accession == "MS:1000512") //filter string
2352  {
2353  //No member => meta data
2354  spec_.setMetaValue("filter string", termValue);
2355  }
2356  else if (accession == "MS:1000803") //analyzer scan offset
2357  {
2358  //No member => meta data
2359  spec_.setMetaValue("analyzer scan offset", termValue); // used in SpectraIdentificationViewWidget()
2360  }
2361  else if (accession == "MS:1000616") //preset scan configuration
2362  {
2363  //No member => meta data
2364  spec_.setMetaValue("preset scan configuration", termValue);
2365  }
2366  else if (accession == "MS:1000800") //mass resolving power
2367  {
2368  //No member => meta data
2369  spec_.setMetaValue("mass resolving power", termValue);
2370  }
2371  else if (accession == "MS:1000880") //interchannel delay
2372  {
2373  //No member => meta data
2374  spec_.setMetaValue("interchannel delay", termValue);
2375  }
2376  //scan direction
2377  else if (accession == "MS:1000092") //decreasing m/z scan
2378  {
2379  //No member => meta data
2380  spec_.setMetaValue("scan direction", String("decreasing"));
2381  }
2382  else if (accession == "MS:1000093") //increasing m/z scan
2383  {
2384  //No member => meta data
2385  spec_.setMetaValue("scan direction", String("increasing"));
2386  }
2387  //scan law
2388  else if (accession == "MS:1000094") //scan law: exponential
2389  {
2390  //No member => meta data
2391  spec_.setMetaValue("scan law", String("exponential"));
2392  }
2393  else if (accession == "MS:1000095") //scan law: linear
2394  {
2395  //No member => meta data
2396  spec_.setMetaValue("scan law", String("linear"));
2397  }
2398  else if (accession == "MS:1000096") //scan law: quadratic
2399  {
2400  //No member => meta data
2401  spec_.setMetaValue("scan law", String("quadratic"));
2402  }
2403  else
2404  {
2405  //warning(LOAD, String("Unhandled cvParam '") + accession + "' in tag '" + parent_tag + "'."); //of course just pops up with debug flag set ...
2406  spec_.getAcquisitionInfo().back().setMetaValue(accession, termValue);
2407  }
2408  }
2409  //------------------------- contact ----------------------------
2410  else if (parent_tag == "contact")
2411  {
2412  if (accession == "MS:1000586") //contact name
2413  {
2414  exp_->getContacts().back().setName(value);
2415  }
2416  else if (accession == "MS:1000587") //contact address
2417  {
2418  exp_->getContacts().back().setAddress(value);
2419  }
2420  else if (accession == "MS:1000588") //contact URL
2421  {
2422  exp_->getContacts().back().setURL(value);
2423  }
2424  else if (accession == "MS:1000589") //contact email
2425  {
2426  exp_->getContacts().back().setEmail(value);
2427  }
2428  else if (accession == "MS:1000590") //contact organization
2429  {
2430  exp_->getContacts().back().setInstitution(value);
2431  }
2432  else
2433  warning(LOAD, String("Unhandled cvParam '") + accession + "' in tag '" + parent_tag + "'.");
2434  }
2435  //------------------------- sourceFile ----------------------------
2436  else if (parent_tag == "sourceFile")
2437  {
2438  if (accession == "MS:1000569") //SHA-1 checksum
2439  {
2440  source_files_[current_id_].setChecksum(value, SourceFile::SHA1);
2441  }
2442  else if (accession == "MS:1000568") //MD5 checksum
2443  {
2444  source_files_[current_id_].setChecksum(value, SourceFile::MD5);
2445  }
2446  else if (cv_.isChildOf(accession, "MS:1000560")) //source file type as string
2447  {
2448  source_files_[current_id_].setFileType(cv_.getTerm(accession).name);
2449  }
2450  else if (cv_.isChildOf(accession, "MS:1000767")) //native spectrum identifier format as string
2451  {
2452  source_files_[current_id_].setNativeIDType(cv_.getTerm(accession).name);
2453  }
2454  else
2455  warning(LOAD, String("Unhandled cvParam '") + accession + "' in tag '" + parent_tag + "'.");
2456  }
2457  //------------------------- sample ----------------------------
2458  else if (parent_tag == "sample")
2459  {
2460  if (accession == "MS:1000004") //sample mass (gram)
2461  {
2462  samples_[current_id_].setMass(value.toDouble());
2463  }
2464  else if (accession == "MS:1000001") //sample number
2465  {
2466  samples_[current_id_].setNumber(value);
2467  }
2468  else if (accession == "MS:1000005") //sample volume (milliliter)
2469  {
2470  samples_[current_id_].setVolume(value.toDouble());
2471  }
2472  else if (accession == "MS:1000006") //sample concentration (gram per liter)
2473  {
2474  samples_[current_id_].setConcentration(value.toDouble());
2475  }
2476  else if (accession == "MS:1000053") //sample batch
2477  {
2478  //No member => meta data
2479  samples_[current_id_].setMetaValue("sample batch", termValue);
2480  }
2481  else if (accession == "MS:1000047") //emulsion
2482  {
2483  samples_[current_id_].setState(Sample::EMULSION);
2484  }
2485  else if (accession == "MS:1000048") //gas
2486  {
2487  samples_[current_id_].setState(Sample::GAS);
2488  }
2489  else if (accession == "MS:1000049") //liquid
2490  {
2491  samples_[current_id_].setState(Sample::LIQUID);
2492  }
2493  else if (accession == "MS:1000050") //solid
2494  {
2495  samples_[current_id_].setState(Sample::SOLID);
2496  }
2497  else if (accession == "MS:1000051") //solution
2498  {
2499  samples_[current_id_].setState(Sample::SOLUTION);
2500  }
2501  else if (accession == "MS:1000052") //suspension
2502  {
2503  samples_[current_id_].setState(Sample::SUSPENSION);
2504  }
2505  else if (accession.hasPrefix("PATO:")) //quality of an object
2506  {
2507  //No member => meta data
2508  samples_[current_id_].setMetaValue(String(name), termValue);
2509  }
2510  else if (accession.hasPrefix("GO:")) //cellular_component
2511  {
2512  //No member => meta data
2513  samples_[current_id_].setMetaValue("GO cellular component", String(name));
2514  }
2515  else if (accession.hasPrefix("BTO:")) //brenda source tissue ontology
2516  {
2517  //No member => meta data
2518  samples_[current_id_].setMetaValue("brenda source tissue", String(name));
2519  }
2520  else
2521  warning(LOAD, String("Unhandled cvParam '") + accession + "' in tag '" + parent_tag + "'.");
2522  }
2523  //------------------------- instrumentConfiguration ----------------------------
2524  else if (parent_tag == "instrumentConfiguration")
2525  {
2526  //instrument model
2527  if (accession == "MS:1000031")
2528  {
2529  //unknown instrument => nothing to do
2530  }
2531  else if (cv_.isChildOf(accession, "MS:1000031")) //instrument name as string
2532  {
2533  instruments_[current_id_].setName(cv_.getTerm(accession).name);
2534  }
2535  //instrument attribute
2536  else if (accession == "MS:1000529") //instrument serial number
2537  {
2538  //No member => meta data
2539  instruments_[current_id_].setMetaValue("instrument serial number", termValue);
2540  }
2541  else if (accession == "MS:1000032") //customization
2542  {
2543  instruments_[current_id_].setCustomizations(value);
2544  }
2545  else if (accession == "MS:1000236") //transmission
2546  {
2547  //No member => metadata
2548  instruments_[current_id_].setMetaValue("transmission", termValue);
2549  }
2550  //ion optics type
2551  else if (accession == "MS:1000246") //delayed extraction
2552  {
2553  instruments_[current_id_].setIonOptics(Instrument::DELAYED_EXTRACTION);
2554  }
2555  else if (accession == "MS:1000221") //magnetic deflection
2556  {
2557  instruments_[current_id_].setIonOptics(Instrument::MAGNETIC_DEFLECTION);
2558  }
2559  else if (accession == "MS:1000275") //collision quadrupole
2560  {
2561  instruments_[current_id_].setIonOptics(Instrument::COLLISION_QUADRUPOLE);
2562  }
2563  else if (accession == "MS:1000281") //selected ion flow tube
2564  {
2565  instruments_[current_id_].setIonOptics(Instrument::SELECTED_ION_FLOW_TUBE);
2566  }
2567  else if (accession == "MS:1000286") //time lag focusing
2568  {
2569  instruments_[current_id_].setIonOptics(Instrument::TIME_LAG_FOCUSING);
2570  }
2571  else if (accession == "MS:1000300") //reflectron
2572  {
2573  instruments_[current_id_].setIonOptics(Instrument::REFLECTRON);
2574  }
2575  else if (accession == "MS:1000307") //einzel lens
2576  {
2577  instruments_[current_id_].setIonOptics(Instrument::EINZEL_LENS);
2578  }
2579  else if (accession == "MS:1000309") //first stability region
2580  {
2581  instruments_[current_id_].setIonOptics(Instrument::FIRST_STABILITY_REGION);
2582  }
2583  else if (accession == "MS:1000310") //fringing field
2584  {
2585  instruments_[current_id_].setIonOptics(Instrument::FRINGING_FIELD);
2586  }
2587  else if (accession == "MS:1000311") //kinetic energy analyzer
2588  {
2589  instruments_[current_id_].setIonOptics(Instrument::KINETIC_ENERGY_ANALYZER);
2590  }
2591  else if (accession == "MS:1000320") //static field
2592  {
2593  instruments_[current_id_].setIonOptics(Instrument::STATIC_FIELD);
2594  }
2595  //ion optics attribute
2596  else if (accession == "MS:1000304") //accelerating voltage
2597  {
2598  //No member => metadata
2599  instruments_[current_id_].setMetaValue("accelerating voltage", termValue);
2600  }
2601  else if (accession == "MS:1000216") //field-free region
2602  {
2603  //No member => metadata
2604  instruments_[current_id_].setMetaValue("field-free region", String("true"));
2605  }
2606  else if (accession == "MS:1000308") //electric field strength
2607  {
2608  //No member => metadata
2609  instruments_[current_id_].setMetaValue("electric field strength", termValue);
2610  }
2611  else if (accession == "MS:1000319") //space charge effect
2612  {
2613  //No member => metadata
2614  instruments_[current_id_].setMetaValue("space charge effect", String("true"));
2615  }
2616  else
2617  warning(LOAD, String("Unhandled cvParam '") + accession + "' in tag '" + parent_tag + "'.");
2618  }
2619  else if (parent_tag == "source")
2620  {
2621  //inlet type
2622  if (accession == "MS:1000055") //continuous flow fast atom bombardment
2623  {
2624  instruments_[current_id_].getIonSources().back().setInletType(IonSource::CONTINUOUSFLOWFASTATOMBOMBARDMENT);
2625  }
2626  else if (accession == "MS:1000056") //direct inlet
2627  {
2628  instruments_[current_id_].getIonSources().back().setInletType(IonSource::DIRECT);
2629  }
2630  else if (accession == "MS:1000057") //electrospray inlet
2631  {
2632  instruments_[current_id_].getIonSources().back().setInletType(IonSource::ELECTROSPRAYINLET);
2633  }
2634  else if (accession == "MS:1000058") //flow injection analysis
2635  {
2636  instruments_[current_id_].getIonSources().back().setInletType(IonSource::FLOWINJECTIONANALYSIS);
2637  }
2638  else if (accession == "MS:1000059") //inductively coupled plasma
2639  {
2640  instruments_[current_id_].getIonSources().back().setInletType(IonSource::INDUCTIVELYCOUPLEDPLASMA);
2641  }
2642  else if (accession == "MS:1000060") //infusion
2643  {
2644  instruments_[current_id_].getIonSources().back().setInletType(IonSource::INFUSION);
2645  }
2646  else if (accession == "MS:1000061") //jet separator
2647  {
2648  instruments_[current_id_].getIonSources().back().setInletType(IonSource::JETSEPARATOR);
2649  }
2650  else if (accession == "MS:1000062") //membrane separator
2651  {
2652  instruments_[current_id_].getIonSources().back().setInletType(IonSource::MEMBRANESEPARATOR);
2653  }
2654  else if (accession == "MS:1000063") //moving belt
2655  {
2656  instruments_[current_id_].getIonSources().back().setInletType(IonSource::MOVINGBELT);
2657  }
2658  else if (accession == "MS:1000064") //moving wire
2659  {
2660  instruments_[current_id_].getIonSources().back().setInletType(IonSource::MOVINGWIRE);
2661  }
2662  else if (accession == "MS:1000065") //open split
2663  {
2664  instruments_[current_id_].getIonSources().back().setInletType(IonSource::OPENSPLIT);
2665  }
2666  else if (accession == "MS:1000066") //particle beam
2667  {
2668  instruments_[current_id_].getIonSources().back().setInletType(IonSource::PARTICLEBEAM);
2669  }
2670  else if (accession == "MS:1000067") //reservoir
2671  {
2672  instruments_[current_id_].getIonSources().back().setInletType(IonSource::RESERVOIR);
2673  }
2674  else if (accession == "MS:1000068") //septum
2675  {
2676  instruments_[current_id_].getIonSources().back().setInletType(IonSource::SEPTUM);
2677  }
2678  else if (accession == "MS:1000069") //thermospray inlet
2679  {
2680  instruments_[current_id_].getIonSources().back().setInletType(IonSource::THERMOSPRAYINLET);
2681  }
2682  else if (accession == "MS:1000248") //direct insertion probe
2683  {
2684  instruments_[current_id_].getIonSources().back().setInletType(IonSource::BATCH);
2685  }
2686  else if (accession == "MS:1000249") //direct liquid introduction
2687  {
2688  instruments_[current_id_].getIonSources().back().setInletType(IonSource::CHROMATOGRAPHY);
2689  }
2690  else if (accession == "MS:1000396") //membrane inlet
2691  {
2692  instruments_[current_id_].getIonSources().back().setInletType(IonSource::MEMBRANE);
2693  }
2694  else if (accession == "MS:1000485") //nanospray inlet
2695  {
2696  instruments_[current_id_].getIonSources().back().setInletType(IonSource::NANOSPRAY);
2697  }
2698  //ionization type
2699  else if (accession == "MS:1000071") //chemical ionization
2700  {
2701  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::CI);
2702  }
2703  else if (accession == "MS:1000073") //electrospray ionization
2704  {
2705  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::ESI);
2706  }
2707  else if (accession == "MS:1000074") //fast atom bombardment ionization
2708  {
2709  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::FAB);
2710  }
2711  else if (accession == "MS:1000227") //multiphoton ionization
2712  {
2713  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::MPI);
2714  }
2715  else if (accession == "MS:1000240") //atmospheric pressure ionization
2716  {
2717  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::API);
2718  }
2719  else if (accession == "MS:1000247") //desorption ionization
2720  {
2721  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::DI);
2722  }
2723  else if (accession == "MS:1000255") //flowing afterglow
2724  {
2725  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::FA);
2726  }
2727  else if (accession == "MS:1000258") //field ionization
2728  {
2729  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::FII);
2730  }
2731  else if (accession == "MS:1000259") //glow discharge ionization
2732  {
2733  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::GD_MS);
2734  }
2735  else if (accession == "MS:1000271") //Negative ion chemical ionization
2736  {
2737  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::NICI);
2738  }
2739  else if (accession == "MS:1000272") //neutralization reionization mass spectrometry
2740  {
2741  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::NRMS);
2742  }
2743  else if (accession == "MS:1000273") //photoionization
2744  {
2745  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::PI);
2746  }
2747  else if (accession == "MS:1000274") //pyrolysis mass spectrometry
2748  {
2749  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::PYMS);
2750  }
2751  else if (accession == "MS:1000276") //resonance enhanced multiphoton ionization
2752  {
2753  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::REMPI);
2754  }
2755  else if (accession == "MS:1000380") //adiabatic ionization
2756  {
2757  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::AI);
2758  }
2759  else if (accession == "MS:1000381") //associative ionization
2760  {
2761  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::ASI);
2762  }
2763  else if (accession == "MS:1000383") //autodetachment
2764  {
2765  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::AD);
2766  }
2767  else if (accession == "MS:1000384") //autoionization
2768  {
2769  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::AUI);
2770  }
2771  else if (accession == "MS:1000385") //charge exchange ionization
2772  {
2773  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::CEI);
2774  }
2775  else if (accession == "MS:1000386") //chemi-ionization
2776  {
2777  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::CHEMI);
2778  }
2779  else if (accession == "MS:1000388") //dissociative ionization
2780  {
2781  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::DISSI);
2782  }
2783  else if (accession == "MS:1000389") //electron ionization
2784  {
2785  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::EI);
2786  }
2787  else if (accession == "MS:1000395") //liquid secondary ionization
2788  {
2789  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::LSI);
2790  }
2791  else if (accession == "MS:1000399") //penning ionization
2792  {
2793  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::PEI);
2794  }
2795  else if (accession == "MS:1000400") //plasma desorption ionization
2796  {
2797  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::PD);
2798  }
2799  else if (accession == "MS:1000402") //secondary ionization
2800  {
2801  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::SI);
2802  }
2803  else if (accession == "MS:1000403") //soft ionization
2804  {
2805  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::SOI);
2806  }
2807  else if (accession == "MS:1000404") //spark ionization
2808  {
2809  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::SPI);
2810  }
2811  else if (accession == "MS:1000406") //surface ionization
2812  {
2813  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::SUI);
2814  }
2815  else if (accession == "MS:1000407") //thermal ionization
2816  {
2817  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::TI);
2818  }
2819  else if (accession == "MS:1000408") //vertical ionization
2820  {
2821  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::VI);
2822  }
2823  else if (accession == "MS:1000446") //fast ion bombardment
2824  {
2825  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::FIB);
2826  }
2827  else if (accession == "MS:1000070") //atmospheric pressure chemical ionization
2828  {
2829  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::APCI);
2830  }
2831  else if (accession == "MS:1000239") //atmospheric pressure matrix-assisted laser desorption ionization
2832  {
2833  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::AP_MALDI);
2834  }
2835  else if (accession == "MS:1000382") //atmospheric pressure photoionization
2836  {
2837  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::APPI);
2838  }
2839  else if (accession == "MS:1000075") //matrix-assisted laser desorption ionization
2840  {
2841  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::MALDI);
2842  }
2843  else if (accession == "MS:1000257") //field desorption
2844  {
2845  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::FD);
2846  }
2847  else if (accession == "MS:1000387") //desorption/ionization on silicon
2848  {
2849  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::SILI);
2850  }
2851  else if (accession == "MS:1000393") //laser desorption ionization
2852  {
2853  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::LD);
2854  }
2855  else if (accession == "MS:1000405") //surface-assisted laser desorption ionization
2856  {
2857  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::SALDI);
2858  }
2859  else if (accession == "MS:1000397") //microelectrospray
2860  {
2861  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::MESI);
2862  }
2863  else if (accession == "MS:1000398") //nanoelectrospray
2864  {
2865  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::NESI);
2866  }
2867  else if (accession == "MS:1000278") //surface enhanced laser desorption ionization
2868  {
2869  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::SELDI);
2870  }
2871  else if (accession == "MS:1000279") //surface enhanced neat desorption
2872  {
2873  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::SEND);
2874  }
2875  else if (accession == "MS:1000008") //ionization type (base term)
2876  {
2877  instruments_[current_id_].getIonSources().back().setIonizationMethod(IonSource::IONMETHODNULL);
2878  }
2879  //source attribute
2880  else if (accession == "MS:1000392") //ionization efficiency
2881  {
2882  //No member => meta data
2883  instruments_[current_id_].getIonSources().back().setMetaValue("ionization efficiency", termValue);
2884  }
2885  else if (accession == "MS:1000486") //source potential
2886  {
2887  //No member => meta data
2888  instruments_[current_id_].getIonSources().back().setMetaValue("source potential", termValue);
2889  }
2890  else if (accession == "MS:1000875") // declustering potential
2891  {
2892  //No member => meta data
2893  instruments_[current_id_].getIonSources().back().setMetaValue("declustering potential", termValue);
2894  }
2895  else if (accession == "MS:1000876") // cone voltage
2896  {
2897  //No member => meta data
2898  instruments_[current_id_].getIonSources().back().setMetaValue("cone voltage", termValue);
2899  }
2900  else if (accession == "MS:1000877") // tube lens
2901  {
2902  //No member => meta data
2903  instruments_[current_id_].getIonSources().back().setMetaValue("tube lens", termValue);
2904  }
2905  //laser attribute
2906  else if (accession == "MS:1000843") // wavelength
2907  {
2908  //No member => meta data
2909  instruments_[current_id_].getIonSources().back().setMetaValue("wavelength", termValue);
2910  }
2911  else if (accession == "MS:1000844") // focus diameter x
2912  {
2913  //No member => meta data
2914  instruments_[current_id_].getIonSources().back().setMetaValue("focus diameter x", termValue);
2915  }
2916  else if (accession == "MS:1000845") // focus diameter y
2917  {
2918  //No member => meta data
2919  instruments_[current_id_].getIonSources().back().setMetaValue("focus diameter y", termValue);
2920  }
2921  else if (accession == "MS:1000846") // pulse energy
2922  {
2923  //No member => meta data
2924  instruments_[current_id_].getIonSources().back().setMetaValue("pulse energy", termValue);
2925  }
2926  else if (accession == "MS:1000847") // pulse duration
2927  {
2928  //No member => meta data
2929  instruments_[current_id_].getIonSources().back().setMetaValue("pulse duration", termValue);
2930  }
2931  else if (accession == "MS:1000848") // attenuation
2932  {
2933  //No member => meta data
2934  instruments_[current_id_].getIonSources().back().setMetaValue("attenuation", termValue);
2935  }
2936  else if (accession == "MS:1000849") // impact angle
2937  {
2938  //No member => meta data
2939  instruments_[current_id_].getIonSources().back().setMetaValue("impact angle", termValue);
2940  }
2941  //laser type
2942  else if (accession == "MS:1000850") // gas laser
2943  {
2944  //No member => meta data
2945  instruments_[current_id_].getIonSources().back().setMetaValue("laser type", "gas laser");
2946  }
2947  else if (accession == "MS:1000851") // solid-state laser
2948  {
2949  //No member => meta data
2950  instruments_[current_id_].getIonSources().back().setMetaValue("laser type", "solid-state laser");
2951  }
2952  else if (accession == "MS:1000852") // dye-laser
2953  {
2954  //No member => meta data
2955  instruments_[current_id_].getIonSources().back().setMetaValue("laser type", "dye-laser");
2956  }
2957  else if (accession == "MS:1000853") // free electron laser
2958  {
2959  //No member => meta data
2960  instruments_[current_id_].getIonSources().back().setMetaValue("laser type", "free electron laser");
2961  }
2962  //MALDI matrix application
2963  else if (accession == "MS:1000834") // matrix solution
2964  {
2965  //No member => meta data
2966  instruments_[current_id_].getIonSources().back().setMetaValue("matrix solution", termValue);
2967  }
2968  else if (accession == "MS:1000835") // matrix solution concentration
2969  {
2970  //No member => meta data
2971  instruments_[current_id_].getIonSources().back().setMetaValue("matrix solution concentration", termValue);
2972  }
2973  // matrix application type
2974  else if (accession == "MS:1000836") // dried dropplet
2975  {
2976  //No member => meta data
2977  instruments_[current_id_].getIonSources().back().setMetaValue("matrix application type", "dried dropplet");
2978  }
2979  else if (accession == "MS:1000837") // printed
2980  {
2981  //No member => meta data
2982  instruments_[current_id_].getIonSources().back().setMetaValue("matrix application type", "printed");
2983  }
2984  else if (accession == "MS:1000838") // sprayed
2985  {
2986  //No member => meta data
2987  instruments_[current_id_].getIonSources().back().setMetaValue("matrix application type", "sprayed");
2988  }
2989  else if (accession == "MS:1000839") // precoated plate
2990  {
2991  //No member => meta data
2992  instruments_[current_id_].getIonSources().back().setMetaValue("matrix application type", " precoated plate");
2993  }
2994  else
2995  warning(LOAD, String("Unhandled cvParam '") + accession + "' in tag '" + parent_tag + "'.");
2996  }
2997  else if (parent_tag == "analyzer")
2998  {
2999  //mass analyzer type
3000  if (accession == "MS:1000079") //fourier transform ion cyclotron resonance mass spectrometer
3001  {
3002  instruments_[current_id_].getMassAnalyzers().back().setType(MassAnalyzer::FOURIERTRANSFORM);
3003  }
3004  else if (accession == "MS:1000080") //magnetic sector
3005  {
3006  instruments_[current_id_].getMassAnalyzers().back().setType(MassAnalyzer::SECTOR);
3007  }
3008  else if (accession == "MS:1000081") //quadrupole
3009  {
3010  instruments_[current_id_].getMassAnalyzers().back().setType(MassAnalyzer::QUADRUPOLE);
3011  }
3012  else if (accession == "MS:1000084") //time-of-flight
3013  {
3014  instruments_[current_id_].getMassAnalyzers().back().setType(MassAnalyzer::TOF);
3015  }
3016  else if (accession == "MS:1000254") //electrostatic energy analyzer
3017  {
3018  instruments_[current_id_].getMassAnalyzers().back().setType(MassAnalyzer::ESA);
3019  }
3020  else if (accession == "MS:1000264") //ion trap
3021  {
3022  instruments_[current_id_].getMassAnalyzers().back().setType(MassAnalyzer::IT);
3023  }
3024  else if (accession == "MS:1000284") //stored waveform inverse fourier transform
3025  {
3026  instruments_[current_id_].getMassAnalyzers().back().setType(MassAnalyzer::SWIFT);
3027  }
3028  else if (accession == "MS:1000288") //cyclotron
3029  {
3030  instruments_[current_id_].getMassAnalyzers().back().setType(MassAnalyzer::CYCLOTRON);
3031  }
3032  else if (accession == "MS:1000484") //orbitrap
3033  {
3034  instruments_[current_id_].getMassAnalyzers().back().setType(MassAnalyzer::ORBITRAP);
3035  }
3036  else if (accession == "MS:1000078") //axial ejection linear ion trap
3037  {
3038  instruments_[current_id_].getMassAnalyzers().back().setType(MassAnalyzer::AXIALEJECTIONLINEARIONTRAP);
3039  }
3040  else if (accession == "MS:1000082") //quadrupole ion trap
3041  {
3042  instruments_[current_id_].getMassAnalyzers().back().setType(MassAnalyzer::PAULIONTRAP);
3043  }
3044  else if (accession == "MS:1000083") //radial ejection linear ion trap
3045  {
3046  instruments_[current_id_].getMassAnalyzers().back().setType(MassAnalyzer::RADIALEJECTIONLINEARIONTRAP);
3047  }
3048  else if (accession == "MS:1000291") //linear ion trap
3049  {
3050  instruments_[current_id_].getMassAnalyzers().back().setType(MassAnalyzer::LIT);
3051  }
3052  else if (accession == "MS:1000443") //mass analyzer type (base term)
3053  {
3054  instruments_[current_id_].getMassAnalyzers().back().setType(MassAnalyzer::ANALYZERNULL);
3055  }
3056  //mass analyzer attribute
3057  else if (accession == "MS:1000014") //accuracy (ppm)
3058  {
3059  instruments_[current_id_].getMassAnalyzers().back().setAccuracy(value.toDouble());
3060  }
3061  else if (accession == "MS:1000022") //TOF Total Path Length (meter)
3062  {
3063  instruments_[current_id_].getMassAnalyzers().back().setTOFTotalPathLength(value.toDouble());
3064  }
3065  else if (accession == "MS:1000024") //final MS exponent
3066  {
3067  instruments_[current_id_].getMassAnalyzers().back().setFinalMSExponent(value.toInt());
3068  }
3069  else if (accession == "MS:1000025") //magnetic field strength (tesla)
3070  {
3071  instruments_[current_id_].getMassAnalyzers().back().setMagneticFieldStrength(value.toDouble());
3072  }
3073  else if (accession == "MS:1000105") //reflectron off
3074  {
3075  instruments_[current_id_].getMassAnalyzers().back().setReflectronState(MassAnalyzer::OFF);
3076  }
3077  else if (accession == "MS:1000106") //reflectron on
3078  {
3079  instruments_[current_id_].getMassAnalyzers().back().setReflectronState(MassAnalyzer::ON);
3080  }
3081  else
3082  warning(LOAD, String("Unhandled cvParam '") + accession + "' in tag '" + parent_tag + "'.");
3083  }
3084  else if (parent_tag == "detector")
3085  {
3086  //detector type
3087  if (accession == "MS:1000107") //channeltron
3088  {
3089  instruments_[current_id_].getIonDetectors().back().setType(IonDetector::CHANNELTRON);
3090  }
3091  else if (accession == "MS:1000110") //daly detector
3092  {
3093  instruments_[current_id_].getIonDetectors().back().setType(IonDetector::DALYDETECTOR);
3094  }
3095  else if (accession == "MS:1000112") //faraday cup
3096  {
3097  instruments_[current_id_].getIonDetectors().back().setType(IonDetector::FARADAYCUP);
3098  }
3099  else if (accession == "MS:1000114") //microchannel plate detector
3100  {
3101  instruments_[current_id_].getIonDetectors().back().setType(IonDetector::MICROCHANNELPLATEDETECTOR);
3102  }
3103  else if (accession == "MS:1000115") //multi-collector
3104  {
3105  instruments_[current_id_].getIonDetectors().back().setType(IonDetector::MULTICOLLECTOR);
3106  }
3107  else if (accession == "MS:1000116") //photomultiplier
3108  {
3109  instruments_[current_id_].getIonDetectors().back().setType(IonDetector::PHOTOMULTIPLIER);
3110  }
3111  else if (accession == "MS:1000253") //electron multiplier
3112  {
3113  instruments_[current_id_].getIonDetectors().back().setType(IonDetector::ELECTRONMULTIPLIER);
3114  }
3115  else if (accession == "MS:1000345") //array detector
3116  {
3117  instruments_[current_id_].getIonDetectors().back().setType(IonDetector::ARRAYDETECTOR);
3118  }
3119  else if (accession == "MS:1000346") //conversion dynode
3120  {
3121  instruments_[current_id_].getIonDetectors().back().setType(IonDetector::CONVERSIONDYNODE);
3122  }
3123  else if (accession == "MS:1000347") //dynode
3124  {
3125  instruments_[current_id_].getIonDetectors().back().setType(IonDetector::DYNODE);
3126  }
3127  else if (accession == "MS:1000348") //focal plane collector
3128  {
3129  instruments_[current_id_].getIonDetectors().back().setType(IonDetector::FOCALPLANECOLLECTOR);
3130  }
3131  else if (accession == "MS:1000349") //ion-to-photon detector
3132  {
3133  instruments_[current_id_].getIonDetectors().back().setType(IonDetector::IONTOPHOTONDETECTOR);
3134  }
3135  else if (accession == "MS:1000350") //point collector
3136  {
3137  instruments_[current_id_].getIonDetectors().back().setType(IonDetector::POINTCOLLECTOR);
3138  }
3139  else if (accession == "MS:1000351") //postacceleration detector
3140  {
3141  instruments_[current_id_].getIonDetectors().back().setType(IonDetector::POSTACCELERATIONDETECTOR);
3142  }
3143  else if (accession == "MS:1000621") //photodiode array detector
3144  {
3145  instruments_[current_id_].getIonDetectors().back().setType(IonDetector::PHOTODIODEARRAYDETECTOR);
3146  }
3147  else if (accession == "MS:1000624") //inductive detector
3148  {
3149  instruments_[current_id_].getIonDetectors().back().setType(IonDetector::INDUCTIVEDETECTOR);
3150  }
3151  else if (accession == "MS:1000108") //conversion dynode electron multiplier
3152  {
3153  instruments_[current_id_].getIonDetectors().back().setType(IonDetector::CONVERSIONDYNODEELECTRONMULTIPLIER);
3154  }
3155  else if (accession == "MS:1000109") //conversion dynode photomultiplier
3156  {
3157  instruments_[current_id_].getIonDetectors().back().setType(IonDetector::CONVERSIONDYNODEPHOTOMULTIPLIER);
3158  }
3159  else if (accession == "MS:1000111") //electron multiplier tube
3160  {
3161  instruments_[current_id_].getIonDetectors().back().setType(IonDetector::ELECTRONMULTIPLIERTUBE);
3162  }
3163  else if (accession == "MS:1000113") //focal plane array
3164  {
3165  instruments_[current_id_].getIonDetectors().back().setType(IonDetector::FOCALPLANEARRAY);
3166  }
3167  else if (accession == "MS:1000026") //detector type (base term)
3168  {
3169  instruments_[current_id_].getIonDetectors().back().setType(IonDetector::TYPENULL);
3170  }
3171  //detector attribute
3172  else if (accession == "MS:1000028") //detector resolution
3173  {
3174  instruments_[current_id_].getIonDetectors().back().setResolution(value.toDouble());
3175  }
3176  else if (accession == "MS:1000029") //sampling frequency
3177  {
3178  instruments_[current_id_].getIonDetectors().back().setADCSamplingFrequency(value.toDouble());
3179  }
3180  //detector acquisition mode
3181  else if (accession == "MS:1000117") //analog-digital converter
3182  {
3183  instruments_[current_id_].getIonDetectors().back().setAcquisitionMode(IonDetector::ADC);
3184  }
3185  else if (accession == "MS:1000118") //pulse counting
3186  {
3187  instruments_[current_id_].getIonDetectors().back().setAcquisitionMode(IonDetector::PULSECOUNTING);
3188  }
3189  else if (accession == "MS:1000119") //time-digital converter
3190  {
3191  instruments_[current_id_].getIonDetectors().back().setAcquisitionMode(IonDetector::TDC);
3192  }
3193  else if (accession == "MS:1000120") //transient recorder
3194  {
3195  instruments_[current_id_].getIonDetectors().back().setAcquisitionMode(IonDetector::TRANSIENTRECORDER);
3196  }
3197  else
3198  warning(LOAD, String("Unhandled cvParam '") + accession + "' in tag '" + parent_tag + "'.");
3199  }
3200  else if (parent_tag == "processingMethod")
3201  {
3202  //data processing parameter
3203  if (accession == "MS:1000629") //low intensity threshold (ion count)
3204  {
3205  processing_[current_id_].back()->setMetaValue("low_intensity_threshold", termValue);
3206  }
3207  else if (accession == "MS:1000631") //high intensity threshold (ion count)
3208  {
3209  processing_[current_id_].back()->setMetaValue("high_intensity_threshold", termValue);
3210  }
3211  else if (accession == "MS:1000787") //inclusive low intensity threshold
3212  {
3213  processing_[current_id_].back()->setMetaValue("inclusive_low_intensity_threshold", termValue);
3214  }
3215  else if (accession == "MS:1000788") //inclusive high intensity threshold
3216  {
3217  processing_[current_id_].back()->setMetaValue("inclusive_high_intensity_threshold", termValue);
3218  }
3219  else if (accession == "MS:1000747") //completion time
3220  {
3221  processing_[current_id_].back()->setCompletionTime(asDateTime_(value));
3222  }
3223  //file format conversion
3224  else if (accession == "MS:1000530") //file format conversion
3225  {
3226  processing_[current_id_].back()->getProcessingActions().insert(DataProcessing::FORMAT_CONVERSION);
3227  }
3228  else if (accession == "MS:1000544") //Conversion to mzML
3229  {
3230  processing_[current_id_].back()->getProcessingActions().insert(DataProcessing::CONVERSION_MZML);
3231  }
3232  else if (accession == "MS:1000545") //Conversion to mzXML
3233  {
3234  processing_[current_id_].back()->getProcessingActions().insert(DataProcessing::CONVERSION_MZXML);
3235  }
3236  else if (accession == "MS:1000546") //Conversion to mzData
3237  {
3238  processing_[current_id_].back()->getProcessingActions().insert(DataProcessing::CONVERSION_MZDATA);
3239  }
3240  else if (accession == "MS:1000741") //Conversion to DTA
3241  {
3242  processing_[current_id_].back()->getProcessingActions().insert(DataProcessing::CONVERSION_DTA);
3243  }
3244  //data processing action
3245  else if (accession == "MS:1000543") //data processing action
3246  {
3247  processing_[current_id_].back()->getProcessingActions().insert(DataProcessing::DATA_PROCESSING);
3248  }
3249  else if (accession == "MS:1000033") //deisotoping
3250  {
3251  processing_[current_id_].back()->getProcessingActions().insert(DataProcessing::DEISOTOPING);
3252  }
3253  else if (accession == "MS:1000034") //charge deconvolution
3254  {
3255  processing_[current_id_].back()->getProcessingActions().insert(DataProcessing::CHARGE_DECONVOLUTION);
3256  }
3257  else if (accession == "MS:1000035" || cv_.isChildOf(accession, "MS:1000035")) //peak picking (or child terms, we make no difference)
3258  {
3259  processing_[current_id_].back()->getProcessingActions().insert(DataProcessing::PEAK_PICKING);
3260  }
3261  else if (accession == "MS:1000592" || cv_.isChildOf(accession, "MS:1000592")) //smoothing (or child terms, we make no difference)
3262  {
3263  processing_[current_id_].back()->getProcessingActions().insert(DataProcessing::SMOOTHING);
3264  }
3265  else if (accession == "MS:1000778" || cv_.isChildOf(accession, "MS:1000778")) //charge state calculation (or child terms, we make no difference)
3266  {
3267  processing_[current_id_].back()->getProcessingActions().insert(DataProcessing::CHARGE_CALCULATION);
3268  }
3269  else if (accession == "MS:1000780" || cv_.isChildOf(accession, "MS:1000780")) //precursor recalculation (or child terms, we make no difference)
3270  {
3271  processing_[current_id_].back()->getProcessingActions().insert(DataProcessing::PRECURSOR_RECALCULATION);
3272  }
3273  else if (accession == "MS:1000593") //baseline reduction
3274  {
3275  processing_[current_id_].back()->getProcessingActions().insert(DataProcessing::BASELINE_REDUCTION);
3276  }
3277  else if (accession == "MS:1000745") //retention time alignment
3278  {
3279  processing_[current_id_].back()->getProcessingActions().insert(DataProcessing::ALIGNMENT);
3280  }
3281  else if (accession == "MS:1001484") //intensity normalization
3282  {
3283  processing_[current_id_].back()->getProcessingActions().insert(DataProcessing::NORMALIZATION);
3284  }
3285  else if (accession == "MS:1001485") //m/z calibration
3286  {
3287  processing_[current_id_].back()->getProcessingActions().insert(DataProcessing::CALIBRATION);
3288  }
3289  else if (accession == "MS:1001486" || cv_.isChildOf(accession, "MS:1001486")) //data filtering (or child terms, we make no difference)
3290  {
3291  processing_[current_id_].back()->getProcessingActions().insert(DataProcessing::FILTERING);
3292  }
3293  else
3294  warning(LOAD, String("Unhandled cvParam '") + accession + "' in tag '" + parent_tag + "'.");
3295  }
3296  else if (parent_tag == "fileContent")
3297  {
3298  if (cv_.isChildOf(accession, "MS:1000524")) //data file content
3299  {
3300  //ignored
3301  //exp_->setMetaValue(name, termValue);
3302  }
3303  else if (cv_.isChildOf(accession, "MS:1000525")) //spectrum representation
3304  {
3305  //ignored
3306  //exp_->setMetaValue(name, termValue);
3307  }
3308  else
3309  warning(LOAD, String("Unhandled cvParam '") + accession + "' in tag '" + parent_tag + "'.");
3310  }
3311  else if (parent_tag == "software")
3312  {
3313  if (cv_.isChildOf(accession, "MS:1000531")) //software as string
3314  {
3315  if (accession == "MS:1000799") //custom unreleased software tool => use value as name
3316  {
3317  software_[current_id_].setName(value);
3318  }
3319  else //use name as name
3320  {
3321  software_[current_id_].setName(name);
3322  }
3323  }
3324  else
3325  {
3326  warning(LOAD, String("Unhandled cvParam '") + accession + "' in tag '" + parent_tag + "'.");
3327  }
3328  //~ software_[current_id_].addCVTerm( CVTerm (accession, value, const String &cv_identifier_ref, const String &value, const Unit &unit) ); TODO somthing like that
3329  }
3330  else if (parent_tag == "chromatogram")
3331  {
3332  if (accession == "MS:1000810")
3333  {
3334  chromatogram_.setChromatogramType(ChromatogramSettings::MASS_CHROMATOGRAM);
3335  }
3336  else if (accession == "MS:1000235")
3337  {
3338  chromatogram_.setChromatogramType(ChromatogramSettings::TOTAL_ION_CURRENT_CHROMATOGRAM);
3339  }
3340  else if (accession == "MS:1000627")
3341  {
3342  chromatogram_.setChromatogramType(ChromatogramSettings::SELECTED_ION_CURRENT_CHROMATOGRAM);
3343  }
3344  else if (accession == "MS:1000628")
3345  {
3346  chromatogram_.setChromatogramType(ChromatogramSettings::BASEPEAK_CHROMATOGRAM);
3347  }
3348  else if (accession == "MS:1001472")
3349  {
3350  chromatogram_.setChromatogramType(ChromatogramSettings::SELECTED_ION_MONITORING_CHROMATOGRAM);
3351  }
3352  else if (accession == "MS:1001473")
3353  {
3354  chromatogram_.setChromatogramType(ChromatogramSettings::SELECTED_REACTION_MONITORING_CHROMATOGRAM);
3355  }
3356  else if (accession == "MS:1001474")
3357  {
3358  chromatogram_.setChromatogramType(ChromatogramSettings::SELECTED_REACTION_MONITORING_CHROMATOGRAM);
3359  }
3360  else if (accession == "MS:1000811")
3361  {
3362  chromatogram_.setChromatogramType(ChromatogramSettings::ELECTROMAGNETIC_RADIATION_CHROMATOGRAM);
3363  }
3364  else if (accession == "MS:1000812")
3365  {
3366  chromatogram_.setChromatogramType(ChromatogramSettings::ABSORPTION_CHROMATOGRAM);
3367  }
3368  else if (accession == "MS:1000813")
3369  {
3370  chromatogram_.setChromatogramType(ChromatogramSettings::EMISSION_CHROMATOGRAM);
3371  }
3372  else if (accession == "MS:1000809")
3373  {
3374  chromatogram_.setName(value);
3375  }
3376  else
3377  warning(LOAD, String("Unhandled cvParam '") + accession + "' in tag '" + parent_tag + "'.");
3378  }
3379  else if (parent_tag == "target")
3380  {
3381  //allowed but, not needed
3382  }
3383  else
3384  warning(LOAD, String("Unhandled cvParam '") + accession + "' in tag '" + parent_tag + "'.");
3385  }
3386 
3387  template <typename MapType>
3388  void MzMLHandler<MapType>::handleUserParam_(const String& parent_parent_tag, const String& parent_tag, const String& name, const String& type, const String& value)
3389  {
3390  //create a DataValue that contains the data in the right type
3391  DataValue data_value;
3392  //float type
3393  if (type == "xsd:double" || type == "xsd:float")
3394  {
3395  data_value = DataValue(value.toDouble());
3396  }
3397  //integer type
3398  else if (type == "xsd:byte" || type == "xsd:decimal" || type == "xsd:int" || type == "xsd:integer" || type == "xsd:long" || type == "xsd:negativeInteger" || type == "xsd:nonNegativeInteger" || type == "xsd:nonPositiveInteger" || type == "xsd:positiveInteger" || type == "xsd:short" || type == "xsd:unsignedByte" || type == "xsd:unsignedInt" || type == "xsd:unsignedLong" || type == "xsd:unsignedShort")
3399  {
3400  data_value = DataValue(value.toInt());
3401  }
3402  //everything else is treated as a string
3403  else
3404  {
3405  data_value = DataValue(value);
3406  }
3407 
3408  //find the right MetaInfoInterface
3409  if (parent_tag == "run")
3410  {
3411  exp_->setMetaValue(name, data_value);
3412  }
3413  else if (parent_tag == "instrumentConfiguration")
3414  {
3415  instruments_[current_id_].setMetaValue(name, data_value);
3416  }
3417  else if (parent_tag == "source")
3418  {
3419  instruments_[current_id_].getIonSources().back().setMetaValue(name, data_value);
3420  }
3421  else if (parent_tag == "analyzer")
3422  {
3423  instruments_[current_id_].getMassAnalyzers().back().setMetaValue(name, data_value);
3424  }
3425  else if (parent_tag == "detector")
3426  {
3427  instruments_[current_id_].getIonDetectors().back().setMetaValue(name, data_value);
3428  }
3429  else if (parent_tag == "sample")
3430  {
3431  samples_[current_id_].setMetaValue(name, data_value);
3432  }
3433  else if (parent_tag == "software")
3434  {
3435  software_[current_id_].setMetaValue(name, data_value);
3436  }
3437  else if (parent_tag == "contact")
3438  {
3439  exp_->getContacts().back().setMetaValue(name, data_value);
3440  }
3441  else if (parent_tag == "sourceFile")
3442  {
3443  source_files_[current_id_].setMetaValue(name, data_value);
3444  }
3445  else if (parent_tag == "binaryDataArray")
3446  {
3447  data_.back().meta.setMetaValue(name, data_value);
3448  }
3449  else if (parent_tag == "spectrum")
3450  {
3451  spec_.setMetaValue(name, data_value);
3452  }
3453  else if (parent_tag == "chromatogram")
3454  {
3455  chromatogram_.setMetaValue(name, data_value);
3456  }
3457  else if (parent_tag == "scanList")
3458  {
3459  spec_.getAcquisitionInfo().setMetaValue(name, data_value);
3460  }
3461  else if (parent_tag == "scan")
3462  {
3463  spec_.getAcquisitionInfo().back().setMetaValue(name, data_value);
3464  }
3465  else if (parent_tag == "scanWindow")
3466  {
3467  spec_.getInstrumentSettings().getScanWindows().back().setMetaValue(name, data_value);
3468  }
3469  else if (parent_tag == "isolationWindow")
3470  {
3471  //We don't have this as a separate location => store it in the precursor
3472  if (parent_parent_tag == "precursor")
3473  {
3474  if (in_spectrum_list_)
3475  {
3476  spec_.getPrecursors().back().setMetaValue(name, data_value);
3477  }
3478  else
3479  {
3480  chromatogram_.getPrecursor().setMetaValue(name, data_value);
3481  }
3482  }
3483  else if (parent_parent_tag == "product")
3484  {
3485  if (in_spectrum_list_)
3486  {
3487  spec_.getProducts().back().setMetaValue(name, data_value);
3488  }
3489  else
3490  {
3491  chromatogram_.getProduct().setMetaValue(name, data_value);
3492  }
3493  }
3494  }
3495  else if (parent_tag == "selectedIon")
3496  {
3497  //parse only the first selected ion
3498  if (selected_ion_count_ > 1)
3499  return;
3500 
3501  //We don't have this as a separate location => store it in the precursor
3502  if (in_spectrum_list_)
3503  {
3504  spec_.getPrecursors().back().setMetaValue(name, data_value);
3505  }
3506  else
3507  {
3508  chromatogram_.getPrecursor().setMetaValue(name, data_value);
3509  }
3510  }
3511  else if (parent_tag == "activation")
3512  {
3513  //We don't have this as a separate location => store it in the precursor
3514  if (in_spectrum_list_)
3515  {
3516  spec_.getPrecursors().back().setMetaValue(name, data_value);
3517  }
3518  else
3519  {
3520  chromatogram_.getPrecursor().setMetaValue(name, data_value);
3521  }
3522  }
3523  else if (parent_tag == "processingMethod")
3524  {
3525  processing_[current_id_].back()->setMetaValue(name, data_value);
3526  }
3527  else if (parent_tag == "fileContent")
3528  {
3529  //exp_->setMetaValue(name, data_value);
3530  }
3531  else
3532  warning(LOAD, String("Unhandled userParam '") + name + "' in tag '" + parent_tag + "'.");
3533  }
3534 
3535  template <typename MapType>
3537  {
3539 
3540  sc.accession = c.id;
3541  sc.name = c.name;
3542  sc.has_unit_accession = false;
3543  sc.has_unit_name = false;
3544 
3545  return validator.SemanticValidator::locateTerm(path, sc);
3546  }
3547 
3548  template <typename MapType>
3550  {
3551  String cvTerm = "<cvParam cvRef=\"" + c.id.prefix(':') + "\" accession=\"" + c.id + "\" name=\"" + c.name;
3552  if (!metaValue.isEmpty())
3553  {
3554  cvTerm += "\" value=\"" + writeXMLEscape(metaValue.toString());
3555  if (metaValue.hasUnit())
3556  {
3557  // unitAccession="UO:0000021" unitName="gram" unitCvRef="UO"
3558  ControlledVocabulary::CVTerm unit = cv_.getTerm(metaValue.getUnit());
3559  cvTerm += "\" unitAccession=\"" + unit.id + "\" unitName=\"" + unit.name + "\" unitCvRef=\"" + unit.id.prefix(2);
3560  }
3561  }
3562  cvTerm += "\"/>\n";
3563  return cvTerm;
3564  }
3565 
3566  template <typename MapType>
3567  void MzMLHandler<MapType>::writeUserParam_(std::ostream& os, const MetaInfoInterface& meta, UInt indent, String path, Internal::MzMLValidator& validator) const
3568  {
3569  std::vector<String> cvParams;
3570  std::vector<String> userParams;
3571 
3572  std::vector<String> keys;
3573  meta.getKeys(keys);
3574 
3575  for (std::vector<String>::iterator key = keys.begin(); key != keys.end(); ++key)
3576  {
3577  // special treatment of GO and BTO terms
3578  // <cvParam cvRef="BTO" accession="BTO:0000199" name="cardiac muscle"/>
3579 
3580  if (*key == "GO cellular component" || *key == "brenda source tissue")
3581  {
3582  // the CVTerm info is in the value
3583  const DataValue& metaValue = meta.getMetaValue(*key);
3584 
3585  if (cv_.hasTermWithName((String) metaValue))
3586  {
3587  ControlledVocabulary::CVTerm c = cv_.getTermByName((String) metaValue);
3588 
3589  // TODO: validate CV, we currently cannot do this as the relations in the BTO and GO are not captured by our CV impl
3590  cvParams.push_back(writeCV_(c, DataValue::EMPTY));
3591  }
3592  }
3593  else
3594  {
3595 
3596  bool writtenAsCVTerm = false;
3597  if (cv_.hasTermWithName(*key))
3598  {
3599  ControlledVocabulary::CVTerm c = cv_.getTermByName(*key); // in cv_ write cvparam else write userparam
3600  if (validateCV_(c, path, validator))
3601  {
3602  // write CV
3603  cvParams.push_back(writeCV_(c, meta.getMetaValue(*key)));
3604  writtenAsCVTerm = true;
3605  }
3606  }
3607 
3608  // if we could not write it as CVTerm we will store it at least as userParam
3609  if (!writtenAsCVTerm)
3610  {
3611  String userParam = "<userParam name=\"" + *key + "\" type=\"";
3612 
3613  const DataValue& d = meta.getMetaValue(*key);
3614  //determine type
3615  if (d.valueType() == DataValue::INT_VALUE)
3616  {
3617  userParam += "xsd:integer";
3618  }
3619  else if (d.valueType() == DataValue::DOUBLE_VALUE)
3620  {
3621  userParam += "xsd:double";
3622  }
3623  else //string or lists are converted to string
3624  {
3625  userParam += "xsd:string";
3626  }
3627  userParam += "\" value=\"" + writeXMLEscape(d.toString()) + "\"/>" + "\n";
3628  userParams.push_back(userParam);
3629  }
3630  }
3631  }
3632 
3633  // write out all the cvParams and userParams in correct order
3634  for (std::vector<String>::iterator term = cvParams.begin(); term != cvParams.end(); ++term)
3635  {
3636  os << String(indent, '\t') << *term;
3637  }
3638 
3639  for (std::vector<String>::iterator term = userParams.begin(); term != userParams.end(); ++term)
3640  {
3641  os << String(indent, '\t') << *term;
3642  }
3643  }
3644 
3645  template <typename MapType>
3647  {
3648  std::set<String> terms;
3649  cv_.getAllChildTerms(terms, parent_accession);
3650  for (std::set<String>::const_iterator it = terms.begin(); it != terms.end(); ++it)
3651  {
3652  if (cv_.getTerm(*it).name == name)
3653  {
3654  return cv_.getTerm(*it);
3655  }
3656  }
3658  }
3659 
3660  template <typename MapType>
3661  void MzMLHandler<MapType>::writeSoftware_(std::ostream& os, const String& id, const Software& software, Internal::MzMLValidator& validator)
3662  {
3663  os << "\t\t<software id=\"" << id << "\" version=\"" << software.getVersion() << "\" >\n";
3664  ControlledVocabulary::CVTerm so_term = getChildWithName_("MS:1000531", software.getName());
3665  if (so_term.id == "")
3666  {
3667  so_term = getChildWithName_("MS:1000531", software.getName() + " software"); //act of desperation to find the right cv and keep compatible with older cv mzmls
3668  }
3669  if (so_term.id == "")
3670  {
3671  so_term = getChildWithName_("MS:1000531", "TOPP " + software.getName()); //act of desperation to find the right cv and keep compatible with older cv mzmls
3672  }
3673  if (so_term.id == "MS:1000799")
3674  {
3675  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000799\" name=\"custom unreleased software tool\" value=\"\" />\n";
3676  }
3677  else if (so_term.id != "")
3678  {
3679  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"" << so_term.id << "\" name=\"" << writeXMLEscape(so_term.name) << "\" />\n";
3680  }
3681  else
3682  {
3683  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000799\" name=\"custom unreleased software tool\" value=\"" << writeXMLEscape(software.getName()) << "\" />\n";
3684  }
3685  writeUserParam_(os, software, 3, "/mzML/Software/cvParam/@accession", validator);
3686  os << "\t\t</software>\n";
3687  }
3688 
3689  template <typename MapType>
3690  void MzMLHandler<MapType>::writeSourceFile_(std::ostream& os, const String& id, const SourceFile& source_file, Internal::MzMLValidator& validator)
3691  {
3692  os << "\t\t\t<sourceFile id=\"" << id << "\" name=\"" << writeXMLEscape(source_file.getNameOfFile()) << "\" location=\"" << writeXMLEscape(source_file.getPathToFile()) << "\">\n";
3693  //checksum
3694  if (source_file.getChecksumType() == SourceFile::SHA1)
3695  {
3696  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000569\" name=\"SHA-1\" value=\"" << source_file.getChecksum() << "\" />\n";
3697  }
3698  else if (source_file.getChecksumType() == SourceFile::MD5)
3699  {
3700  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000568\" name=\"MD5\" value=\"" << source_file.getChecksum() << "\" />\n";
3701  }
3702  else //FORCED
3703  {
3704  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000569\" name=\"SHA-1\" value=\"\" />\n";
3705  }
3706  //file type
3707  ControlledVocabulary::CVTerm ft_term = getChildWithName_("MS:1000560", source_file.getFileType());
3708  if (ft_term.id.empty() && source_file.getFileType().hasSuffix("file"))
3709  {
3710  ft_term = getChildWithName_("MS:1000560", source_file.getFileType().chop(4) + "format"); // this is born out of desperation that sourcefile has a string interface for its filetype and not the enum, which could have been easily manipulated to the updated cv
3711  }
3712  if (ft_term.id != "")
3713  {
3714  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"" << ft_term.id << "\" name=\"" << ft_term.name << "\" />\n";
3715  }
3716  else //FORCED
3717  {
3718  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000564\" name=\"PSI mzData format\" />\n";
3719  }
3720  //native ID format
3721  ControlledVocabulary::CVTerm id_term = getChildWithName_("MS:1000767", source_file.getNativeIDType());
3722  if (id_term.id != "")
3723  {
3724  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"" << id_term.id << "\" name=\"" << id_term.name << "\" />\n";
3725  }
3726  else //FORCED
3727  {
3728  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000777\" name=\"spectrum identifier nativeID format\" />\n";
3729  }
3730  writeUserParam_(os, source_file, 4, "/mzML/fileDescription/sourceFileList/sourceFile/cvParam/@accession", validator);
3731  os << "\t\t\t</sourceFile>\n";
3732  }
3733 
3734  template <typename MapType>
3735  void MzMLHandler<MapType>::writeDataProcessing_(std::ostream& os, const String& id, const std::vector< ConstDataProcessingPtr >& dps, Internal::MzMLValidator& validator)
3736  {
3737  os << "\t\t<dataProcessing id=\"" << id << "\">\n";
3738 
3739  //FORCED
3740  if (dps.empty())
3741  {
3742  os << "\t\t\t<processingMethod order=\"0\" softwareRef=\"so_default\">\n";
3743  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000544\" name=\"Conversion to mzML\" />\n";
3744  os << "\t\t\t\t<userParam name=\"warning\" type=\"xsd:string\" value=\"fictional processing method used to fulfill format requirements\" />\n";
3745  os << "\t\t\t</processingMethod>\n";
3746  }
3747 
3748  bool written = false;
3749  for (Size i = 0; i < dps.size(); ++i)
3750  {
3751  //data processing action
3752  os << "\t\t\t<processingMethod order=\"0\" softwareRef=\"so_" << id << "_pm_" << i << "\">\n";
3753  if (dps[i]->getProcessingActions().count(DataProcessing::DATA_PROCESSING) == 1)
3754  {
3755  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000543\" name=\"data processing action\" />\n";
3756  written = true;
3757  }
3758  if (dps[i]->getProcessingActions().count(DataProcessing::CHARGE_DECONVOLUTION) == 1)
3759  {
3760  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000034\" name=\"charge deconvolution\" />\n";
3761  written = true;
3762  }
3763  if (dps[i]->getProcessingActions().count(DataProcessing::DEISOTOPING) == 1)
3764  {
3765  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000033\" name=\"deisotoping\" />\n";
3766  written = true;
3767  }
3768  if (dps[i]->getProcessingActions().count(DataProcessing::SMOOTHING) == 1)
3769  {
3770  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000592\" name=\"smoothing\" />\n";
3771  written = true;
3772  }
3773  if (dps[i]->getProcessingActions().count(DataProcessing::CHARGE_CALCULATION) == 1)
3774  {
3775  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000778\" name=\"charge state calculation\" />\n";
3776  written = true;
3777  }
3778  if (dps[i]->getProcessingActions().count(DataProcessing::PRECURSOR_RECALCULATION) == 1)
3779  {
3780  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000780\" name=\"precursor recalculation\" />\n";
3781  written = true;
3782  }
3783  if (dps[i]->getProcessingActions().count(DataProcessing::BASELINE_REDUCTION) == 1)
3784  {
3785  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000593\" name=\"baseline reduction\" />\n";
3786  written = true;
3787  }
3788  if (dps[i]->getProcessingActions().count(DataProcessing::PEAK_PICKING) == 1)
3789  {
3790  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000035\" name=\"peak picking\" />\n";
3791  written = true;
3792  }
3793  if (dps[i]->getProcessingActions().count(DataProcessing::ALIGNMENT) == 1)
3794  {
3795  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000745\" name=\"retention time alignment\" />\n";
3796  written = true;
3797  }
3798  if (dps[i]->getProcessingActions().count(DataProcessing::CALIBRATION) == 1)
3799  {
3800  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1001485\" name=\"m/z calibration\" />\n";
3801  written = true;
3802  }
3803  if (dps[i]->getProcessingActions().count(DataProcessing::NORMALIZATION) == 1)
3804  {
3805  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1001484\" name=\"intensity normalization\" />\n";
3806  written = true;
3807  }
3808  if (dps[i]->getProcessingActions().count(DataProcessing::FILTERING) == 1)
3809  {
3810  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1001486\" name=\"data filtering\" />\n";
3811  written = true;
3812  }
3813  //file format conversion
3814  if (dps[i]->getProcessingActions().count(DataProcessing::FORMAT_CONVERSION) == 1)
3815  {
3816  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000530\" name=\"file format conversion\" />\n";
3817  written = true;
3818  }
3819  if (dps[i]->getProcessingActions().count(DataProcessing::CONVERSION_MZDATA) == 1)
3820  {
3821  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000546\" name=\"Conversion to mzData\" />\n";
3822  written = true;
3823  }
3824  if (dps[i]->getProcessingActions().count(DataProcessing::CONVERSION_MZML) == 1)
3825  {
3826  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000544\" name=\"Conversion to mzML\" />\n";
3827  written = true;
3828  }
3829  if (dps[i]->getProcessingActions().count(DataProcessing::CONVERSION_MZXML) == 1)
3830  {
3831  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000545\" name=\"Conversion to mzXML\" />\n";
3832  written = true;
3833  }
3834  if (dps[i]->getProcessingActions().count(DataProcessing::CONVERSION_DTA) == 1)
3835  {
3836  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000741\" name=\"Conversion to dta\" />\n";
3837  written = true;
3838  }
3839  if (!written)
3840  {
3841  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000543\" name=\"data processing action\" />\n";
3842  }
3843 
3844  //data processing attribute
3845  if (dps[i]->getCompletionTime().isValid())
3846  {
3847  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000747\" name=\"completion time\" value=\"" << dps[i]->getCompletionTime().toString("yyyy-MM-dd+hh:mm").toStdString() << "\" />\n";
3848  }
3849 
3850  writeUserParam_(os, *(dps[i].get()), 4, "/mzML/dataProcessingList/dataProcessing/processingMethod/cvParam/@accession", validator);
3851  os << "\t\t\t</processingMethod>\n";
3852  }
3853 
3854  os << "\t\t</dataProcessing>\n";
3855  }
3856 
3857  template <typename MapType>
3858  void MzMLHandler<MapType>::writePrecursor_(std::ostream& os, const Precursor& precursor, Internal::MzMLValidator& validator)
3859  {
3860  os << "\t\t\t\t\t<precursor>\n";
3861  //--------------------------------------------------------------------------------------------
3862  //isolation window
3863  //--------------------------------------------------------------------------------------------
3864  os << "\t\t\t\t\t\t<isolationWindow>\n";
3865  os << "\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000827\" name=\"isolation window target m/z\" value=\"" << precursor.getMZ() << "\" unitAccession=\"MS:1000040\" unitName=\"m/z\" unitCvRef=\"MS\" />\n";
3866  os << "\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000828\" name=\"isolation window lower offset\" value=\"" << precursor.getIsolationWindowLowerOffset() << "\" unitAccession=\"MS:1000040\" unitName=\"m/z\" unitCvRef=\"MS\" />\n";
3867  os << "\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000829\" name=\"isolation window upper offset\" value=\"" << precursor.getIsolationWindowUpperOffset() << "\" unitAccession=\"MS:1000040\" unitName=\"m/z\" unitCvRef=\"MS\" />\n";
3868  os << "\t\t\t\t\t\t</isolationWindow>\n";
3869  //userParam: no extra object for it => no user parameters
3870 
3871  //--------------------------------------------------------------------------------------------
3872  //selected ion list
3873  //--------------------------------------------------------------------------------------------
3874  os << "\t\t\t\t\t\t<selectedIonList count=\"1\">\n";
3875  os << "\t\t\t\t\t\t\t<selectedIon>\n";
3876  os << "\t\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000744\" name=\"selected ion m/z\" value=\"" << precursor.getMZ() << "\" unitAccession=\"MS:1000040\" unitName=\"m/z\" unitCvRef=\"MS\" />\n";
3877  os << "\t\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000041\" name=\"charge state\" value=\"" << precursor.getCharge() << "\" />\n";
3878  os << "\t\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000042\" name=\"peak intensity\" value=\"" << precursor.getIntensity() << "\" unitAccession=\"MS:1000132\" unitName=\"percent of base peak\" unitCvRef=\"MS\" />\n";
3879  for (Size j = 0; j < precursor.getPossibleChargeStates().size(); ++j)
3880  {
3881  os << "\t\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000633\" name=\"possible charge state\" value=\"" << precursor.getPossibleChargeStates()[j] << "\" />\n";
3882  }
3883  //userParam: no extra object for it => no user parameters
3884  os << "\t\t\t\t\t\t\t</selectedIon>\n";
3885  os << "\t\t\t\t\t\t</selectedIonList>\n";
3886 
3887  //--------------------------------------------------------------------------------------------
3888  //activation
3889  //--------------------------------------------------------------------------------------------
3890  os << "\t\t\t\t\t\t<activation>\n";
3891 #pragma clang diagnostic push
3892 #pragma clang diagnostic ignored "-Wfloat-equal"
3893  if (precursor.getActivationEnergy() != 0)
3894 #pragma clang diagnostic pop
3895  {
3896  os << "\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000509\" name=\"activation energy\" value=\"" << precursor.getActivationEnergy() << "\" unitAccession=\"UO:0000266\" unitName=\"electronvolt\" unitCvRef=\"UO\" />\n";
3897  }
3898  if (precursor.getActivationMethods().count(Precursor::CID) != 0)
3899  {
3900  os << "\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000133\" name=\"collision-induced dissociation\" />\n";
3901  }
3902  if (precursor.getActivationMethods().count(Precursor::PD) != 0)
3903  {
3904  os << "\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000134\" name=\"plasma desorption\" />\n";
3905  }
3906  if (precursor.getActivationMethods().count(Precursor::PSD) != 0)
3907  {
3908  os << "\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000135\" name=\"post-source decay\" />\n";
3909  }
3910  if (precursor.getActivationMethods().count(Precursor::SID) != 0)
3911  {
3912  os << "\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000136\" name=\"surface-induced dissociation\" />\n";
3913  }
3914  if (precursor.getActivationMethods().count(Precursor::BIRD) != 0)
3915  {
3916  os << "\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000242\" name=\"blackbody infrared radiative dissociation\" />\n";
3917  }
3918  if (precursor.getActivationMethods().count(Precursor::ECD) != 0)
3919  {
3920  os << "\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000250\" name=\"electron capture dissociation\" />\n";
3921  }
3922  if (precursor.getActivationMethods().count(Precursor::IMD) != 0)
3923  {
3924  os << "\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000262\" name=\"infrared multiphoton dissociation\" />\n";
3925  }
3926  if (precursor.getActivationMethods().count(Precursor::SORI) != 0)
3927  {
3928  os << "\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000282\" name=\"sustained off-resonance irradiation\" />\n";
3929  }
3930  if (precursor.getActivationMethods().count(Precursor::HCID) != 0)
3931  {
3932  os << "\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000422\" name=\"high-energy collision-induced dissociation\" />\n";
3933  }
3934  if (precursor.getActivationMethods().count(Precursor::LCID) != 0)
3935  {
3936  os << "\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000433\" name=\"low-energy collision-induced dissociation\" />\n";
3937  }
3938  if (precursor.getActivationMethods().count(Precursor::PHD) != 0)
3939  {
3940  os << "\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000435\" name=\"photodissociation\" />\n";
3941  }
3942  if (precursor.getActivationMethods().count(Precursor::ETD) != 0)
3943  {
3944  os << "\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000598\" name=\"electron transfer dissociation\" />\n";
3945  }
3946  if (precursor.getActivationMethods().count(Precursor::PQD) != 0)
3947  {
3948  os << "\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000599\" name=\"pulsed q dissociation\" />\n";
3949  }
3950  if (precursor.getActivationMethods().empty())
3951  {
3952  os << "\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000044\" name=\"dissociation method\" />\n";
3953  }
3954  //as "precursor" has no own user param its userParam is stored here
3955  writeUserParam_(os, precursor, 6, "/mzML/run/spectrumList/spectrum/precursorList/precursor/activation/cvParam/@accession", validator);
3956  os << "\t\t\t\t\t\t</activation>\n";
3957  os << "\t\t\t\t\t</precursor>\n";
3958 
3959  }
3960 
3961  template <typename MapType>
3962  void MzMLHandler<MapType>::writeProduct_(std::ostream& os, const Product& product, Internal::MzMLValidator& validator)
3963  {
3964  os << "\t\t\t\t\t<product>\n";
3965  os << "\t\t\t\t\t\t<isolationWindow>\n";
3966  os << "\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000827\" name=\"isolation window target m/z\" value=\"" << product.getMZ() << "\" unitAccession=\"MS:1000040\" unitName=\"m/z\" unitCvRef=\"MS\" />\n";
3967  os << "\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000828\" name=\"isolation window lower offset\" value=\"" << product.getIsolationWindowLowerOffset() << "\" unitAccession=\"MS:1000040\" unitName=\"m/z\" unitCvRef=\"MS\" />\n";
3968  os << "\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000829\" name=\"isolation window upper offset\" value=\"" << product.getIsolationWindowUpperOffset() << "\" unitAccession=\"MS:1000040\" unitName=\"m/z\" unitCvRef=\"MS\" />\n";
3969  writeUserParam_(os, product, 7, "/mzML/run/spectrumList/spectrum/productList/product/isolationWindow/cvParam/@accession", validator);
3970  os << "\t\t\t\t\t\t</isolationWindow>\n";
3971  os << "\t\t\t\t\t</product>\n";
3972  }
3973 
3974  template <typename MapType>
3975  void MzMLHandler<MapType>::writeTo(std::ostream& os)
3976  {
3977  const MapType& exp = *(cexp_);
3978  logger_.startProgress(0, exp.size() + exp.getChromatograms().size(), "storing mzML file");
3979  int progress = 0;
3980  Internal::MzMLValidator validator(mapping_, cv_);
3981 
3982  std::vector<std::vector< ConstDataProcessingPtr > > dps;
3983  //--------------------------------------------------------------------------------------------
3984  //header
3985  //--------------------------------------------------------------------------------------------
3986  writeHeader_(os, exp, dps, validator);
3987 
3988  //--------------------------------------------------------------------------------------------
3989  //spectrum
3990  //--------------------------------------------------------------------------------------------
3991  if (exp.size() != 0)
3992  {
3993  // INFO : do not try to be smart and skip empty spectra or
3994  // chromatograms. There can be very good reasons for this (e.g. if the
3995  // meta information needs to be stored here but the actual data is
3996  // stored somewhere else).
3997  os << "\t\t<spectrumList count=\"" << exp.size() << "\" defaultDataProcessingRef=\"dp_sp_0\">\n";
3998 
3999  //check native ids
4000  bool renew_native_ids = false;
4001  for (Size s = 0; s < exp.size(); ++s)
4002  {
4003  if (!exp[s].getNativeID().has('='))
4004  {
4005  renew_native_ids = true;
4006  break;
4007  }
4008  }
4009  //issue warning if something is wrong
4010  if (renew_native_ids)
4011  {
4012  warning(STORE, String("Invalid native IDs detected. Using spectrum identifier nativeID format (spectrum=xsd:nonNegativeInteger) for all spectra."));
4013  }
4014 
4015  //write actual data
4016  for (Size s = 0; s < exp.size(); ++s)
4017  {
4018  logger_.setProgress(progress++);
4019  const SpectrumType& spec = exp[s];
4020  writeSpectrum_(os, spec, s, validator, renew_native_ids, dps);
4021  }
4022  os << "\t\t</spectrumList>\n";
4023  }
4024 
4025  //--------------------------------------------------------------------------------------------
4026  //chromatograms
4027  //--------------------------------------------------------------------------------------------
4028  if (!exp.getChromatograms().empty())
4029  {
4030  // INFO : do not try to be smart and skip empty spectra or
4031  // chromatograms. There can be very good reasons for this (e.g. if the
4032  // meta information needs to be stored here but the actual data is
4033  // stored somewhere else).
4034  os << "\t\t<chromatogramList count=\"" << exp.getChromatograms().size() << "\" defaultDataProcessingRef=\"dp_sp_0\">\n";
4035  for (Size c = 0; c != exp.getChromatograms().size(); ++c)
4036  {
4037  logger_.setProgress(progress++);
4038  const ChromatogramType& chromatogram = exp.getChromatograms()[c];
4039  writeChromatogram_(os, chromatogram, c, validator);
4040  }
4041  os << "\t\t</chromatogramList>" << "\n";
4042  }
4043 
4044  MzMLHandlerHelper::writeFooter_(os, options_, spectra_offsets, chromatograms_offsets);
4045  logger_.endProgress();
4046  }
4047 
4048  template <typename MapType>
4049  void MzMLHandler<MapType>::writeHeader_(std::ostream& os, const MapType& exp,
4050  std::vector<std::vector< ConstDataProcessingPtr > >& dps, Internal::MzMLValidator& validator)
4051  {
4052  os << "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
4053 
4054  if (options_.getWriteIndex())
4055  {
4056  os << "<indexedmzML xmlns=\"http://psi.hupo.org/ms/mzml\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://psi.hupo.org/ms/mzml http://psidev.info/files/ms/mzML/xsd/mzML1.1.0_idx.xsd\">\n";
4057  }
4058  os << "<mzML xmlns=\"http://psi.hupo.org/ms/mzml\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://psi.hupo.org/ms/mzml http://psidev.info/files/ms/mzML/xsd/mzML1.1.0.xsd\" accession=\"" << writeXMLEscape(exp.getIdentifier()) << "\" version=\"" << version_ << "\">\n";
4059  //--------------------------------------------------------------------------------------------
4060  // CV list
4061  //--------------------------------------------------------------------------------------------
4062  os << "\t<cvList count=\"5\">\n"
4063  << "\t\t<cv id=\"MS\" fullName=\"Proteomics Standards Initiative Mass Spectrometry Ontology\" URI=\"http://psidev.cvs.sourceforge.net/*checkout*/psidev/psi/psi-ms/mzML/controlledVocabulary/psi-ms.obo\"/>\n"
4064  << "\t\t<cv id=\"UO\" fullName=\"Unit Ontology\" URI=\"http://obo.cvs.sourceforge.net/obo/obo/ontology/phenotype/unit.obo\"/>\n"
4065  << "\t\t<cv id=\"BTO\" fullName=\"BrendaTissue545\" version=\"unknown\" URI=\"http://www.brenda-enzymes.info/ontology/tissue/tree/update/update_files/BrendaTissueOBO\"/>\n"
4066  << "\t\t<cv id=\"GO\" fullName=\"Gene Ontology - Slim Versions\" version=\"unknown\" URI=\"http://www.geneontology.org/GO_slims/goslim_goa.obo\"/>\n"
4067  << "\t\t<cv id=\"PATO\" fullName=\"Quality ontology\" version=\"unknown\" URI=\"http://obo.cvs.sourceforge.net/*checkout*/obo/obo/ontology/phenotype/quality.obo\"/>\n"
4068  << "\t</cvList>\n";
4069  //--------------------------------------------------------------------------------------------
4070  // file content
4071  //--------------------------------------------------------------------------------------------
4072  os << "\t<fileDescription>\n";
4073  os << "\t\t<fileContent>\n";
4075  for (Size i = 0; i < exp.size(); ++i)
4076  {
4077  ++file_content[exp[i].getInstrumentSettings().getScanMode()];
4078  }
4079  if (file_content.has(InstrumentSettings::MASSSPECTRUM))
4080  {
4081  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000294\" name=\"mass spectrum\" />\n";
4082  }
4083  if (file_content.has(InstrumentSettings::MS1SPECTRUM))
4084  {
4085  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000579\" name=\"MS1 spectrum\" />\n";
4086  }
4087  if (file_content.has(InstrumentSettings::MSNSPECTRUM))
4088  {
4089  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000580\" name=\"MSn spectrum\" />\n";
4090  }
4091  if (file_content.has(InstrumentSettings::SIM))
4092  {
4093  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000582\" name=\"SIM spectrum\" />\n";
4094  }
4095  if (file_content.has(InstrumentSettings::SRM))
4096  {
4097  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000583\" name=\"SRM spectrum\" />\n";
4098  }
4099  if (file_content.has(InstrumentSettings::CRM))
4100  {
4101  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000581\" name=\"CRM spectrum\" />\n";
4102  }
4103  if (file_content.has(InstrumentSettings::PRECURSOR))
4104  {
4105  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000341\" name=\"precursor ion spectrum\" />\n";
4106  }
4107  if (file_content.has(InstrumentSettings::CNG))
4108  {
4109  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000325\" name=\"constant neutral gain spectrum\" />\n";
4110  }
4111  if (file_content.has(InstrumentSettings::CNL))
4112  {
4113  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000326\" name=\"constant neutral loss spectrum\" />\n";
4114  }
4115  if (file_content.has(InstrumentSettings::EMR))
4116  {
4117  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000804\" name=\"electromagnetic radiation spectrum\" />\n";
4118  }
4119  if (file_content.has(InstrumentSettings::EMISSION))
4120  {
4121  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000805\" name=\"emission spectrum\" />\n";
4122  }
4123  if (file_content.has(InstrumentSettings::ABSORBTION))
4124  {
4125  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000806\" name=\"absorption spectrum\" />\n";
4126  }
4127  if (file_content.has(InstrumentSettings::EMC))
4128  {
4129  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000789\" name=\"enhanced multiply charged spectrum\" />\n";
4130  }
4131  if (file_content.has(InstrumentSettings::TDF))
4132  {
4133  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000789\" name=\"time-delayed fragmentation spectrum\" />\n";
4134  }
4135  if (file_content.has(InstrumentSettings::UNKNOWN) || file_content.empty())
4136  {
4137  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000294\" name=\"mass spectrum\" />\n";
4138  }
4139  // writeUserParam_(os, exp, 3, "/mzML/fileDescription/fileContent/cvParam/@accession", validator);
4140  os << "\t\t</fileContent>\n";
4141 
4142  //--------------------------------------------------------------------------------------------
4143  // source file list
4144  //--------------------------------------------------------------------------------------------
4145  //find out how many spectra source files need to be written
4146  UInt sf_sp_count = 0;
4147  for (Size i = 0; i < exp.size(); ++i)
4148  {
4149  if (exp[i].getSourceFile() != SourceFile())
4150  {
4151  ++sf_sp_count;
4152  }
4153  }
4154  if (exp.getSourceFiles().size() > 0 || sf_sp_count > 0)
4155  {
4156  os << "\t\t<sourceFileList count=\"" << exp.getSourceFiles().size() + sf_sp_count << "\">\n";
4157 
4158  //write source file of run
4159  for (Size i = 0; i < exp.getSourceFiles().size(); ++i)
4160  {
4161  writeSourceFile_(os, String("sf_ru_") + String(i), exp.getSourceFiles()[i], validator);
4162  }
4163 
4164  // write source files of spectra
4165  if (sf_sp_count > 0)
4166  {
4167  const SourceFile sf_default;
4168  for (Size i = 0; i < exp.size(); ++i)
4169  {
4170  if (exp[i].getSourceFile() != sf_default)
4171  {
4172  writeSourceFile_(os, String("sf_sp_") + i, exp[i].getSourceFile(), validator);
4173  }
4174  }
4175  }
4176 
4177  os << "\t\t</sourceFileList>\n";
4178  }
4179 
4180  //--------------------------------------------------------------------------------------------
4181  // contacts
4182  //--------------------------------------------------------------------------------------------
4183  for (Size i = 0; i < exp.getContacts().size(); ++i)
4184  {
4185  const ContactPerson& cp = exp.getContacts()[i];
4186  os << "\t\t<contact>\n";
4187  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000586\" name=\"contact name\" value=\"" << writeXMLEscape(cp.getLastName()) << ", " << writeXMLEscape(cp.getFirstName()) << "\" />\n";
4188  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000590\" name=\"contact affiliation\" value=\"" << writeXMLEscape(cp.getInstitution()) << "\" />\n";
4189 
4190  if (cp.getAddress() != "")
4191  {
4192  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000587\" name=\"contact address\" value=\"" << writeXMLEscape(cp.getAddress()) << "\" />\n";
4193  }
4194  if (cp.getURL() != "")
4195  {
4196  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000588\" name=\"contact URL\" value=\"" << writeXMLEscape(cp.getURL()) << "\" />\n";
4197  }
4198  if (cp.getEmail() != "")
4199  {
4200  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000589\" name=\"contact email\" value=\"" << writeXMLEscape(cp.getEmail()) << "\" />\n";
4201  }
4202  if (cp.getContactInfo() != "")
4203  {
4204  os << "\t\t\t<userParam name=\"contact_info\" type=\"xsd:string\" value=\"" << writeXMLEscape(cp.getContactInfo()) << "\" />\n";
4205  }
4206  writeUserParam_(os, cp, 3, "/mzML/fileDescription/contact/cvParam/@accession", validator);
4207  os << "\t\t</contact>\n";
4208  }
4209  os << "\t</fileDescription>\n";
4210 
4211  //--------------------------------------------------------------------------------------------
4212  // sample
4213  //--------------------------------------------------------------------------------------------
4214  const Sample& sa = exp.getSample();
4215  os << "\t<sampleList count=\"1\">\n";
4216  os << "\t\t<sample id=\"sa_0\" name=\"" << writeXMLEscape(sa.getName()) << "\">\n";
4217  if (sa.getNumber() != "")
4218  {
4219  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000001\" name=\"sample number\" value=\"" << writeXMLEscape(sa.getNumber()) << "\" />\n";
4220  }
4221  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000004\" name=\"sample mass\" value=\"" << sa.getMass() << "\" unitAccession=\"UO:0000021\" unitName=\"gram\" unitCvRef=\"UO\" />\n";
4222  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000005\" name=\"sample volume\" value=\"" << sa.getVolume() << "\" unitAccession=\"UO:0000098\" unitName=\"milliliter\" unitCvRef=\"UO\" />\n";
4223  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000006\" name=\"sample concentration\" value=\"" << sa.getConcentration() << "\" unitAccession=\"UO:0000175\" unitName=\"gram per liter\" unitCvRef=\"UO\" />\n";
4224  if (sa.getState() == Sample::EMULSION)
4225  {
4226  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000047\" name=\"emulsion\" />\n";
4227  }
4228  else if (sa.getState() == Sample::GAS)
4229  {
4230  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000048\" name=\"gas\" />\n";
4231  }
4232  else if (sa.getState() == Sample::LIQUID)
4233  {
4234  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000049\" name=\"liquid\" />\n";
4235  }
4236  else if (sa.getState() == Sample::SOLID)
4237  {
4238  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000050\" name=\"solid\" />\n";
4239  }
4240  else if (sa.getState() == Sample::SOLUTION)
4241  {
4242  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000051\" name=\"solution\" />\n";
4243  }
4244  else if (sa.getState() == Sample::SUSPENSION)
4245  {
4246  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000052\" name=\"suspension\" />\n";
4247  }
4248  if (sa.getComment() != "")
4249  {
4250  os << "\t\t\t<userParam name=\"comment\" type=\"xsd:string\" value=\"" << writeXMLEscape(sa.getComment()) << "\" />\n";
4251  }
4252  writeUserParam_(os, sa, 3, "/mzML/sampleList/sample/cvParam/@accession", validator);
4253  os << "\t\t</sample>\n";
4254  os << "\t</sampleList>\n";
4255 
4256  //--------------------------------------------------------------------------------------------
4257  // Software
4258  //--------------------------------------------------------------------------------------------
4259 
4260  // instrument software and fallback software is always written (see below)
4261  Size num_software(2);
4262 
4263  // Create a list of all different data processings: check if the
4264  // DataProcessing of the current spectra/chromatogram is already present
4265  // and if not, append it to the dps vector
4266  for (Size s = 0; s < exp.size(); ++s)
4267  {
4268  bool already_present = false;
4269  for (Size j = 0; j < dps.size(); j++)
4270  {
4271  already_present = OpenMS::Helpers::cmpPtrContainer(
4272  exp[s].getDataProcessing(), dps[j]);
4273  if (already_present) break;
4274  }
4275  if (!already_present)
4276  {
4277  dps.push_back(exp[s].getDataProcessing());
4278  num_software += exp[s].getDataProcessing().size();
4279  }
4280  }
4281  for (Size s = 0; s < exp.getChromatograms().size(); ++s)
4282  {
4283  bool already_present = false;
4284  for (Size j = 0; j < dps.size(); j++)
4285  {
4286  already_present = OpenMS::Helpers::cmpPtrContainer(
4287  exp.getChromatograms()[s].getDataProcessing(), dps[j]);
4288  if (already_present) break;
4289  }
4290  if (!already_present)
4291  {
4292  dps.push_back(exp.getChromatograms()[s].getDataProcessing());
4293  num_software += exp.getChromatograms()[s].getDataProcessing().size();
4294  }
4295  }
4296 
4297  // count binary data array software
4298  Size num_bi_software(0);
4299 
4300  for (Size s = 0; s < exp.size(); ++s)
4301  {
4302  for (Size m = 0; m < exp[s].getFloatDataArrays().size(); ++m)
4303  {
4304  for (Size i = 0; i < exp[s].getFloatDataArrays()[m].getDataProcessing().size(); ++i)
4305  {
4306  ++num_bi_software;
4307  }
4308  }
4309  }
4310 
4311  os << "\t<softwareList count=\"" << num_software + num_bi_software << "\">\n";
4312 
4313  // write instrument software
4314  writeSoftware_(os, "so_in_0", exp.getInstrument().getSoftware(), validator);
4315 
4316  // write fallback software
4317  writeSoftware_(os, "so_default", Software(), validator);
4318 
4319  // write the software of the dps
4320  for (Size s1 = 0; s1 != dps.size(); ++s1)
4321  {
4322  for (Size s2 = 0; s2 != dps[s1].size(); ++s2)
4323  {
4324  writeSoftware_(os, String("so_dp_sp_") + s1 + "_pm_" + s2, dps[s1][s2]->getSoftware(), validator);
4325  }
4326  }
4327 
4328  //write data processing (for each binary data array)
4329  for (Size s = 0; s < exp.size(); ++s)
4330  {
4331  for (Size m = 0; m < exp[s].getFloatDataArrays().size(); ++m)
4332  {
4333  for (Size i = 0; i < exp[s].getFloatDataArrays()[m].getDataProcessing().size(); ++i)
4334  {
4335  writeSoftware_(os, String("so_dp_sp_") + s + "_bi_" + m + "_pm_" + i,
4336  exp[s].getFloatDataArrays()[m].getDataProcessing()[i]->getSoftware(), validator);
4337  }
4338  }
4339  }
4340  os << "\t</softwareList>\n";
4341 
4342  //--------------------------------------------------------------------------------------------
4343  // instrument configuration (enclosing ion source, mass analyzer and detector)
4344  //--------------------------------------------------------------------------------------------
4345  const Instrument& in = exp.getInstrument();
4346  os << "\t<instrumentConfigurationList count=\"1\">\n";
4347  os << "\t\t<instrumentConfiguration id=\"ic_0\">\n";
4348  ControlledVocabulary::CVTerm in_term = getChildWithName_("MS:1000031", in.getName());
4349  if (in_term.id != "")
4350  {
4351  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"" << in_term.id << "\" name=\"" << writeXMLEscape(in_term.name) << "\" />\n";
4352  }
4353  else
4354  {
4355  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000031\" name=\"instrument model\" />\n";
4356  }
4357 
4358  if (in.getCustomizations() != "")
4359  {
4360  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000032\" name=\"customization\" value=\"" << writeXMLEscape(in.getCustomizations()) << "\" />\n";
4361  }
4362 
4363  //ion optics
4365  {
4366  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000221\" name=\"magnetic deflection\" />\n";
4367  }
4369  {
4370  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000246\" name=\"delayed extraction\" />\n";
4371  }
4373  {
4374  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000275\" name=\"collision quadrupole\" />\n";
4375  }
4377  {
4378  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000281\" name=\"selected ion flow tube\" />\n";
4379  }
4381  {
4382  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000286\" name=\"time lag focusing\" />\n";
4383  }
4384  else if (in.getIonOptics() == Instrument::REFLECTRON)
4385  {
4386  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000300\" name=\"reflectron\" />\n";
4387  }
4388  else if (in.getIonOptics() == Instrument::EINZEL_LENS)
4389  {
4390  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000307\" name=\"einzel lens\" />\n";
4391  }
4393  {
4394  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000309\" name=\"first stability region\" />\n";
4395  }
4396  else if (in.getIonOptics() == Instrument::FRINGING_FIELD)
4397  {
4398  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000310\" name=\"fringing field\" />\n";
4399  }
4401  {
4402  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000311\" name=\"kinetic energy analyzer\" />\n";
4403  }
4404  else if (in.getIonOptics() == Instrument::STATIC_FIELD)
4405  {
4406  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000320\" name=\"static field\" />\n";
4407  }
4408 
4409  writeUserParam_(os, in, 3, "/mzML/instrumentConfigurationList/instrumentConfiguration/cvParam/@accession", validator);
4410  Size component_count = in.getIonSources().size() + in.getMassAnalyzers().size() + in.getIonDetectors().size();
4411  if (component_count != 0)
4412  {
4413  os << "\t\t\t<componentList count=\"" << (std::max)((Size)3, component_count) << "\">\n";
4414  //--------------------------------------------------------------------------------------------
4415  // ion source
4416  //--------------------------------------------------------------------------------------------
4417  for (Size i = 0; i < in.getIonSources().size(); ++i)
4418  {
4419  const IonSource& so = in.getIonSources()[i];
4420  os << "\t\t\t\t<source order=\"" << so.getOrder() << "\">\n";
4421 
4423  {
4424  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000055\" name=\"continuous flow fast atom bombardment\" />\n";
4425  }
4426  else if (so.getInletType() == IonSource::DIRECT)
4427  {
4428  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000056\" name=\"direct inlet\" />\n";
4429  }
4430  else if (so.getInletType() == IonSource::ELECTROSPRAYINLET)
4431  {
4432  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000057\" name=\"electrospray inlet\" />\n";
4433  }
4435  {
4436  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000058\" name=\"flow injection analysis\" />\n";
4437  }
4439  {
4440  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000059\" name=\"inductively coupled plasma\" />\n";
4441  }
4442  else if (so.getInletType() == IonSource::INFUSION)
4443  {
4444  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000060\" name=\"infusion\" />\n";
4445  }
4446  else if (so.getInletType() == IonSource::JETSEPARATOR)
4447  {
4448  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000061\" name=\"jet separator\" />\n";
4449  }
4450  else if (so.getInletType() == IonSource::MEMBRANESEPARATOR)
4451  {
4452  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000062\" name=\"membrane separator\" />\n";
4453  }
4454  else if (so.getInletType() == IonSource::MOVINGBELT)
4455  {
4456  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000063\" name=\"moving belt\" />\n";
4457  }
4458  else if (so.getInletType() == IonSource::MOVINGWIRE)
4459  {
4460  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000064\" name=\"moving wire\" />\n";
4461  }
4462  else if (so.getInletType() == IonSource::OPENSPLIT)
4463  {
4464  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000065\" name=\"open split\" />\n";
4465  }
4466  else if (so.getInletType() == IonSource::PARTICLEBEAM)
4467  {
4468  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000066\" name=\"particle beam\" />\n";
4469  }
4470  else if (so.getInletType() == IonSource::RESERVOIR)
4471  {
4472  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000067\" name=\"reservoir\" />\n";
4473  }
4474  else if (so.getInletType() == IonSource::SEPTUM)
4475  {
4476  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000068\" name=\"septum\" />\n";
4477  }
4478  else if (so.getInletType() == IonSource::THERMOSPRAYINLET)
4479  {
4480  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000069\" name=\"thermospray inlet\" />\n";
4481  }
4482  else if (so.getInletType() == IonSource::BATCH)
4483  {
4484  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000248\" name=\"direct insertion probe\" />\n";
4485  }
4486  else if (so.getInletType() == IonSource::CHROMATOGRAPHY)
4487  {
4488  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000249\" name=\"direct liquid introduction\" />\n";
4489  }
4490  else if (so.getInletType() == IonSource::MEMBRANE)
4491  {
4492  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000396\" name=\"membrane inlet\" />\n";
4493  }
4494  else if (so.getInletType() == IonSource::NANOSPRAY)
4495  {
4496  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000485\" name=\"nanospray inlet\" />\n";
4497  }
4498 
4500  {
4501  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000070\" name=\"atmospheric pressure chemical ionization\" />\n";
4502  }
4503  else if (so.getIonizationMethod() == IonSource::CI)
4504  {
4505  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000071\" name=\"chemical ionization\" />\n";
4506  }
4507  else if (so.getIonizationMethod() == IonSource::ESI)
4508  {
4509  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000073\" name=\"electrospray ionization\" />\n";
4510  }
4511  else if (so.getIonizationMethod() == IonSource::FAB)
4512  {
4513  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000074\" name=\"fast atom bombardment ionization\" />\n";
4514  }
4515  else if (so.getIonizationMethod() == IonSource::MALDI)
4516  {
4517  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000075\" name=\"matrix-assisted laser desorption ionization\" />\n";
4518  }
4519  else if (so.getIonizationMethod() == IonSource::MPI)
4520  {
4521  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000227\" name=\"multiphoton ionization\" />\n";
4522  }
4523  else if (so.getIonizationMethod() == IonSource::AP_MALDI)
4524  {
4525  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000239\" name=\"atmospheric pressure matrix-assisted laser desorption ionization\" />\n";
4526  }
4527  else if (so.getIonizationMethod() == IonSource::API)
4528  {
4529  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000240\" name=\"atmospheric pressure ionization\" />\n";
4530  }
4531  else if (so.getIonizationMethod() == IonSource::DI)
4532  {
4533  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000247\" name=\"desorption ionization\" />\n";
4534  }
4535  else if (so.getIonizationMethod() == IonSource::FA)
4536  {
4537  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000255\" name=\"flowing afterglow\" />\n";
4538  }
4539  else if (so.getIonizationMethod() == IonSource::FD)
4540  {
4541  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000257\" name=\"field desorption\" />\n";
4542  }
4543  else if (so.getIonizationMethod() == IonSource::FI)
4544  {
4545  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000258\" name=\"field ionization\" />\n";
4546  }
4547  else if (so.getIonizationMethod() == IonSource::GD_MS)
4548  {
4549  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000259\" name=\"glow discharge ionization\" />\n";
4550  }
4551  else if (so.getIonizationMethod() == IonSource::NICI)
4552  {
4553  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000271\" name=\"Negative ion chemical ionization\" />\n";
4554  }
4555  else if (so.getIonizationMethod() == IonSource::NRMS)
4556  {
4557  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000272\" name=\"neutralization reionization mass spectrometry\" />\n";
4558  }
4559  else if (so.getIonizationMethod() == IonSource::PI)
4560  {
4561  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000273\" name=\"photoionization\" />\n";
4562  }
4563  else if (so.getIonizationMethod() == IonSource::PYMS)
4564  {
4565  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000274\" name=\"pyrolysis mass spectrometry\" />\n";
4566  }
4567  else if (so.getIonizationMethod() == IonSource::REMPI)
4568  {
4569  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000276\" name=\"resonance enhanced multiphoton ionization\" />\n";
4570  }
4571  else if (so.getIonizationMethod() == IonSource::SELDI)
4572  {
4573  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000278\" name=\"surface enhanced laser desorption ionization\" />\n";
4574  }
4575  else if (so.getIonizationMethod() == IonSource::SEND)
4576  {
4577  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000279\" name=\"surface enhanced neat desorption\" />\n";
4578  }
4579  else if (so.getIonizationMethod() == IonSource::AI)
4580  {
4581  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000380\" name=\"adiabatic ionization\" />\n";
4582  }
4583  else if (so.getIonizationMethod() == IonSource::ASI)
4584  {
4585  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000381\" name=\"associative ionization\" />\n";
4586  }
4587  else if (so.getIonizationMethod() == IonSource::APPI)
4588  {
4589  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000382\" name=\"atmospheric pressure photoionization\" />\n";
4590  }
4591  else if (so.getIonizationMethod() == IonSource::AD)
4592  {
4593  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000383\" name=\"autodetachment\" />\n";
4594  }
4595  else if (so.getIonizationMethod() == IonSource::AUI)
4596  {
4597  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000384\" name=\"autoionization\" />\n";
4598  }
4599  else if (so.getIonizationMethod() == IonSource::CEI)
4600  {
4601  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000385\" name=\"charge exchange ionization\" />\n";
4602  }
4603  else if (so.getIonizationMethod() == IonSource::CHEMI)
4604  {
4605  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000386\" name=\"chemi-ionization\" />\n";
4606  }
4607  else if (so.getIonizationMethod() == IonSource::SILI)
4608  {
4609  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000387\" name=\"desorption/ionization on silicon\" />\n";
4610  }
4611  else if (so.getIonizationMethod() == IonSource::DISSI)
4612  {
4613  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000388\" name=\"dissociative ionization\" />\n";
4614  }
4615  else if (so.getIonizationMethod() == IonSource::EI)
4616  {
4617  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000389\" name=\"electron ionization\" />\n";
4618  }
4619  else if (so.getIonizationMethod() == IonSource::LD)
4620  {
4621  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000393\" name=\"laser desorption ionization\" />\n";
4622  }
4623  else if (so.getIonizationMethod() == IonSource::LSI)
4624  {
4625  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000395\" name=\"liquid secondary ionization\" />\n";
4626  }
4627  else if (so.getIonizationMethod() == IonSource::MESI)
4628  {
4629  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000397\" name=\"microelectrospray\" />\n";
4630  }
4631  else if (so.getIonizationMethod() == IonSource::NESI)
4632  {
4633  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000398\" name=\"nanoelectrospray\" />\n";
4634  }
4635  else if (so.getIonizationMethod() == IonSource::PEI)
4636  {
4637  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000399\" name=\"penning ionization\" />\n";
4638  }
4639  else if (so.getIonizationMethod() == IonSource::PD)
4640  {
4641  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000400\" name=\"plasma desorption ionization\" />\n";
4642  }
4643  else if (so.getIonizationMethod() == IonSource::SI)
4644  {
4645  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000402\" name=\"secondary ionization\" />\n";
4646  }
4647  else if (so.getIonizationMethod() == IonSource::SOI)
4648  {
4649  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000403\" name=\"soft ionization\" />\n";
4650  }
4651  else if (so.getIonizationMethod() == IonSource::SPI)
4652  {
4653  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000404\" name=\"spark ionization\" />\n";
4654  }
4655  else if (so.getIonizationMethod() == IonSource::SALDI)
4656  {
4657  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000405\" name=\"surface-assisted laser desorption ionization\" />\n";
4658  }
4659  else if (so.getIonizationMethod() == IonSource::SUI)
4660  {
4661  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000406\" name=\"surface ionization\" />\n";
4662  }
4663  else if (so.getIonizationMethod() == IonSource::TI)
4664  {
4665  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000407\" name=\"thermal ionization\" />\n";
4666  }
4667  else if (so.getIonizationMethod() == IonSource::VI)
4668  {
4669  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000408\" name=\"vertical ionization\" />\n";
4670  }
4671  else if (so.getIonizationMethod() == IonSource::FIB)
4672  {
4673  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000446\" name=\"fast ion bombardment\" />\n";
4674  }
4676  {
4677  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000008\" name=\"ionization type\" />\n";
4678  }
4679 
4680  writeUserParam_(os, so, 5, "/mzML/instrumentConfigurationList/instrumentConfiguration/componentList/source/cvParam/@accession", validator);
4681  os << "\t\t\t\t</source>\n";
4682  }
4683  //FORCED
4684  if (component_count < 3 && in.getIonSources().empty())
4685  {
4686  os << "\t\t\t\t<source order=\"1234\">\n";
4687  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000446\" name=\"fast ion bombardment\" />\n";
4688  os << "\t\t\t\t\t<userParam name=\"warning\" type=\"xsd:string\" value=\"invented ion source, to fulfill mzML schema\" />\n";
4689  os << "\t\t\t\t</source>\n";
4690  }
4691  //--------------------------------------------------------------------------------------------
4692  // mass analyzer
4693  //--------------------------------------------------------------------------------------------
4694  for (Size i = 0; i < in.getMassAnalyzers().size(); ++i)
4695  {
4696  const MassAnalyzer& ma = in.getMassAnalyzers()[i];
4697  os << "\t\t\t\t<analyzer order=\"" << ma.getOrder() << "\">\n";
4698 
4699  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000014\" name=\"accuracy\" value=\"" << ma.getAccuracy() << "\" unitAccession=\"UO:0000169\" unitName=\"parts per million\" unitCvRef=\"UO\" />\n";
4700  // @todo: the parameters below are instrument specific and should not be written every time
4701  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000022\" name=\"TOF Total Path Length\" value=\"" << ma.getTOFTotalPathLength() << "\" unitAccession=\"UO:0000008\" unitName=\"meter\" unitCvRef=\"UO\" />\n";
4702  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000024\" name=\"final MS exponent\" value=\"" << ma.getFinalMSExponent() << "\" />\n";
4703  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000025\" name=\"magnetic field strength\" value=\"" << ma.getMagneticFieldStrength() << "\" unitAccession=\"UO:0000228\" unitName=\"tesla\" unitCvRef=\"UO\" />\n";
4704 
4706  {
4707  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000106\" name=\"reflectron on\" />\n";
4708 
4709  }
4710  else if (ma.getReflectronState() == MassAnalyzer::OFF)
4711  {
4712  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000105\" name=\"reflectron off\" />\n";
4713  }
4714 
4716  {
4717  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000079\" name=\"fourier transform ion cyclotron resonance mass spectrometer\" />\n";
4718  }
4719  else if (ma.getType() == MassAnalyzer::SECTOR)
4720  {
4721  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000080\" name=\"magnetic sector\" />\n";
4722  }
4723  else if (ma.getType() == MassAnalyzer::QUADRUPOLE)
4724  {
4725  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000081\" name=\"quadrupole\" />\n";
4726  }
4727  else if (ma.getType() == MassAnalyzer::TOF)
4728  {
4729  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000084\" name=\"time-of-flight\" />\n";
4730  }
4731  else if (ma.getType() == MassAnalyzer::ESA)
4732  {
4733  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000254\" name=\"electrostatic energy analyzer\" />\n";
4734  }
4735  else if (ma.getType() == MassAnalyzer::IT)
4736  {
4737  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000264\" name=\"ion trap\" />\n";
4738  }
4739  else if (ma.getType() == MassAnalyzer::SWIFT)
4740  {
4741  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000284\" name=\"stored waveform inverse fourier transform\" />\n";
4742  }
4743  else if (ma.getType() == MassAnalyzer::CYCLOTRON)
4744  {
4745  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000288\" name=\"cyclotron\" />\n";
4746  }
4747  else if (ma.getType() == MassAnalyzer::ORBITRAP)
4748  {
4749  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000484\" name=\"orbitrap\" />\n";
4750  }
4752  {
4753  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000078\" name=\"axial ejection linear ion trap\" />\n";
4754  }
4755  else if (ma.getType() == MassAnalyzer::PAULIONTRAP)
4756  {
4757  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000082\" name=\"quadrupole ion trap\" />\n";
4758  }
4760  {
4761  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000083\" name=\"radial ejection linear ion trap\" />\n";
4762  }
4763  else if (ma.getType() == MassAnalyzer::LIT)
4764  {
4765  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000291\" name=\"linear ion trap\" />\n";
4766  }
4767  else if (ma.getType() == MassAnalyzer::ANALYZERNULL)
4768  {
4769  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000443\" name=\"mass analyzer type\" />\n";
4770  }
4771 
4772  writeUserParam_(os, ma, 5, "/mzML/instrumentConfigurationList/instrumentConfiguration/componentList/analyzer/cvParam/@accession", validator);
4773  os << "\t\t\t\t</analyzer>\n";
4774  }
4775  //FORCED
4776  if (component_count < 3 && in.getMassAnalyzers().empty())
4777  {
4778  os << "\t\t\t\t<analyzer order=\"1234\">\n";
4779  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000288\" name=\"cyclotron\" />\n";
4780  os << "\t\t\t\t\t<userParam name=\"warning\" type=\"xsd:string\" value=\"invented mass analyzer, to fulfill mzML schema\" />\n";
4781  os << "\t\t\t\t</analyzer>\n";
4782  }
4783  //--------------------------------------------------------------------------------------------
4784  // ion detector
4785  //--------------------------------------------------------------------------------------------
4786  for (Size i = 0; i < in.getIonDetectors().size(); ++i)
4787  {
4788  const IonDetector& id = in.getIonDetectors()[i];
4789  os << "\t\t\t\t<detector order=\"" << id.getOrder() << "\">\n";
4790 
4791  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000028\" name=\"detector resolution\" value=\"" << id.getResolution() << "\" />\n";
4792  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000029\" name=\"sampling frequency\" value=\"" << id.getADCSamplingFrequency() << "\" unitAccession=\"UO:0000106\" unitName=\"hertz\" unitCvRef=\"UO\" />\n";
4793 
4794  if (id.getAcquisitionMode() == IonDetector::ADC)
4795  {
4796  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000117\" name=\"analog-digital converter\" />\n";
4797  }
4798  else if (id.getAcquisitionMode() == IonDetector::PULSECOUNTING)
4799  {
4800  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000118\" name=\"pulse counting\" />\n";
4801  }
4802  else if (id.getAcquisitionMode() == IonDetector::TDC)
4803  {
4804  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000119\" name=\"time-digital converter\" />\n";
4805  }
4806  else if (id.getAcquisitionMode() == IonDetector::TRANSIENTRECORDER)
4807  {
4808  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000120\" name=\"transient recorder\" />\n";
4809  }
4810 
4811  if (id.getType() == IonDetector::CHANNELTRON)
4812  {
4813  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000107\" name=\"channeltron\" />\n";
4814  }
4815  else if (id.getType() == IonDetector::DALYDETECTOR)
4816  {
4817  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000110\" name=\"daly detector\" />\n";
4818  }
4819  else if (id.getType() == IonDetector::FARADAYCUP)
4820  {
4821  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000112\" name=\"faraday cup\" />\n";
4822  }
4823  else if (id.getType() == IonDetector::MICROCHANNELPLATEDETECTOR)
4824  {
4825  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000114\" name=\"microchannel plate detector\" />\n";
4826  }
4827  else if (id.getType() == IonDetector::MULTICOLLECTOR)
4828  {
4829  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000115\" name=\"multi-collector\" />\n";
4830  }
4831  else if (id.getType() == IonDetector::PHOTOMULTIPLIER)
4832  {
4833  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000116\" name=\"photomultiplier\" />\n";
4834  }
4835  else if (id.getType() == IonDetector::ELECTRONMULTIPLIER)
4836  {
4837  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000253\" name=\"electron multiplier\" />\n";
4838  }
4839  else if (id.getType() == IonDetector::ARRAYDETECTOR)
4840  {
4841  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000345\" name=\"array detector\" />\n";
4842  }
4843  else if (id.getType() == IonDetector::CONVERSIONDYNODE)
4844  {
4845  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000346\" name=\"conversion dynode\" />\n";
4846  }
4847  else if (id.getType() == IonDetector::DYNODE)
4848  {
4849  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000347\" name=\"dynode\" />\n";
4850  }
4851  else if (id.getType() == IonDetector::FOCALPLANECOLLECTOR)
4852  {
4853  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000348\" name=\"focal plane collector\" />\n";
4854  }
4855  else if (id.getType() == IonDetector::IONTOPHOTONDETECTOR)
4856  {
4857  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000349\" name=\"ion-to-photon detector\" />\n";
4858  }
4859  else if (id.getType() == IonDetector::POINTCOLLECTOR)
4860  {
4861  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000350\" name=\"point collector\" />\n";
4862  }
4863  else if (id.getType() == IonDetector::POSTACCELERATIONDETECTOR)
4864  {
4865  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000351\" name=\"postacceleration detector\" />\n";
4866  }
4867  else if (id.getType() == IonDetector::PHOTODIODEARRAYDETECTOR)
4868  {
4869  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000621\" name=\"photodiode array detector\" />\n";
4870  }
4871  else if (id.getType() == IonDetector::INDUCTIVEDETECTOR)
4872  {
4873  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000624\" name=\"inductive detector\" />\n";
4874  }
4875  else if (id.getType() == IonDetector::CONVERSIONDYNODEELECTRONMULTIPLIER)
4876  {
4877  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000108\" name=\"conversion dynode electron multiplier\" />\n";
4878  }
4879  else if (id.getType() == IonDetector::CONVERSIONDYNODEPHOTOMULTIPLIER)
4880  {
4881  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000109\" name=\"conversion dynode photomultiplier\" />\n";
4882  }
4883  else if (id.getType() == IonDetector::ELECTRONMULTIPLIERTUBE)
4884  {
4885  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000111\" name=\"electron multiplier tube\" />\n";
4886  }
4887  else if (id.getType() == IonDetector::FOCALPLANEARRAY)
4888  {
4889  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000113\" name=\"focal plane array\" />\n";
4890  }
4891  else if (id.getType() == IonDetector::TYPENULL)
4892  {
4893  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000026\" name=\"detector type\" />\n";
4894  }
4895 
4896  writeUserParam_(os, id, 5, "/mzML/instrumentConfigurationList/instrumentConfiguration/componentList/detector/cvParam/@accession", validator);
4897  os << "\t\t\t\t</detector>\n";
4898  }
4899  //FORCED
4900  if (component_count < 3 && in.getIonDetectors().empty())
4901  {
4902  os << "\t\t\t\t<detector order=\"1234\">\n";
4903  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000107\" name=\"channeltron\" />\n";
4904  os << "\t\t\t\t\t<userParam name=\"warning\" type=\"xsd:string\" value=\"invented ion detector, to fulfill mzML schema\" />\n";
4905  os << "\t\t\t\t</detector>\n";
4906  }
4907  os << "\t\t\t</componentList>\n";
4908  }
4909  os << "\t\t\t<softwareRef ref=\"so_in_0\" />\n";
4910  os << "\t\t</instrumentConfiguration>\n";
4911  os << "\t</instrumentConfigurationList>\n";
4912 
4913  //--------------------------------------------------------------------------------------------
4914  // data processing
4915  //--------------------------------------------------------------------------------------------
4916 
4917  // count number of float data array dps
4918  Size num_bi_dps(0);
4919  for (Size s = 0; s < exp.size(); ++s)
4920  {
4921  for (Size m = 0; m < exp[s].getFloatDataArrays().size(); ++m)
4922  {
4923  ++num_bi_dps;
4924  }
4925  }
4926 
4927  os << "\t<dataProcessingList count=\"" << (std::max)((Size)1, dps.size() + num_bi_dps) << "\">\n";
4928  //default (first spectrum data or fictional data)
4929  if (exp.empty())
4930  {
4931  std::vector< ConstDataProcessingPtr > dummy;
4932  writeDataProcessing_(os, "dp_sp_0", dummy, validator);
4933  }
4934 
4935  for (Size s = 0; s < dps.size(); ++s)
4936  {
4937  writeDataProcessing_(os, String("dp_sp_") + s, dps[s], validator);
4938  }
4939 
4940  //for each binary data array
4941  for (Size s = 0; s < exp.size(); ++s)
4942  {
4943  for (Size m = 0; m < exp[s].getFloatDataArrays().size(); ++m)
4944  {
4945  writeDataProcessing_(os, String("dp_sp_") + s + "_bi_" + m,
4946  exp[s].getFloatDataArrays()[m].getDataProcessing(), validator);
4947  }
4948  }
4949 
4950  os << "\t</dataProcessingList>\n";
4951  //--------------------------------------------------------------------------------------------
4952  // acquisitionSettings
4953  //--------------------------------------------------------------------------------------------
4954 
4955  //--------------------------------------------------------------------------------------------
4956  // run
4957  //--------------------------------------------------------------------------------------------
4958  os << "\t<run id=\"ru_0\" defaultInstrumentConfigurationRef=\"ic_0\" sampleRef=\"sa_0\"";
4959  if (exp.getDateTime().isValid())
4960  {
4961  os << " startTimeStamp=\"" << exp.getDateTime().get().substitute(' ', 'T') << "\"";
4962  }
4963  if (exp.getSourceFiles().size() > 0)
4964  {
4965  os << " defaultSourceFileRef=\"sf_ru_0\"";
4966  }
4967  os << ">\n";
4968 
4969  //run attributes
4970  if (exp.getFractionIdentifier() != "")
4971  {
4972  os << "\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000858\" name=\"fraction identifier\" value=\"" << exp.getFractionIdentifier() << "\" />\n";
4973  }
4974 
4975  writeUserParam_(os, exp, 2, "/mzML/run/cvParam/@accession", validator);
4976 
4977  }
4978 
4979  template <typename MapType>
4981  const SpectrumType& spec, Size s,
4982  Internal::MzMLValidator& validator, bool renew_native_ids,
4983  std::vector<std::vector< ConstDataProcessingPtr > >& dps)
4984  {
4985  //native id
4986  String native_id = spec.getNativeID();
4987  if (renew_native_ids)
4988  {
4989  native_id = String("spectrum=") + s;
4990  }
4991 
4992  long offset = os.tellp();
4993  spectra_offsets.push_back(make_pair(native_id, offset + 3));
4994 
4995  // IMPORTANT make sure the offset (above) corresponds to the start of the <spectrum tag
4996  os << "\t\t\t<spectrum id=\"" << writeXMLEscape(native_id) << "\" index=\"" << s << "\" defaultArrayLength=\"" << spec.size() << "\"";
4997  if (spec.getSourceFile() != SourceFile())
4998  {
4999  os << " sourceFileRef=\"sf_sp_" << s << "\"";
5000  }
5001  //the data processing info of the first spectrum is the default
5002  //if (s==0 || spec.getDataProcessing()!=exp[0].getDataProcessing())
5003  if (s == 0 || spec.getDataProcessing() != dps[0])
5004  {
5005  Size dp_ref_num = s;
5006  if (s != 0)
5007  {
5008  for (Size i = 0; i < dps.size(); ++i)
5009  {
5010  if (spec.getDataProcessing() == dps[i])
5011  {
5012  dp_ref_num = i;
5013  break;
5014  }
5015  }
5016  }
5017  os << " dataProcessingRef=\"dp_sp_" << dp_ref_num << "\"";
5018  }
5019  os << ">\n";
5020 
5021  //spectrum representation
5022  if (spec.getType() == SpectrumSettings::PEAKS)
5023  {
5024  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000127\" name=\"centroid spectrum\" />\n";
5025  }
5026  else if (spec.getType() == SpectrumSettings::RAWDATA)
5027  {
5028  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000128\" name=\"profile spectrum\" />\n";
5029  }
5030  else
5031  {
5032  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000525\" name=\"spectrum representation\" />\n";
5033  }
5034 
5035  //spectrum attributes
5036  if (spec.getMSLevel() != 0)
5037  {
5038  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000511\" name=\"ms level\" value=\"" << spec.getMSLevel() << "\" />\n";
5039  }
5040  if (spec.getInstrumentSettings().getZoomScan())
5041  {
5042  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000497\" name=\"zoom scan\" />\n";
5043  }
5044 
5045  //spectrum type
5047  {
5048  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000294\" name=\"mass spectrum\" />\n";
5049  }
5051  {
5052  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000579\" name=\"MS1 spectrum\" />\n";
5053  }
5055  {
5056  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000580\" name=\"MSn spectrum\" />\n";
5057  }
5059  {
5060  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000582\" name=\"SIM spectrum\" />\n";
5061  }
5063  {
5064  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000583\" name=\"SRM spectrum\" />\n";
5065  }
5067  {
5068  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000581\" name=\"CRM spectrum\" />\n";
5069  }
5071  {
5072  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000341\" name=\"precursor ion spectrum\" />\n";
5073  }
5075  {
5076  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000325\" name=\"constant neutral gain spectrum\" />\n";
5077  }
5079  {
5080  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000326\" name=\"constant neutral loss spectrum\" />\n";
5081  }
5083  {
5084  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000804\" name=\"electromagnetic radiation spectrum\" />\n";
5085  }
5087  {
5088  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000805\" name=\"emission spectrum\" />\n";
5089  }
5091  {
5092  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000806\" name=\"absorption spectrum\" />\n";
5093  }
5095  {
5096  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000789\" name=\"enhanced multiply charged spectrum\" />\n";
5097  }
5099  {
5100  os << "\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000789\" name=\"time-delayed fragmentation spectrum\" />\n";
5101  }
5102  else //FORCED
5103  {
5104  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000294\" name=\"mass spectrum\" />\n";
5105  }
5106 
5107  //scan polarity
5109  {
5110  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000129\" name=\"negative scan\" />\n";
5111  }
5113  {
5114  os << "\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000130\" name=\"positive scan\" />\n";
5115  }
5116 
5117  writeUserParam_(os, spec, 4, "/mzML/run/spectrumList/spectrum/cvParam/@accession", validator);
5118  //--------------------------------------------------------------------------------------------
5119  //scan list
5120  //--------------------------------------------------------------------------------------------
5121  os << "\t\t\t\t<scanList count=\"" << (std::max)((Size)1, spec.getAcquisitionInfo().size()) << "\">\n";
5122  ControlledVocabulary::CVTerm ai_term = getChildWithName_("MS:1000570", spec.getAcquisitionInfo().getMethodOfCombination());
5123  if (ai_term.id != "")
5124  {
5125  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"" << ai_term.id << "\" name=\"" << ai_term.name << "\" />\n";
5126  }
5127  else
5128  {
5129  os << "\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000795\" name=\"no combination\" />\n";
5130  }
5131  writeUserParam_(os, spec.getAcquisitionInfo(), 5, "/mzML/run/spectrumList/spectrum/scanList/cvParam/@accession", validator);
5132 
5133  //--------------------------------------------------------------------------------------------
5134  //scan
5135  //--------------------------------------------------------------------------------------------
5136  for (Size j = 0; j < spec.getAcquisitionInfo().size(); ++j)
5137  {
5138  const Acquisition& ac = spec.getAcquisitionInfo()[j];
5139  os << "\t\t\t\t\t<scan ";
5140  if (ac.getIdentifier() != "")
5141  os << "externalSpectrumID=\"" << ac.getIdentifier() << "\"";
5142  os << ">\n";
5143  if (j == 0)
5144  {
5145  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000016\" name=\"scan start time\" value=\"" << spec.getRT() << "\" unitAccession=\"UO:0000010\" unitName=\"second\" unitCvRef=\"UO\" />\n";
5146  }
5147  writeUserParam_(os, ac, 6, "/mzML/run/spectrumList/spectrum/scanList/scan/cvParam/@accession", validator);
5148  //scan windows
5149  if (j == 0 && spec.getInstrumentSettings().getScanWindows().size() != 0)
5150  {
5151  os << "\t\t\t\t\t\t<scanWindowList count=\"" << spec.getInstrumentSettings().getScanWindows().size() << "\">\n";
5152  for (Size k = 0; k < spec.getInstrumentSettings().getScanWindows().size(); ++k)
5153  {
5154  os << "\t\t\t\t\t\t\t<scanWindow>\n";
5155  os << "\t\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000501\" name=\"scan window lower limit\" value=\"" << spec.getInstrumentSettings().getScanWindows()[k].begin << "\" unitAccession=\"MS:1000040\" unitName=\"m/z\" unitCvRef=\"MS\" />\n";
5156  os << "\t\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000500\" name=\"scan window upper limit\" value=\"" << spec.getInstrumentSettings().getScanWindows()[k].end << "\" unitAccession=\"MS:1000040\" unitName=\"m/z\" unitCvRef=\"MS\" />\n";
5157  writeUserParam_(os, spec.getInstrumentSettings().getScanWindows()[k], 8, "/mzML/run/spectrumList/spectrum/scanList/scan/scanWindowList/scanWindow/cvParam/@accession", validator);
5158  os << "\t\t\t\t\t\t\t</scanWindow>\n";
5159  }
5160  os << "\t\t\t\t\t\t</scanWindowList>\n";
5161  }
5162  os << "\t\t\t\t\t</scan>\n";
5163  }
5164  //fallback if we have no acquisition information (a dummy scan is created for RT and so on)
5165  if (spec.getAcquisitionInfo().empty())
5166  {
5167  os << "\t\t\t\t\t<scan>\n";
5168  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000016\" name=\"scan start time\" value=\"" << spec.getRT() << "\" unitAccession=\"UO:0000010\" unitName=\"second\" unitCvRef=\"UO\" />\n";
5169  //scan windows
5170  if (spec.getInstrumentSettings().getScanWindows().size() != 0)
5171  {
5172  os << "\t\t\t\t\t\t<scanWindowList count=\"" << spec.getInstrumentSettings().getScanWindows().size() << "\">\n";
5173  for (Size j = 0; j < spec.getInstrumentSettings().getScanWindows().size(); ++j)
5174  {
5175  os << "\t\t\t\t\t\t\t<scanWindow>\n";
5176  os << "\t\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000501\" name=\"scan window lower limit\" value=\"" << spec.getInstrumentSettings().getScanWindows()[j].begin << "\" unitAccession=\"MS:1000040\" unitName=\"m/z\" unitCvRef=\"MS\" />\n";
5177  os << "\t\t\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000500\" name=\"scan window upper limit\" value=\"" << spec.getInstrumentSettings().getScanWindows()[j].end << "\" unitAccession=\"MS:1000040\" unitName=\"m/z\" unitCvRef=\"MS\" />\n";
5178  writeUserParam_(os, spec.getInstrumentSettings().getScanWindows()[j], 8, "/mzML/run/spectrumList/spectrum/scanList/scan/scanWindowList/scanWindow/cvParam/@accession", validator);
5179  os << "\t\t\t\t\t\t\t</scanWindow>\n";
5180  }
5181  os << "\t\t\t\t\t\t</scanWindowList>\n";
5182  }
5183  os << "\t\t\t\t\t</scan>\n";
5184  }
5185  os << "\t\t\t\t</scanList>\n";
5186 
5187  //--------------------------------------------------------------------------------------------
5188  //precursor list
5189  //--------------------------------------------------------------------------------------------
5190  if (!spec.getPrecursors().empty())
5191  {
5192  os << "\t\t\t<precursorList count=\"" << spec.getPrecursors().size() << "\">\n";
5193  for (Size p = 0; p != spec.getPrecursors().size(); ++p)
5194  {
5195  writePrecursor_(os, spec.getPrecursors()[p], validator);
5196  }
5197  os << "\t\t\t</precursorList>\n";
5198  }
5199 
5200  //--------------------------------------------------------------------------------------------
5201  //product list
5202  //--------------------------------------------------------------------------------------------
5203  if (spec.getProducts().size() != 0)
5204  {
5205  os << "\t\t\t\t<productList count=\"" << spec.getProducts().size() << "\">\n";
5206  for (Size p = 0; p < spec.getProducts().size(); ++p)
5207  {
5208  writeProduct_(os, spec.getProducts()[p], validator);
5209  }
5210  os << "\t\t\t\t</productList>\n";
5211  }
5212 
5213  //--------------------------------------------------------------------------------------------
5214  //binary data array list
5215  //--------------------------------------------------------------------------------------------
5216  if (spec.size() != 0)
5217  {
5218  String encoded_string;
5219  os << "\t\t\t\t<binaryDataArrayList count=\"" << (2 + spec.getFloatDataArrays().size() + spec.getStringDataArrays().size() + spec.getIntegerDataArrays().size()) << "\">\n";
5220 
5221  writeContainerData<SpectrumType>(os, options_, spec, "mz");
5222  writeContainerData<SpectrumType>(os, options_, spec, "intensity");
5223 
5224  String compression_term = MzMLHandlerHelper::getCompressionTerm_(options_, options_.getNumpressConfigurationIntensity(), false);
5225  //write float data array
5226  for (Size m = 0; m < spec.getFloatDataArrays().size(); ++m)
5227  {
5228  const typename SpectrumType::FloatDataArray& array = spec.getFloatDataArrays()[m];
5229  std::vector<double> data64_to_encode(array.size());
5230  for (Size p = 0; p < array.size(); ++p)
5231  data64_to_encode[p] = array[p];
5232  // TODO also encode float data arrays using numpress?
5233  decoder_.encode(data64_to_encode, Base64::BYTEORDER_LITTLEENDIAN, encoded_string, options_.getCompression());
5234  String data_processing_ref_string = "";
5235  if (array.getDataProcessing().size() != 0)
5236  {
5237  data_processing_ref_string = String("dataProcessingRef=\"dp_sp_") + s + "_bi_" + m + "\"";
5238  }
5239  os << "\t\t\t\t\t<binaryDataArray arrayLength=\"" << array.size() << "\" encodedLength=\"" << encoded_string.size() << "\" " << data_processing_ref_string << ">\n";
5240  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000523\" name=\"64-bit float\" />\n";
5241  os << "\t\t\t\t\t\t" << compression_term << "\n";
5242  ControlledVocabulary::CVTerm bi_term = getChildWithName_("MS:1000513", array.getName());
5243  if (bi_term.id != "")
5244  {
5245  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"" << bi_term.id << "\" name=\"" << bi_term.name << "\" />\n";
5246  }
5247  else
5248  {
5249  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000786\" name=\"non-standard data array\" value=\"" << array.getName() << "\" />\n";
5250  }
5251  writeUserParam_(os, array, 6, "/mzML/run/spectrumList/spectrum/binaryDataArrayList/binaryDataArray/cvParam/@accession", validator);
5252  os << "\t\t\t\t\t\t<binary>" << encoded_string << "</binary>\n";
5253  os << "\t\t\t\t\t</binaryDataArray>\n";
5254  }
5255  //write integer data array
5256  for (Size m = 0; m < spec.getIntegerDataArrays().size(); ++m)
5257  {
5258  const typename SpectrumType::IntegerDataArray& array = spec.getIntegerDataArrays()[m];
5259  std::vector<Int64> data64_to_encode(array.size());
5260  for (Size p = 0; p < array.size(); ++p)
5261  data64_to_encode[p] = array[p];
5262  decoder_.encodeIntegers(data64_to_encode, Base64::BYTEORDER_LITTLEENDIAN, encoded_string, options_.getCompression());
5263  String data_processing_ref_string = "";
5264  if (array.getDataProcessing().size() != 0)
5265  {
5266  data_processing_ref_string = String("dataProcessingRef=\"dp_sp_") + s + "_bi_" + m + "\"";
5267  }
5268  os << "\t\t\t\t\t<binaryDataArray arrayLength=\"" << array.size() << "\" encodedLength=\"" << encoded_string.size() << "\" " << data_processing_ref_string << ">\n";
5269  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000522\" name=\"64-bit integer\" />\n";
5270  os << "\t\t\t\t\t\t" << compression_term << "\n";
5271  ControlledVocabulary::CVTerm bi_term = getChildWithName_("MS:1000513", array.getName());
5272  if (bi_term.id != "")
5273  {
5274  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"" << bi_term.id << "\" name=\"" << bi_term.name << "\" />\n";
5275  }
5276  else
5277  {
5278  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000786\" name=\"non-standard data array\" value=\"" << array.getName() << "\" />\n";
5279  }
5280  writeUserParam_(os, array, 6, "/mzML/run/spectrumList/spectrum/binaryDataArrayList/binaryDataArray/cvParam/@accession", validator);
5281  os << "\t\t\t\t\t\t<binary>" << encoded_string << "</binary>\n";
5282  os << "\t\t\t\t\t</binaryDataArray>\n";
5283  }
5284  //write string data arrays
5285  for (Size m = 0; m < spec.getStringDataArrays().size(); ++m)
5286  {
5287  const typename SpectrumType::StringDataArray& array = spec.getStringDataArrays()[m];
5288  std::vector<String> data_to_encode;
5289  data_to_encode.resize(array.size());
5290  for (Size p = 0; p < array.size(); ++p)
5291  data_to_encode[p] = array[p];
5292  decoder_.encodeStrings(data_to_encode, encoded_string, options_.getCompression());
5293  String data_processing_ref_string = "";
5294  if (array.getDataProcessing().size() != 0)
5295  {
5296  data_processing_ref_string = String("dataProcessingRef=\"dp_sp_") + s + "_bi_" + m + "\"";
5297  }
5298  os << "\t\t\t\t\t<binaryDataArray arrayLength=\"" << array.size() << "\" encodedLength=\"" << encoded_string.size() << "\" " << data_processing_ref_string << ">\n";
5299  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1001479\" name=\"null-terminated ASCII string\" />\n";
5300  os << "\t\t\t\t\t\t" << compression_term << "\n";
5301  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000786\" name=\"non-standard data array\" value=\"" << array.getName() << "\" />\n";
5302  writeUserParam_(os, array, 6, "/mzML/run/spectrumList/spectrum/binaryDataArrayList/binaryDataArray/cvParam/@accession", validator);
5303  os << "\t\t\t\t\t\t<binary>" << encoded_string << "</binary>\n";
5304  os << "\t\t\t\t\t</binaryDataArray>\n";
5305  }
5306  os << "\t\t\t\t</binaryDataArrayList>\n";
5307  }
5308 
5309  os << "\t\t\t</spectrum>\n";
5310  }
5311 
5312  template <typename MapType>
5314  const ChromatogramType& chromatogram, Size c, Internal::MzMLValidator& validator)
5315  {
5316  long offset = os.tellp();
5317  chromatograms_offsets.push_back(make_pair(chromatogram.getNativeID(), offset + 6));
5318 
5319  // TODO native id with chromatogram=?? prefix?
5320  // IMPORTANT make sure the offset (above) corresponds to the start of the <chromatogram tag
5321  os << " <chromatogram id=\"" << writeXMLEscape(chromatogram.getNativeID()) << "\" index=\"" << c << "\" defaultArrayLength=\"" << chromatogram.size() << "\">" << "\n";
5322 
5323  // write cvParams (chromatogram type)
5325  {
5326  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000810\" name=\"mass chromatogram\" />\n";
5327  }
5329  {
5330  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000235\" name=\"total ion current chromatogram\" />\n";
5331  }
5333  {
5334  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000627\" name=\"selected ion current chromatogram\" />\n";
5335  }
5337  {
5338  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000628\" name=\"basepeak chromatogram\" />\n";
5339  }
5341  {
5342  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1001472\" name=\"selected ion monitoring chromatogram\" />\n";
5343  }
5345  {
5346  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1001473\" name=\"selected reaction monitoring chromatogram\" />\n";
5347  }
5349  {
5350  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000811\" name=\"electromagnetic radiation chromatogram\" />\n";
5351  }
5353  {
5354  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000812\" name=\"absorption chromatogram\" />\n";
5355  }
5357  {
5358  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000813\" name=\"emission chromatogram\" />\n";
5359  }
5360  else
5361  {
5362  // TODO
5363  }
5364  writePrecursor_(os, chromatogram.getPrecursor(), validator);
5365  writeProduct_(os, chromatogram.getProduct(), validator);
5366 
5367  //--------------------------------------------------------------------------------------------
5368  //binary data array list
5369  //--------------------------------------------------------------------------------------------
5370  String compression_term;
5371  String encoded_string;
5372  os << "\t\t\t\t<binaryDataArrayList count=\"" << (2 + chromatogram.getFloatDataArrays().size() + chromatogram.getStringDataArrays().size() + chromatogram.getIntegerDataArrays().size()) << "\">\n";
5373 
5374  writeContainerData<ChromatogramType>(os, options_, chromatogram, "time");
5375  writeContainerData<ChromatogramType>(os, options_, chromatogram, "intensity");
5376 
5377  compression_term = MzMLHandlerHelper::getCompressionTerm_(options_, options_.getNumpressConfigurationIntensity(), false);
5378  //write float data array
5379  for (Size m = 0; m < chromatogram.getFloatDataArrays().size(); ++m)
5380  {
5381  const typename ChromatogramType::FloatDataArray& array = chromatogram.getFloatDataArrays()[m];
5382  std::vector<double> data64_to_encode(array.size());
5383  for (Size p = 0; p < array.size(); ++p)
5384  data64_to_encode[p] = array[p];
5385  // TODO also encode float data arrays using numpress?
5386  decoder_.encode(data64_to_encode, Base64::BYTEORDER_LITTLEENDIAN, encoded_string, options_.getCompression());
5387  String data_processing_ref_string = "";
5388  if (array.getDataProcessing().size() != 0)
5389  {
5390  data_processing_ref_string = String("dataProcessingRef=\"dp_sp_") + c + "_bi_" + m + "\"";
5391  }
5392  os << "\t\t\t\t\t<binaryDataArray arrayLength=\"" << array.size() << "\" encodedLength=\"" << encoded_string.size() << "\" " << data_processing_ref_string << ">\n";
5393  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000523\" name=\"64-bit float\" />\n";
5394  os << "\t\t\t\t\t\t" << compression_term << "\n";
5395  ControlledVocabulary::CVTerm bi_term = getChildWithName_("MS:1000513", array.getName());
5396  if (bi_term.id != "")
5397  {
5398  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"" << bi_term.id << "\" name=\"" << bi_term.name << "\" />\n";
5399  }
5400  else
5401  {
5402  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000786\" name=\"non-standard data array\" value=\"" << array.getName() << "\" />\n";
5403  }
5404  writeUserParam_(os, array, 6, "/mzML/run/chromatogramList/chromatogram/binaryDataArrayList/binaryDataArray/cvParam/@accession", validator);
5405  os << "\t\t\t\t\t\t<binary>" << encoded_string << "</binary>\n";
5406  os << "\t\t\t\t\t</binaryDataArray>\n";
5407  }
5408  //write integer data array
5409  for (Size m = 0; m < chromatogram.getIntegerDataArrays().size(); ++m)
5410  {
5411  const typename ChromatogramType::IntegerDataArray& array = chromatogram.getIntegerDataArrays()[m];
5412  std::vector<Int64> data64_to_encode(array.size());
5413  for (Size p = 0; p < array.size(); ++p)
5414  data64_to_encode[p] = array[p];
5415  decoder_.encodeIntegers(data64_to_encode, Base64::BYTEORDER_LITTLEENDIAN, encoded_string, options_.getCompression());
5416  String data_processing_ref_string = "";
5417  if (array.getDataProcessing().size() != 0)
5418  {
5419  data_processing_ref_string = String("dataProcessingRef=\"dp_sp_") + c + "_bi_" + m + "\"";
5420  }
5421  os << "\t\t\t\t\t<binaryDataArray arrayLength=\"" << array.size() << "\" encodedLength=\"" << encoded_string.size() << "\" " << data_processing_ref_string << ">\n";
5422  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000522\" name=\"64-bit integer\" />\n";
5423  os << "\t\t\t\t\t\t" << compression_term << "\n";
5424  ControlledVocabulary::CVTerm bi_term = getChildWithName_("MS:1000513", array.getName());
5425  if (bi_term.id != "")
5426  {
5427  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"" << bi_term.id << "\" name=\"" << bi_term.name << "\" />\n";
5428  }
5429  else
5430  {
5431  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000786\" name=\"non-standard data array\" value=\"" << array.getName() << "\" />\n";
5432  }
5433  writeUserParam_(os, array, 6, "/mzML/run/chromatogramList/chromatogram/binaryDataArrayList/binaryDataArray/cvParam/@accession", validator);
5434  os << "\t\t\t\t\t\t<binary>" << encoded_string << "</binary>\n";
5435  os << "\t\t\t\t\t</binaryDataArray>\n";
5436  }
5437  //write string data arrays
5438  for (Size m = 0; m < chromatogram.getStringDataArrays().size(); ++m)
5439  {
5440  const typename ChromatogramType::StringDataArray& array = chromatogram.getStringDataArrays()[m];
5441  std::vector<String> data_to_encode;
5442  data_to_encode.resize(array.size());
5443  for (Size p = 0; p < array.size(); ++p)
5444  data_to_encode[p] = array[p];
5445  decoder_.encodeStrings(data_to_encode, encoded_string, options_.getCompression());
5446  String data_processing_ref_string = "";
5447  if (array.getDataProcessing().size() != 0)
5448  {
5449  data_processing_ref_string = String("dataProcessingRef=\"dp_sp_") + c + "_bi_" + m + "\"";
5450  }
5451  os << "\t\t\t\t\t<binaryDataArray arrayLength=\"" << array.size() << "\" encodedLength=\"" << encoded_string.size() << "\" " << data_processing_ref_string << ">\n";
5452  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1001479\" name=\"null-terminated ASCII string\" />\n";
5453  os << "\t\t\t\t\t\t" << compression_term << "\n";
5454  os << "\t\t\t\t\t\t<cvParam cvRef=\"MS\" accession=\"MS:1000786\" name=\"non-standard data array\" value=\"" << array.getName() << "\" />\n";
5455  writeUserParam_(os, array, 6, "/mzML/run/chromatogramList/chromatogram/binaryDataArrayList/binaryDataArray/cvParam/@accession", validator);
5456  os << "\t\t\t\t\t\t<binary>" << encoded_string << "</binary>\n";
5457  os << "\t\t\t\t\t</binaryDataArray>\n";
5458  }
5459  os << "\t\t\t\t</binaryDataArrayList>\n";
5460  os << "\t\t\t</chromatogram>" << "\n";
5461  }
5462 
5463  } // namespace Internal
5464 } // namespace OpenMS
5465 
5466 #endif
const String & getPathToFile() const
returns the file path
const String & getAddress() const
returns the address
String chop(Size n) const
Returns a substring where n characters were removed from the end of the string.
Sustained off-resonance irradiation.
Definition: Precursor.h:73
Definition: ChromatogramSettings.h:72
const double k
const DataValue & getMetaValue(const String &name) const
Returns the value corresponding to a string (or DataValue::EMPTY if not found)
Pulse counting.
Definition: IonDetector.h:85
Cyclotron.
Definition: MassAnalyzer.h:67
general spectrum type
Definition: InstrumentSettings.h:56
const String & getNativeID() const
returns the native identifier for the spectrum, used by the acquisition software. ...
Description of the applied preprocessing steps.
Definition: DataProcessing.h:52
Conversion to mzXML format.
Definition: DataProcessing.h:79
const String & getCustomizations() const
returns a description of customizations
resonance enhanced multiphoton ionization
Definition: IonSource.h:117
ChecksumType getChecksumType() const
returns the checksum type
atmospheric pressure ionisation
Definition: IonSource.h:94
fast atom bombardment
Definition: IonSource.h:86
Class to encode and decode data encoded with MSNumpress.
Definition: MSNumpressCoder.h:55
Open split.
Definition: IonSource.h:60
NumpressCompression np_compression
check error tolerance after encoding, guarantee abs(1.0-(encoded/decoded)) <= this, 0=do not guarantee anything
Definition: MSNumpressCoder.h:73
neutralization reionization mass spectrometry
Definition: IonSource.h:114
void setMetaValue(const String &name, const DataValue &value)
Sets the DataValue corresponding to a name.
Definition: Sample.h:65
Conversion dynode electron multiplier.
Definition: IonDetector.h:59
postacceleration detector
Definition: IonDetector.h:72
static const VersionDetails EMPTY
Definition: VersionInfo.h:93
PeakFileOptions options_
Options that can be set for loading/storing.
Definition: MzMLHandler.h:904
Description of a MS instrument.
Definition: Instrument.h:64
bool getSkipXMLChecks() const
returns whether to skip some XML checks and be fast instead
bool hasUnit() const
Check if the value has a unit.
Definition: DataValue.h:370
bool hasMZRange() const
returns true if an MZ range has been set
Peak picking (conversion from raw to peak data)
Definition: DataProcessing.h:68
void populateSpectraWithData()
Populate all spectra on the stack with data from input.
Definition: MzMLHandler.h:324
integer value
Definition: DataValue.h:69
Infusion.
Definition: IonSource.h:69
double getIsolationWindowLowerOffset() const
Returns the lower offset from the target m/z.
const String & getNameOfFile() const
returns the file name
bool getSortChromatogramsByRT() const
gets whether or not peaks in chromatograms should be sorted
fringing field
Definition: Instrument.h:82
static String getXRefTypeName(XRefType type)
Baseline reduction.
Definition: DataProcessing.h:67
static String absolutePath(const String &file)
Replaces the relative path in the argument with the absolute path.
String accession
Definition: SemanticValidator.h:75
Representation of a CV term.
Definition: ControlledVocabulary.h:60
surface ionization
Definition: IonSource.h:129
std::vector< SpectrumData > spectrum_data_
Vector of spectrum data stored for later parallel processing.
Definition: MzMLHandler.h:951
atmospheric pressure chemical ionization
Definition: IonSource.h:99
String writeCV_(const ControlledVocabulary::CVTerm &c, const DataValue &metaValue) const
Helper method to write an CV based on a meta value.
Definition: MzMLHandler.h:3549
A more convenient string class.
Definition: String.h:57
Multiphoton ionization.
Definition: IonSource.h:108
kinetic energy analyzer
Definition: Instrument.h:83
Precursor meta information.
Definition: Precursor.h:56
Class to encode and decode Base64.
Definition: Base64.h:64
const String & getNumber() const
returns the sample number (default: "")
dynode
Definition: IonDetector.h:68
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:104
void warning(const xercesc::SAXParseException &exception)
const std::vector< IonSource > & getIonSources() const
returns a const reference to the ion source list
bool getAlwaysAppendData() const
returns whether or not to always append the data to the given map (even if a consumer is given) ...
dissociative ionization
Definition: IonSource.h:124
ControlledVocabulary cv_
Controlled vocabulary (psi-ms from OpenMS/share/OpenMS/CV/psi-ms.obo)
Definition: MzMLHandler.h:998
bool encloses(const PositionType &position) const
Checks whether this range contains a certain point.
Definition: DRange.h:172
UInt getMSLevel() const
Returns the MS level.
Definition: MSSpectrum.h:259
InletType getInletType() const
returns the inlet type
Plasma desorption.
Definition: Precursor.h:68
time lag focusing
Definition: Instrument.h:78
String version_
Schema version.
Definition: XMLHandler.h:190
Infrared multiphoton dissociation.
Definition: Precursor.h:72
bool hasIntensityRange() const
returns true if an intensity range has been set
IntensityType getIntensity() const
Definition: Peak1D.h:109
Product meta information.
Definition: Product.h:49
void set(UInt month, UInt day, UInt year, UInt hour, UInt minute, UInt second)
sets data from six integers
liquid secondary ionization
Definition: IonSource.h:125
Electrostatic energy analyzer.
Definition: MassAnalyzer.h:64
void writeSpectrum_(std::ostream &os, const SpectrumType &spec, Size s, Internal::MzMLValidator &validator, bool renew_native_ids, std::vector< std::vector< ConstDataProcessingPtr > > &dps)
Definition: MzMLHandler.h:4980
bool has(const Key &key) const
Test whether the map contains the given key.
Definition: Map.h:109
Message-Digest algorithm 5.
Definition: SourceFile.h:56
Conversion to mzML format.
Definition: DataProcessing.h:78
Faraday cup.
Definition: IonDetector.h:58
charge exchange ionization
Definition: IonSource.h:122
Surface enhanced neat desorption.
Definition: IonSource.h:105
double getMass() const
returns the mass (in gram) (default: 0.0)
Fast ion bombardment.
Definition: IonSource.h:106
String id
Identifier.
Definition: ControlledVocabulary.h:83
spark ionization
Definition: IonSource.h:128
bool rt_set_
Definition: MzMLHandler.h:995
Membrane separator.
Definition: IonSource.h:59
const DRange< 1 > & getIntensityRange() const
returns the intensity range
Contact person information.
Definition: ContactPerson.h:50
const String & getNativeIDType() const
Returns the native ID type of the spectra.
bool hasSuffix(const String &string) const
true if String ends with string, false otherwise
static const DataValue EMPTY
Empty data value for comparisons.
Definition: DataValue.h:63
Data necessary to generate a single spectrum.
Definition: MzMLHandler.h:942
Semantically validates MzXML files.
Definition: MzMLValidator.h:52
Fourier transform ion cyclotron resonance mass spectrometer.
Definition: MassAnalyzer.h:62
Data filtering or extraction.
Definition: DataProcessing.h:72
photoionization
Definition: IonSource.h:115
Pulsed q dissociation.
Definition: Precursor.h:78
virtual void startElement(const XMLCh *const , const XMLCh *const , const XMLCh *const qname, const xercesc::Attributes &attributes)
Parsing method for opening tags.
Definition: MzMLHandler.h:1081
static String path(const String &file)
Returns the path of the file (without the file name).
const std::vector< MassAnalyzer > & getMassAnalyzers() const
returns a const reference to the mass analyzer list
Thermo spray.
Definition: IonSource.h:68
String toString() const
Conversion to String.
Unknown scan method.
Definition: InstrumentSettings.h:55
Map< String, std::vector< DataProcessingPtr > > processing_
The data processing list: id => Instrument.
Definition: MzMLHandler.h:931
SpectrumType spec_
The current spectrum.
Definition: MzMLHandler.h:909
Enhanced multiply charged scan.
Definition: InstrumentSettings.h:65
Surface enhanced laser desorption ionization.
Definition: IonSource.h:104
ChromatogramPeakT ChromatogramPeakType
Chromatogram peak type.
Definition: MSExperiment.h:83
penning ionization
Definition: IonSource.h:126
const AcquisitionInfo & getAcquisitionInfo() const
returns a const reference to the acquisition info
CoordinateType getMZ() const
Non-mutable access to m/z.
Definition: Peak1D.h:114
Negative polarity.
Definition: IonSource.h:144
bool hasRTRange() const
returns true if an RT range has been set
IonizationMethod getIonizationMethod() const
returns the ionization method
std::vector< BinaryData > data
Definition: MzMLHandler.h:962
associative ionization
Definition: IonSource.h:119
AnalyzerType getType() const
returns the analyzer type
IonOpticsType getIonOptics() const
returns the ion optics type
const StringDataArrays & getStringDataArrays() const
Returns a const reference to the string meta data arrays.
Definition: MSChromatogram.h:262
array detector
Definition: IonDetector.h:66
Int getCharge() const
Non-mutable access to the charge.
Base class for XML handlers.
Definition: XMLHandler.h:99
Electron transfer dissociation.
Definition: Precursor.h:77
void populateSpectraWithData_(std::vector< MzMLHandlerHelper::BinaryData > &input_data, Size &default_arr_length, const PeakFileOptions &peak_file_options, SpectrumType &spectrum)
Fill a single spectrum with data from input.
Definition: MzMLHandler.h:497
Emission scan.
Definition: InstrumentSettings.h:68
bool getSortSpectraByMZ() const
gets whether or not peaks in spectra should be sorted
bool getIntensity32Bit() const
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:135
field ionization
Definition: IonSource.h:111
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
Constant neutral loss scan Synonyms: 'CNG scan'.
Definition: InstrumentSettings.h:63
double getAccuracy() const
returns the mass accuracy i.e. how much the theoretical mass may differ from the measured mass (in pp...
flowing afterglow
Definition: IonSource.h:110
MS2+ mass spectrum, is a "mass spectrum".
Definition: InstrumentSettings.h:58
Binary data representation.
Definition: MzMLHandlerHelper.h:58
Raw data (also called profile data)
Definition: SpectrumSettings.h:75
Little endian type.
Definition: Base64.h:79
Axial ejection linear ion trap.
Definition: MassAnalyzer.h:59
Time-delayed fragmentation scan.
Definition: InstrumentSettings.h:66
Micro electrospray ionization.
Definition: IonSource.h:103
void addSpectrumMetaData_(const std::vector< MzMLHandlerHelper::BinaryData > &input_data, const Size n, SpectrumType &spectrum) const
Definition: MzMLHandler.h:443
electron multiplier tube
Definition: IonDetector.h:75
Calibration of m/z positions.
Definition: DataProcessing.h:70
Description of the software used for processing.
Definition: Software.h:49
const double c
glow discharge ionization
Definition: IonSource.h:112
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Definition: Sample.h:65
Flow injection analysis.
Definition: IonSource.h:66
bool getCompression() const
const IntegerDataArrays & getIntegerDataArrays() const
Returns a const reference to the integer meta data arrays.
Definition: MSSpectrum.h:322
static String find(const String &filename, StringList directories=StringList())
Looks up the location of the file filename.
Time-of-flight.
Definition: MassAnalyzer.h:60
std::vector< std::pair< std::string, long > > spectra_offsets
Definition: MzMLHandler.h:973
const String & getUnit() const
Return the unit associated to this DataValue.
Quadrupole ion trap / Paul ion trap.
Definition: MassAnalyzer.h:57
MzMLHandler(const MapType &exp, const String &filename, const String &version, const ProgressLogger &logger)
Constructor for a write-only handler.
Definition: MzMLHandler.h:155
first stability region
Definition: Instrument.h:81
Recalculation of precursor m/z.
Definition: DataProcessing.h:66
channeltron
Definition: IonDetector.h:63
ChromatogramType chromatogram_
The current chromatogram.
Definition: MzMLHandler.h:911
Focal plane array.
Definition: IonDetector.h:57
Definition: ControlledVocabulary.h:66
void writeContainerData(std::ostream &os, const PeakFileOptions &pf_options_, const ContainerT &container, String array_type)
Definition: MzMLHandler.h:272
static bool isDirectory(const String &path)
Return true if the given path specifies a directory.
electron ionization
Definition: IonSource.h:84
void populateChromatogramsWithData()
Populate all chromatograms on the stack with data from input.
Definition: MzMLHandler.h:389
bool obsolete
Flag that indicates of the term is obsolete.
Definition: ControlledVocabulary.h:86
Configuration class for MSNumpress.
Definition: MSNumpressCoder.h:69
Int getOrder() const
returns the position of this part in the whole Instrument.
Map< String, SourceFile > source_files_
The source files: id => SourceFile.
Definition: MzMLHandler.h:923
const ProgressLogger & logger_
Progress logger.
Definition: MzMLHandler.h:981
Retention time alignment of different maps.
Definition: DataProcessing.h:69
ion-to-photon detector
Definition: IonDetector.h:70
Map< String, Software > software_
The software list: id => Software.
Definition: MzMLHandler.h:927
double getActivationEnergy() const
returns the activation energy (in electronvolt)
#define LOG_ERROR
Macro to be used if non-fatal error are reported (processing continues)
Definition: LogStream.h:447
SpectrumType getType() const
returns the spectrum type
const String & getIdentifier() const
return the identifier/index/number of the acquisition
double toDouble() const
Conversion to double.
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:57
double getIsolationWindowUpperOffset() const
Returns the upper offset from the target m/z.
bool getZoomScan() const
return if this scan is a zoom (enhanced resolution) scan
Conversion to DTA format.
Definition: DataProcessing.h:80
ScanMode getScanMode() const
returns the scan mode
double getTOFTotalPathLength() const
returns the path length for a TOF mass analyzer (in meter)
negative ion chemical ionization
Definition: IonSource.h:113
const std::set< ActivationMethod > & getActivationMethods() const
returns a const reference to the activation methods
double getMZ() const
returns the target m/z
virtual void endElement(const XMLCh *const , const XMLCh *const , const XMLCh *const qname)
Parsing method for closing tags.
Definition: MzMLHandler.h:1542
String unit_accession
Definition: SemanticValidator.h:79
MSExperiment< Peak1D > MapType
Definition: PeakPickerIterative.cpp:87
Selected reaction monitoring scan Synonyms: 'Multiple reaction monitoring scan', 'SRM scan', 'MRM scan'.
Definition: InstrumentSettings.h:60
Representation of a controlled vocabulary.
Definition: ControlledVocabulary.h:54
double getMagneticFieldStrength() const
returns the strength of the magnetic field (in T)
Size default_array_length
Definition: MzMLHandler.h:945
Definition: ChromatogramSettings.h:69
bool cmpPtrContainer(const ContainerType &a, const ContainerType &b)
Helper function to compare two pointer-containers for equality of all elements.
Definition: Helpers.h:84
Size default_array_length_
The default number of peaks in the current spectrum.
Definition: MzMLHandler.h:915
Data necessary to generate a single chromatogram.
Definition: MzMLHandler.h:960
collision quadrupole
Definition: Instrument.h:76
SpectrumType spectrum
Definition: MzMLHandler.h:946
void load(const String &filename, CVMappings &cv_mappings, bool strip_namespaces=false)
loads CvMappings from the given file
XML handler for MzMLFile.
Definition: MzMLHandler.h:110
Particle beam.
Definition: IonSource.h:58
Definition: ControlledVocabulary.h:67
reflectron
Definition: Instrument.h:79
desorption ionization
Definition: IonSource.h:109
void loadFromOBO(const String &name, const String &filename)
Loads the CV from an OBO file.
void writeSourceFile_(std::ostream &os, const String &id, const SourceFile &software, Internal::MzMLValidator &validator)
Helper method that writes a source file.
Definition: MzMLHandler.h:3690
Int toInt() const
Conversion to int.
Definition: ControlledVocabulary.h:75
bool has_unit_accession
Definition: SemanticValidator.h:80
General data processing (if no other term applies)
Definition: DataProcessing.h:61
plasma desorption
Definition: IonSource.h:91
const Precursor & getPrecursor() const
returns a const reference to the precursors
Direct.
Definition: IonSource.h:55
const std::vector< ScanWindow > & getScanWindows() const
returns a const reference to the m/z scan windows
const SourceFile & getSourceFile() const
returns a const reference to the source file
Representation of a parsed CV term.
Definition: SemanticValidator.h:73
MapType * exp_
map pointer for reading
Definition: MzMLHandler.h:899
bool skip_spectrum_
Definition: MzMLHandler.h:992
Definition: ChromatogramSettings.h:76
magnetic deflection
Definition: Instrument.h:74
Linear ion trap.
Definition: MassAnalyzer.h:69
flame ionization
Definition: IonSource.h:90
Electron capture dissociation.
Definition: Precursor.h:71
Smoothing of the signal to reduce noise.
Definition: DataProcessing.h:64
photodiode array detector
Definition: IonDetector.h:73
Transient recorder.
Definition: IonDetector.h:88
Septum.
Definition: IonSource.h:62
Base64 decoder_
Decoder/Encoder for Base64-data in MzML.
Definition: MzMLHandler.h:978
DataType valueType() const
returns the type of value stored
Definition: DataValue.h:351
const String & getContactInfo() const
returns miscellaneous info about the contact person
Nano electrospray ionization.
Definition: IonSource.h:102
const DRange< 1 > & getRTRange() const
returns the RT range
Map< String, Sample > samples_
The sample list: id => Sample.
Definition: MzMLHandler.h:925
Nanospray inlet.
Definition: IonSource.h:73
double getIsolationWindowLowerOffset() const
returns the lower offset from the target m/z
MapType::ChromatogramPeakType ChromatogramPeakType
Chromatogram peak type.
Definition: MzMLHandler.h:257
Unknown.
Definition: IonDetector.h:54
static field
Definition: Instrument.h:84
void writeBinaryDataArray(std::ostream &os, const PeakFileOptions &pf_options_, std::vector< DataType > data_to_encode, bool is32bit, String array_type)
Definition: MzMLHandler.h:823
Definition: ControlledVocabulary.h:65
atmospheric pressure photo ionization
Definition: IonSource.h:100
String default_processing_
id of the default data processing (used when no processing is defined)
Definition: MzMLHandler.h:933
Deisotoping.
Definition: DataProcessing.h:63
electrospray ionisation
Definition: IonSource.h:83
PeakFileOptions & getOptions()
Get the peak file options.
Definition: MzMLHandler.h:232
boost::shared_ptr< DataProcessing > DataProcessingPtr
Definition: DataProcessing.h:127
secondary ion MS
Definition: IonSource.h:92
Radial ejection linear ion trap.
Definition: MassAnalyzer.h:58
Normalization of intensity values.
Definition: DataProcessing.h:71
Selected ion monitoring scan Synonyms: 'Multiple ion monitoring scan', 'SIM scan', 'MIM scan'.
Definition: InstrumentSettings.h:59
String & trim()
removes whitespaces (space, tab, line feed, carriage return) at the beginning and the end of the stri...
Interfaces::IMSDataConsumer< MapType > * consumer_
Consumer class to work on spectra.
Definition: MzMLHandler.h:984
delayed extraction
Definition: Instrument.h:75
CVMappings mapping_
Definition: MzMLHandler.h:999
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:55
Surface-induced dissociation.
Definition: Precursor.h:69
Scan window description.
Definition: ScanWindow.h:47
inductive detector
Definition: IonDetector.h:74
double getRT() const
Definition: MSSpectrum.h:243
static void writeFooter_(std::ostream &os, const PeakFileOptions &options_, std::vector< std::pair< std::string, long > > &spectra_offsets, std::vector< std::pair< std::string, long > > &chromatograms_offsets)
Write the mzML footer the appropriate compression term given the PeakFileOptions and the NumpressConf...
autoionization
Definition: IonSource.h:121
ReflectronState getReflectronState() const
returns the reflectron state (for TOF)
full scan mass spectrum, is a "mass spectrum" Synonyms: 'full spectrum', 'Q1 spectrum', 'Q3 spectrum', 'Single-Stage Mass Spectrometry'
Definition: InstrumentSettings.h:57
static void computeDataProperties_(std::vector< BinaryData > &data_, bool &precision_64, SignedSize &index, String index_name)
Peak data (also called centroided data or stick data)
Definition: SpectrumSettings.h:74
Post-source decay.
Definition: Precursor.h:67
chemi-ionization
Definition: IonSource.h:123
XRefType xref_type
xref value-type for the CV-term
Definition: ControlledVocabulary.h:90
Reservoir.
Definition: IonSource.h:63
Meta information about the sample.
Definition: Sample.h:60
Off.
Definition: MassAnalyzer.h:130
einzel lens
Definition: Instrument.h:80
Time-digital converter.
Definition: IonDetector.h:87
MSChromatogram< ChromatogramPeakType > ChromatogramType
Spectrum type.
Definition: MzMLHandler.h:261
Electro spray.
Definition: IonSource.h:67
daly detector
Definition: IonDetector.h:64
Photo multiplier.
Definition: IonDetector.h:56
MSSpectrum< PeakType > SpectrumType
Spectrum type.
Definition: MzMLHandler.h:259
String file_
File name.
Definition: XMLHandler.h:187
std::vector< BinaryData > data_
The spectrum data (or chromatogram data)
Definition: MzMLHandler.h:913
Description of a ion detector (part of a MS Instrument)
Definition: IonDetector.h:47
String name
Definition: SemanticValidator.h:76
double getIsolationWindowUpperOffset() const
returns the upper offset from the target m/z
Information about one raw data spectrum that was combined with several other raw data spectra...
Definition: Acquisition.h:50
String name
if it is a score type, lookup has_order
Definition: ControlledVocabulary.h:82
virtual void writeTo(std::ostream &os)
Writes the contents to a stream.
Definition: MzMLHandler.h:3975
void getKeys(std::vector< String > &keys) const
Fills the given vector with a list of all keys for which a value is set.
Stored waveform inverse fourier transform.
Definition: MassAnalyzer.h:66
Definition: VersionInfo.h:63
void populateChromatogramsWithData_(std::vector< MzMLHandlerHelper::BinaryData > &input_data, Size &default_arr_length, const PeakFileOptions &peak_file_options, ChromatogramType &inp_chromatogram)
Fill a single chromatogram with data from input.
Definition: MzMLHandler.h:673
Batch (e.g. in MALDI)
Definition: IonSource.h:56
Conversion dynode photo multiplier.
Definition: IonDetector.h:60
static String getCompressionTerm_(const PeakFileOptions &opt, MSNumpressCoder::NumpressConfig np_compression, bool use_numpress=false)
Returns the appropriate compression term given the PeakFileOptions and the NumpressConfig.
const String & getName() const
returns the name of the software
vertical ionization
Definition: IonSource.h:130
void setUnit(const String &unit)
Sets the unit to the given String.
ChromatogramType getChromatogramType() const
returns the chromatogram type, e.g. a SRM chromatogram
MSNumpressCoder::NumpressConfig getNumpressConfigurationMassTime() const
Set numpress configuration options for m/z or rt dimension.
void writePrecursor_(std::ostream &os, const Precursor &precursor, Internal::MzMLValidator &validator)
Helper method that write precursor information from spectra and chromatograms.
Definition: MzMLHandler.h:3858
Unknown.
Definition: MassAnalyzer.h:55
const Product & getProduct() const
returns a const reference to the products
Absorbtion scan.
Definition: InstrumentSettings.h:69
Ion trap.
Definition: MassAnalyzer.h:65
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition: MetaInfoInterface.h:56
Invalid conversion exception.
Definition: Exception.h:363
void fatalError(const xercesc::SAXParseException &exception)
Multi-collector.
Definition: IonDetector.h:61
bool isEmpty() const
test if the value is empty
Definition: DataValue.h:360
Consecutive reaction monitoring scan Synonyms: 'CRM scan'.
Definition: InstrumentSettings.h:61
Loading a file.
Definition: XMLHandler.h:118
Analog-digital converter.
Definition: IonDetector.h:86
Determination of the peak charge.
Definition: DataProcessing.h:65
const String & getComment() const
returns the comment (default: "")
Electromagnetic radiation scan Synonyms: 'EMR spectrum'.
Definition: InstrumentSettings.h:67
static String basename(const String &file)
Returns the basename of the file (without the path).
MSNumpressCoder::NumpressConfig getNumpressConfigurationIntensity() const
Set numpress configuration options for intensity dimension.
bool in_spectrum_list_
Flag that indicates that we're inside a spectrum (in contrast to a chromatogram)
Definition: MzMLHandler.h:917
PeakType PeakType
Peak type.
Definition: MSSpectrum.h:105
Secure Hash Algorithm-1.
Definition: SourceFile.h:55
const String & getFileType() const
returns the file type
std::vector< DataProcessingPtr > & getDataProcessing()
returns a mutable reference to the description of the applied processing
Invalid value exception.
Definition: Exception.h:336
laser desorption
Definition: IonSource.h:88
bool getFillData() const
returns whether to fill the actual data into the container (spectrum/chromatogram) ...
void getCounts(Size &spectra_counts, Size &chromatogram_counts)
Get the spectra and chromatogram counts of a file.
Definition: MzMLHandler.h:240
soft ionization
Definition: IonSource.h:127
std::vector< ChromatogramData > chromatogram_data_
Vector of chromatogram data stored for later parallel processing.
Definition: MzMLHandler.h:968
const String & getURL() const
returns the email address
Electron multiplier.
Definition: IonDetector.h:55
Blackbody infrared radiative dissociation.
Definition: Precursor.h:70
const IntegerDataArrays & getIntegerDataArrays() const
Returns a const reference to the integer meta data arrays.
Definition: MSChromatogram.h:274
const StringDataArrays & getStringDataArrays() const
Returns a const reference to the string meta data arrays.
Definition: MSSpectrum.h:310
point collector
Definition: IonDetector.h:71
UInt scan_count
Counting spectra and chromatograms.
Definition: MzMLHandler.h:987
Chromatography (liquid)
Definition: IonSource.h:57
String value
Definition: SemanticValidator.h:77
const String & getFirstName() const
returns the first name of the person
const String & getVersion() const
returns the software version
IonSource::Polarity getPolarity() const
returns the polarity
bool skip_chromatogram_
Flag that indicates whether this spectrum should be skipped (due to options)
Definition: MzMLHandler.h:991
Matrix-assisted laser desorption ionization.
Definition: IonSource.h:107
static VersionDetails create(const String &version)
parse String and return as proper struct
adiabatic ionization
Definition: IonSource.h:118
const String & getMethodOfCombination() const
returns the method of combination
pyrolysis mass spectrometry
Definition: IonSource.h:116
Low-energy collision-induced dissociation.
Definition: Precursor.h:75
The interface of a consumer of spectra and chromatograms.
Definition: IMSDataConsumer.h:68
Precursor ion scan.
Definition: InstrumentSettings.h:64
String prefix(SizeType length) const
returns the prefix of length length
Positive polarity.
Definition: IonSource.h:143
static void decodeBase64Arrays(std::vector< BinaryData > &data_, bool skipXMLCheck=false)
const String & getChecksum() const
returns the file's checksum
Definition: ChromatogramSettings.h:77
void writeSoftware_(std::ostream &os, const String &id, const Software &software, Internal::MzMLValidator &validator)
Helper method that writes a software.
Definition: MzMLHandler.h:3661
DateTime Class.
Definition: DateTime.h:55
Jet separator.
Definition: IonSource.h:61
String & substitute(char from, char to)
Replaces all occurrences of the character from by the character to.
OPENMS_INT64_TYPE Int64
Signed integer type (64bit)
Definition: Types.h:71
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:55
UInt selected_ion_count_
Count of selected ions.
Definition: MzMLHandler.h:1003
const std::vector< Product > & getProducts() const
returns a const reference to the products
const String & getName() const
returns the name of the instrument
Int getFinalMSExponent() const
returns the final MS exponent
ControlledVocabulary::CVTerm getChildWithName_(const String &parent_accession, const String &name) const
Looks up a child CV term of parent_accession with the name name. If no such term is found...
Definition: MzMLHandler.h:3646
void setIdentifier(const String &identifier)
sets the index/number of the scan
MapType::PeakType PeakType
Peak type.
Definition: MzMLHandler.h:255
void encode(std::vector< FromType > &in, ByteOrder to_byte_order, String &out, bool zlib_compression=false)
Encodes a vector of floating point numbers to a Base64 string.
Definition: Base64.h:210
void setOptions(const PeakFileOptions &opt)
Set the peak file options.
Definition: MzMLHandler.h:224
double value
Definition: DataValue.h:70
Constant neutral gain scan Synonyms: 'CNG scan'.
Definition: InstrumentSettings.h:62
Definition: MSNumpressCoder.h:60
Membrane inlet.
Definition: IonSource.h:72
microchannel plate detector
Definition: IonDetector.h:65
const InstrumentSettings & getInstrumentSettings() const
returns a const reference to the instrument settings of the current spectrum
void writeUserParam_(std::ostream &os, const MetaInfoInterface &meta, UInt indent, String path, Internal::MzMLValidator &validator) const
Writes user terms.
Definition: MzMLHandler.h:3567
void encodeNP(const std::vector< double > &in, String &result, bool zlib_compression, const NumpressConfig &config)
Encodes a vector of floating point numbers into a Base64 string using numpress.
Definition: MSNumpressCoder.h:129
thermal ionization
Definition: IonSource.h:93
Conversion to mzData format.
Definition: DataProcessing.h:77
std::vector< Int > & getPossibleChargeStates()
Mutable access to possible charge states.
static bool handleBinaryDataArrayCVParam(std::vector< BinaryData > &data_, const String &accession, const String &value, const String &name)
bool has_unit_name
Definition: SemanticValidator.h:82
conversion dynode
Definition: IonDetector.h:67
Quadrupole.
Definition: MassAnalyzer.h:56
void fillChromatogramData_()
Fills the current chromatogram with data points and meta data.
Photodissociation.
Definition: Precursor.h:76
Size getMaxDataPoolSize() const
Get maximal size of the data pool.
Collision-induced dissociation.
Definition: Precursor.h:66
MzMLHandler(MapType &exp, const String &filename, const String &version, ProgressLogger &logger)
Constructor for a read-only handler.
Definition: MzMLHandler.h:118
Moving wire.
Definition: IonSource.h:65
Definition: Sample.h:65
Inductively coupled plasma.
Definition: IonSource.h:71
const DRange< 1 > & getMZRange() const
returns the MZ range
std::vector< std::pair< std::string, long > > chromatograms_offsets
Definition: MzMLHandler.h:974
void handleUserParam_(const String &parent_parent_tag, const String &parent_tag, const String &name, const String &type, const String &value)
Handles user terms.
Definition: MzMLHandler.h:3388
MzMLHandlerHelper::BinaryData BinaryData
Definition: MzMLHandler.h:263
void writeProduct_(std::ostream &os, const Product &product, Internal::MzMLValidator &validator)
Helper method that write precursor information from spectra and chromatograms.
Definition: MzMLHandler.h:3962
Map< String, Instrument > instruments_
The data processing list: id => Instrument.
Definition: MzMLHandler.h:929
High-energy collision-induced dissociation.
Definition: Precursor.h:74
field desorption
Definition: IonSource.h:89
const FloatDataArrays & getFloatDataArrays() const
Definition: MSChromatogram.h:250
desorption/ionization on silicon
Definition: IonSource.h:132
String current_id_
Id of the current list. Used for referencing param group, source file, sample, software, ...
Definition: MzMLHandler.h:919
std::vector< BinaryData > data
Definition: MzMLHandler.h:944
const std::vector< Precursor > & getPrecursors() const
returns a const reference to the precursors
Representation of controlled vocabulary mapping rules (for PSI formats)
Definition: CVMappings.h:57
Definition: ControlledVocabulary.h:73
atmospheric pressure matrix-assisted laser desorption ionization
Definition: IonSource.h:131
Options for loading files containing peak data.
Definition: PeakFileOptions.h:48
Map< String, std::vector< SemanticValidator::CVTerm > > ref_param_
The referencing param groups: id => array (accession, value)
Definition: MzMLHandler.h:921
void writeDataProcessing_(std::ostream &os, const String &id, const std::vector< ConstDataProcessingPtr > &dps, Internal::MzMLValidator &validator)
Helper method that writes a data processing list.
Definition: MzMLHandler.h:3735
autodetachment
Definition: IonSource.h:120
const FloatDataArrays & getFloatDataArrays() const
Returns a const reference to the float meta data arrays.
Definition: MSSpectrum.h:298
On.
Definition: MassAnalyzer.h:129
const String & getInstitution() const
returns the affiliation
Definition: Sample.h:65
Int getOrder() const
returns the position of this part in the whole Instrument.
const String & getNativeID() const
returns the native identifier for the spectrum, used by the acquisition software. ...
Unknown spectrum type.
Definition: SpectrumSettings.h:73
void writeChromatogram_(std::ostream &os, const ChromatogramType &chromatogram, Size c, Internal::MzMLValidator &validator)
Definition: MzMLHandler.h:5313
bool skip_data
Definition: MzMLHandler.h:947
const String & getLastName() const
returns the last name of the person
void setMSDataConsumer(Interfaces::IMSDataConsumer< MapType > *consumer)
Set the IMSDataConsumer consumer which will consume the read data.
Definition: MzMLHandler.h:247
int Int
Signed integer type.
Definition: Types.h:103
focal plane collector
Definition: IonDetector.h:69
bool getMz32Bit() const
Map class based on the STL map (containing several convenience functions)
Definition: Map.h:51
Description of a mass analyzer (part of a MS Instrument)
Definition: MassAnalyzer.h:48
Description of an ion source (part of a MS Instrument)
Definition: IonSource.h:47
Charge deconvolution.
Definition: DataProcessing.h:62
selected ion flow tube
Definition: Instrument.h:77
const MapType * cexp_
map pointer for writing
Definition: MzMLHandler.h:901
const String & getName() const
returns the sample name (default: "")
const String & getEmail() const
returns the email address
void writeHeader_(std::ostream &os, const MapType &exp, std::vector< std::vector< ConstDataProcessingPtr > > &dps, Internal::MzMLValidator &validator)
Definition: MzMLHandler.h:4049
General file format conversion (if no other term applies)
Definition: DataProcessing.h:76
ChromatogramType chromatogram
Definition: MzMLHandler.h:964
void handleCVParam_(const String &parent_parent_tag, const String &parent_tag, const String &accession, const String &name, const String &value, const String &unit_accession="")
Handles CV terms.
Definition: MzMLHandler.h:1646
surface-assisted laser desorption ionization
Definition: IonSource.h:133
Definition: Sample.h:65
chemical ionisation
Definition: IonSource.h:85
virtual ~MzMLHandler()
Destructor.
Definition: MzMLHandler.h:192
double getConcentration() const
returns the concentration (in g/l) (default: 0.0)
SampleState getState() const
returns the state of aggregation (default: SAMPLENULL)
UInt chromatogram_count
Definition: MzMLHandler.h:988
bool validateCV_(const ControlledVocabulary::CVTerm &c, const String &path, const Internal::MzMLValidator &validator) const
Helper method to validate if the given CV is allowed in the current location (path) ...
Definition: MzMLHandler.h:3536
bool hasPrefix(const String &string) const
true if String begins with string, false otherwise
Parse Error exception.
Definition: Exception.h:608
virtual void characters(const XMLCh *const chars, const XMLSize_t length)
Parsing method for character data.
Definition: MzMLHandler.h:1050
Orbitrap.
Definition: MassAnalyzer.h:68
Size default_array_length
Definition: MzMLHandler.h:963
Moving belt.
Definition: IonSource.h:64
Magnetic sector.
Definition: MassAnalyzer.h:61
Continuous flow fast atom bombardment.
Definition: IonSource.h:70
double getVolume() const
returns the volume (in ml) (default: 0.0)
Unknown.
Definition: IonSource.h:82
Definition: Sample.h:65
Used to load CvMapping files.
Definition: CVMappingFile.h:57

OpenMS / TOPP release 2.0.0 Documentation generated on Tue Jan 31 2017 06:39:50 using doxygen 1.8.8