| OpenMS 2.5.0

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-2020.
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: Timo Sachsenberg $
32 // $Authors: Marc Sturm, Chris Bielow, Hannes Roest $
33 // --------------------------------------------------------------------------
34
35 #pragma once
36
37 #include <OpenMS/CONCEPT/Helpers.h>
38 #include <OpenMS/CONCEPT/ProgressLogger.h>
39
40 #include <OpenMS/DATASTRUCTURES/CVMappings.h>
41
42 #include <OpenMS/KERNEL/StandardTypes.h>
43 #include <OpenMS/KERNEL/MSExperiment.h>
44
45 #include <OpenMS/FORMAT/HANDLERS/XMLHandler.h>
46 #include <OpenMS/FORMAT/HANDLERS/MzMLHandlerHelper.h>
47
48 #include <OpenMS/FORMAT/OPTIONS/PeakFileOptions.h>
49 #include <OpenMS/FORMAT/ControlledVocabulary.h>
50 #include <OpenMS/FORMAT/VALIDATORS/SemanticValidator.h>
51
52
53 //MISSING:
54 // - more than one selected ion per precursor (warning if more than one)
55 // - scanWindowList for each acquisition separately (currently for the whole spectrum only)
56 // - instrumentConfigurationRef attribute for scan (why should the instrument change between scans? - warning if used)
57 // - scanSettingsRef attribute for instrumentConfiguration tag (currently no information there because of missing mapping file entry - warning if used)
58
59 // xs:id/xs:idref prefix list
60 // - sf_ru : sourceFile (run)
61 // - sf_sp : sourceFile (spectrum)
62 // - sf_pr : sourceFile (precursor)
63 // - sf_ac : sourceFile (acquisition)
64 // - sa : sample
65 // - ic : instrumentConfiguration
66 // - so_dp : software (data processing)
67 // - so_in : software (instrument)
68 // - dp_sp : dataProcessing (spectrum)
69 // - dp_bi : dataProcessing (binary data array)
70 // - dp_ch : dataProcessing (chromatogram)
71
72 namespace OpenMS
73 {
74 namespace Interfaces
75 {
76 class IMSDataConsumer;
77 }
78
79 namespace Internal
80 {
81 class MzMLValidator;
82
83 typedef PeakMap MapType;
84 typedef MSSpectrum SpectrumType;
85 typedef MSChromatogram ChromatogramType;
86
116 class OPENMS_DLLAPI MzMLHandler :
117 public XMLHandler
118 {
119 public:
120
123
125 MzMLHandler(MapType& exp, const String& filename, const String& version, const ProgressLogger& logger);
126
128 MzMLHandler(const MapType& exp, const String& filename, const String& version, const ProgressLogger& logger);
129
131 ~MzMLHandler() override;
133
139
141 void endElement(const XMLCh* const /*uri*/, const XMLCh* const /*local_name*/, const XMLCh* const qname) override;
142
144 void startElement(const XMLCh* const /*uri*/, const XMLCh* const /*local_name*/, const XMLCh* const qname, const xercesc::Attributes& attributes) override;
145
147 void characters(const XMLCh* const chars, const XMLSize_t length) override;
148
150 void writeTo(std::ostream& os) override;
151
153
164
166 void setOptions(const PeakFileOptions& opt);
167
169 PeakFileOptions& getOptions();
170
172
174 void getCounts(Size& spectra_counts, Size& chromatogram_counts);
175
185
187 void setMSDataConsumer(Interfaces::IMSDataConsumer* consumer);
189
191 virtual LOADDETAIL getLoadDetail() const override;
192
194 virtual void setLoadDetail(const LOADDETAIL d) override;
195
196 protected:
197
199 MzMLHandler(const String& filename, const String& version, const ProgressLogger& logger);
200
202 typedef MapType::PeakType PeakType;
204 typedef MapType::ChromatogramPeakType ChromatogramPeakType;
206 typedef MSSpectrum SpectrumType;
208 typedef MSChromatogram ChromatogramType;
209
210 typedef MzMLHandlerHelper::BinaryData BinaryData;
211
216
223 void populateSpectraWithData_();
224
231 void populateChromatogramsWithData_();
232
238 void addSpectrumMetaData_(const std::vector<MzMLHandlerHelper::BinaryData>& input_data,
239 const Size n,
240 SpectrumType& spectrum) const;
241
257 void populateSpectraWithData_(std::vector<MzMLHandlerHelper::BinaryData>& input_data,
258 Size& length,
259 const PeakFileOptions& peak_file_options,
260 SpectrumType& spectrum);
261
274 void populateChromatogramsWithData_(std::vector<MzMLHandlerHelper::BinaryData>& input_data,
275 Size& length,
276 const PeakFileOptions& peak_file_options,
277 ChromatogramType& inp_chromatogram);
278
280 void fillChromatogramData_();
281
283 void handleCVParam_(const String& parent_parent_tag,
284 const String& parent_tag,
285 const String& accession,
286 const String& name,
287 const String& value,
288 const String& unit_accession = "");
289
291 void handleUserParam_(const String& parent_parent_tag,
292 const String& parent_tag,
293 const String& name,
294 const String& type,
295 const String& value,
296 const String& unit_accession = "");
298
304
306 void writeHeader_(std::ostream& os,
307 const MapType& exp,
308 std::vector<std::vector< ConstDataProcessingPtr > >& dps,
309 const Internal::MzMLValidator& validator);
310
311
313 void writeSpectrum_(std::ostream& os,
314 const SpectrumType& spec,
315 Size spec_idx,
316 const Internal::MzMLValidator& validator,
317 bool renew_native_ids,
318 std::vector<std::vector< ConstDataProcessingPtr > >& dps);
319
321 void writeChromatogram_(std::ostream& os,
322 const ChromatogramType& chromatogram,
323 Size chrom_idx,
324 const Internal::MzMLValidator& validator);
325
326 template <typename ContainerT>
327 void writeContainerData_(std::ostream& os, const PeakFileOptions& pf_options_, const ContainerT& container, String array_type);
328
342 template <typename DataType>
343 void writeBinaryDataArray_(std::ostream& os,
344 const PeakFileOptions& options,
345 std::vector<DataType>& data,
346 bool is32bit,
347 String array_type);
348
363 void writeBinaryFloatDataArray_(std::ostream& os,
364 const PeakFileOptions& pf_options_,
365 const OpenMS::DataArrays::FloatDataArray& array,
366 const Size spec_chrom_idx,
367 const Size array_idx,
368 bool isSpectrum,
369 const Internal::MzMLValidator& validator);
370
372 void writeUserParam_(std::ostream& os, const MetaInfoInterface& meta, UInt indent, const String& path, const Internal::MzMLValidator& validator, const std::set<String>& exclude = {}) const;
373
375 void writeSoftware_(std::ostream& os, const String& id, const Software& software, const Internal::MzMLValidator& validator);
376
378 void writeSourceFile_(std::ostream& os, const String& id, const SourceFile& software, const Internal::MzMLValidator& validator);
379
381 void writeDataProcessing_(std::ostream& os, const String& id, const std::vector< ConstDataProcessingPtr >& dps, const Internal::MzMLValidator& validator);
382
384 void writePrecursor_(std::ostream& os, const Precursor& precursor, const Internal::MzMLValidator& validator);
385
387 void writeProduct_(std::ostream& os, const Product& product, const Internal::MzMLValidator& validator);
388
390 String writeCV_(const ControlledVocabulary::CVTerm& c, const DataValue& metaValue) const;
391
393 bool validateCV_(const ControlledVocabulary::CVTerm& c, const String& path, const Internal::MzMLValidator& validator) const;
394
396 ControlledVocabulary::CVTerm getChildWithName_(const String& parent_accession, const String& name) const;
397
399
400 // MEMBERS
401
403 MapType* exp_{ nullptr };
404
406 const MapType* cexp_{ nullptr };
407
409 PeakFileOptions options_;
410
413 SpectrumType spec_;
416 ChromatogramType chromatogram_;
418 std::vector<BinaryData> bin_data_;
420 Size default_array_length_;
422 bool in_spectrum_list_{ false };
424 bool skip_spectrum_{ false };
426 bool skip_chromatogram_{ false };
428 bool rt_set_{ false };
430 String current_id_;
432 Map<String, std::vector<SemanticValidator::CVTerm> > ref_param_;
434 Map<String, SourceFile> source_files_;
436 Map<String, Sample> samples_;
438 Map<String, Software> software_;
440 Map<String, Instrument> instruments_;
442 Map<String, std::vector< DataProcessingPtr > > processing_;
444 String default_processing_;
446 UInt selected_ion_count_{ 0 };
447
455 struct SpectrumData
456 {
457 std::vector<BinaryData> data;
458 Size default_array_length;
459 SpectrumType spectrum;
460 };
461
463 std::vector<SpectrumData> spectrum_data_;
464
472 struct ChromatogramData
473 {
474 std::vector<BinaryData> data;
475 Size default_array_length;
476 ChromatogramType chromatogram;
477 };
478
480 std::vector<ChromatogramData> chromatogram_data_;
481
483
490 std::vector<std::pair<std::string, Int64> > spectra_offsets_;
491 std::vector<std::pair<std::string, Int64> > chromatograms_offsets_;
492
493
495 const ProgressLogger& logger_;
496
498 Interfaces::IMSDataConsumer* consumer_{ nullptr };
499
501 UInt scan_count_{ 0 };
502 UInt chromatogram_count_{ 0 };
503 Int scan_count_total_{ -1 };
504 Int chrom_count_total_{ -1 };
505
506
508 ControlledVocabulary cv_;
509 CVMappings mapping_;
510
511 };
512
513 //--------------------------------------------------------------------------------
514
515 } // namespace Internal
516 } // namespace OpenMS
517
OpenMS::Internal::MzMLHandler::default_processing_
String default_processing_
id of the default data processing (used when no processing is defined)
Definition: MzMLHandler.h:444
OpenMS::Product
Product meta information.
Definition: Product.h:48
OpenMS::SourceFile
Description of a file location, used to store the origin of (meta) data.
Definition: SourceFile.h:46
OpenMS::Internal::MzMLHandler::chromatograms_offsets_
std::vector< std::pair< std::string, Int64 > > chromatograms_offsets_
Stores binary offsets for each <chromatogram> tag.
Definition: MzMLHandler.h:491
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::DataValue
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:56
OpenMS::Internal::MzMLHandler
Handler for mzML file format.
Definition: MzMLHandler.h:116
OpenMS::Internal::MzMLValidator
Semantically validates MzXML files.
Definition: MzMLValidator.h:48
OpenMS::Internal::MzMLHandler::current_id_
String current_id_
Id of the current list. Used for referencing param group, source file, sample, software, ...
Definition: MzMLHandler.h:430
OpenMS::ChromatogramPeak
A 1-dimensional raw data point or peak for chromatograms.
Definition: ChromatogramPeak.h:54
SemanticValidator.h
OpenMS::MSChromatogram
The representation of a chromatogram.
Definition: MSChromatogram.h:54
OpenMS::Internal::MapType
PeakMap MapType
XML handler for MzDataFile.
Definition: MzDataHandler.h:59
Helpers.h
OpenMS::Precursor
Precursor meta information.
Definition: Precursor.h:57
OpenMS::Internal::MzMLHandler::chromatogram_
ChromatogramType chromatogram_
The current chromatogram.
Definition: MzMLHandler.h:416
OpenMS::Internal::MzMLHandler::ChromatogramType
MSChromatogram ChromatogramType
Spectrum type.
Definition: MzMLHandler.h:208
XMLHandler.h
OpenMS::Internal::MzMLHandler::processing_
Map< String, std::vector< DataProcessingPtr > > processing_
The data processing list: id => Instrument.
Definition: MzMLHandler.h:442
OpenMS::Internal::SpectrumType
MSSpectrum SpectrumType
Definition: MzDataHandler.h:60
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:77
OpenMS::Internal::MzMLHandler::samples_
Map< String, Sample > samples_
The sample list: id => Sample.
Definition: MzMLHandler.h:436
OpenMS::CVMappings
Representation of controlled vocabulary mapping rules (for PSI formats)
Definition: CVMappings.h:56
OpenMS::Internal::MzMLHandler::SpectrumData::spectrum
SpectrumType spectrum
Definition: MzMLHandler.h:459
OpenMS::Internal::ChromatogramType
MSChromatogram ChromatogramType
Definition: MzDataHandler.h:61
OpenMS::Internal::MzMLHandler::instruments_
Map< String, Instrument > instruments_
The data processing list: id => Instrument.
Definition: MzMLHandler.h:440
StandardTypes.h
OpenMS::DataArrays::FloatDataArray
Float data array class.
Definition: DataArrays.h:45
OpenMS::Internal::MzMLHandler::spectrum_data_
std::vector< SpectrumData > spectrum_data_
Vector of spectrum data stored for later parallel processing.
Definition: MzMLHandler.h:463
MzMLHandlerHelper.h
OpenMS::Internal::MzMLHandler::default_array_length_
Size default_array_length_
The default number of peaks in the current spectrum.
Definition: MzMLHandler.h:420
OpenMS::Software
Description of the software used for processing.
Definition: Software.h:48
OpenMS::Internal::MzMLHandler::spectra_offsets_
std::vector< std::pair< std::string, Int64 > > spectra_offsets_
Stores binary offsets for each <spectrum> tag.
Definition: MzMLHandler.h:490
ControlledVocabulary.h
OpenMS::Peak1D
A 1-dimensional raw data point or peak.
Definition: Peak1D.h:54
OpenMS::MSSpectrum
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
OpenMS::Internal::MzMLHandlerHelper::BinaryData
Representation for binary data in mzML.
Definition: MzMLHandlerHelper.h:69
OpenMS::PeakFileOptions
Options for loading files containing peak data.
Definition: PeakFileOptions.h:47
OpenMS::Internal::MzMLHandler::bin_data_
std::vector< BinaryData > bin_data_
The spectrum data (or chromatogram data)
Definition: MzMLHandler.h:418
ProgressLogger.h
OpenMS::Map
Map class based on the STL map (containing several convenience functions)
Definition: Map.h:50
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::Internal::MzMLHandler::software_
Map< String, Software > software_
The software list: id => Software.
Definition: MzMLHandler.h:438
OpenMS::Internal::MzMLHandler::mapping_
CVMappings mapping_
Definition: MzMLHandler.h:509
MSExperiment.h
OpenMS::ProgressLogger
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:54
OpenMS::Internal::MzMLHandler::logger_
const ProgressLogger & logger_
Progress logger.
Definition: MzMLHandler.h:495
OpenMS::Internal::MzMLHandler::BinaryData
MzMLHandlerHelper::BinaryData BinaryData
Definition: MzMLHandler.h:210
OpenMS::Internal::MzMLHandler::ref_param_
Map< String, std::vector< SemanticValidator::CVTerm > > ref_param_
The referencing param groups: id => array (accession, value)
Definition: MzMLHandler.h:432
OpenMS::Internal::XMLHandler::LOADDETAIL
LOADDETAIL
Definition: XMLHandler.h:175
OpenMS::Internal::MzMLHandler::cv_
ControlledVocabulary cv_
Controlled vocabulary (psi-ms from OpenMS/share/OpenMS/CV/psi-ms.obo)
Definition: MzMLHandler.h:508
OpenMS::Interfaces::IMSDataConsumer
The interface of a consumer of spectra and chromatograms.
Definition: IMSDataConsumer.h:69
OpenMS::UInt
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
OpenMS::Constants::c
const double c
OpenMS::ControlledVocabulary::CVTerm
Representation of a CV term.
Definition: ControlledVocabulary.h:60
int
PeakFileOptions.h
OpenMS::Internal::MzMLHandler::options_
PeakFileOptions options_
Options that can be set for loading/storing.
Definition: MzMLHandler.h:409
OpenMS::Internal::MzMLHandler::ChromatogramPeakType
MapType::ChromatogramPeakType ChromatogramPeakType
Chromatogram peak type.
Definition: MzMLHandler.h:204
OpenMS::Internal::MzMLHandler::chromatogram_data_
std::vector< ChromatogramData > chromatogram_data_
Vector of chromatogram data stored for later parallel processing.
Definition: MzMLHandler.h:480
OpenMS::Internal::MzMLHandler::PeakType
MapType::PeakType PeakType
Peak type.
Definition: MzMLHandler.h:202
OpenMS::Internal::MzMLHandler::SpectrumData
Data necessary to generate a single spectrum.
Definition: MzMLHandler.h:455
OpenMS::Internal::MzMLHandler::ChromatogramData
Data necessary to generate a single chromatogram.
Definition: MzMLHandler.h:472
OpenMS::ControlledVocabulary
Representation of a controlled vocabulary.
Definition: ControlledVocabulary.h:54
CVMappings.h
OpenMS::Internal::XMLHandler
Base class for XML handlers.
Definition: XMLHandler.h:151
OpenMS::Internal::MzMLHandler::SpectrumType
MSSpectrum SpectrumType
Spectrum type.
Definition: MzMLHandler.h:206
OpenMS::Internal::MzMLHandler::ChromatogramData::chromatogram
ChromatogramType chromatogram
Definition: MzMLHandler.h:476
OpenMS::MetaInfoInterface
Interface for classes that can store arbitrary meta information (Type-Name-Value tuples).
Definition: MetaInfoInterface.h:60
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::Internal::MzMLHandler::SpectrumData::data
std::vector< BinaryData > data
Definition: MzMLHandler.h:457
OpenMS::Internal::MzMLHandler::SpectrumData::default_array_length
Size default_array_length
Definition: MzMLHandler.h:458
OpenMS::Internal::MzMLHandler::source_files_
Map< String, SourceFile > source_files_
The source files: id => SourceFile.
Definition: MzMLHandler.h:434