| OpenMS 2.5.0

MzDataHandler.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 $
33 // --------------------------------------------------------------------------
34
35 #pragma once
36
37 #include <OpenMS/KERNEL/StandardTypes.h>
38 #include <OpenMS/CONCEPT/Exception.h>
39 #include <OpenMS/CONCEPT/ProgressLogger.h>
40 #include <OpenMS/FORMAT/HANDLERS/XMLHandler.h>
41 #include <OpenMS/FORMAT/OPTIONS/PeakFileOptions.h>
42 #include <OpenMS/KERNEL/MSExperiment.h>
43
44 #include <sstream>
45
46 namespace OpenMS
47 {
48 namespace Internal
49 {
59 typedef PeakMap MapType;
60 typedef MSSpectrum SpectrumType;
61 typedef MSChromatogram ChromatogramType;
62
63 class OPENMS_DLLAPI MzDataHandler :
64 public XMLHandler
65 {
66 public:
69 MzDataHandler(MapType & exp, const String & filename, const String & version, ProgressLogger & logger);
71
73 MzDataHandler(const MapType & exp, const String & filename, const String & version, const ProgressLogger & logger);
74
76 ~MzDataHandler() override
77 {
78 }
79
81
82
83 // Docu in base class
84 void endElement(const XMLCh * const /*uri*/, const XMLCh * const /*local_name*/, const XMLCh * const qname) override;
85
86 // Docu in base class
87 void startElement(const XMLCh * const /*uri*/, const XMLCh * const /*local_name*/, const XMLCh * const qname, const xercesc::Attributes & attributes) override;
88
89 // Docu in base class
90 void characters(const XMLCh * const chars, const XMLSize_t length) override;
91
93 void writeTo(std::ostream & os) override;
94
96 void setOptions(const PeakFileOptions & options)
97 {
98 options_ = options;
99 }
100
101 private:
102 void init_();
103
104 protected:
105
107 typedef MapType::PeakType PeakType;
109 typedef MSSpectrum SpectrumType;
110
112 MapType * exp_;
114 const MapType * cexp_;
115
117 PeakFileOptions options_;
118
121 UInt peak_count_;
124 SpectrumType spec_;
126 std::vector<std::pair<String, MetaInfoDescription> > meta_id_descs_;
128 std::vector<String> data_to_decode_;
130 std::vector<float> data_to_encode_;
131 std::vector<std::vector<float> > decoded_list_;
132 std::vector<std::vector<double> > decoded_double_list_;
133 std::vector<String> precisions_;
134 std::vector<String> endians_;
136
138 bool skip_spectrum_;
139
141 const ProgressLogger & logger_;
142
144 void fillData_();
145
147
148
159 inline void writeCVS_(std::ostream & os, double value, const String & acc, const String & name, UInt indent = 4) const;
160
172 inline void writeCVS_(std::ostream & os, const String & value, const String & acc, const String & name, UInt indent = 4) const;
173
187 inline void writeCVS_(std::ostream & os, UInt value, UInt map, const String & acc, const String & name, UInt indent = 4);
188
190 inline void writeUserParam_(std::ostream & os, const MetaInfoInterface & meta, UInt indent = 4);
191
199 void cvParam_(const String & name, const String & value);
201
207 inline void writeBinary_(std::ostream & os, Size size, const String & tag, const String & name = "", SignedSize id = -1);
208
209 //Data processing auxiliary variable
210 boost::shared_ptr< DataProcessing > data_processing_;
211
212 };
213
214 //--------------------------------------------------------------------------------
215 } // namespace Internal
216
217 } // namespace OpenMS
218
OpenMS::SignedSize
ptrdiff_t SignedSize
Signed Size type e.g. used as pointer difference.
Definition: Types.h:134
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::MSChromatogram
The representation of a chromatogram.
Definition: MSChromatogram.h:54
OpenMS::Internal::MapType
PeakMap MapType
XML handler for MzDataFile.
Definition: MzDataHandler.h:59
OpenMS::Internal::MzDataHandler::PeakType
MapType::PeakType PeakType
Peak type.
Definition: MzDataHandler.h:107
OpenMS::Internal::MzDataHandler::data_to_encode_
std::vector< float > data_to_encode_
floating point numbers which have to be encoded and written
Definition: MzDataHandler.h:130
OpenMS::Internal::MzDataHandler::SpectrumType
MSSpectrum SpectrumType
Spectrum type.
Definition: MzDataHandler.h:109
XMLHandler.h
OpenMS::Internal::MzDataHandler::spec_
SpectrumType spec_
The current spectrum.
Definition: MzDataHandler.h:124
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::MzDataHandler::skip_spectrum_
bool skip_spectrum_
Flag that indicates whether this spectrum should be skipped (due to options)
Definition: MzDataHandler.h:138
OpenMS::Internal::ChromatogramType
MSChromatogram ChromatogramType
Definition: MzDataHandler.h:61
Exception.h
StandardTypes.h
OpenMS::Internal::MzDataHandler::options_
PeakFileOptions options_
Options that can be set for loading/storing.
Definition: MzDataHandler.h:117
OpenMS::Internal::MzDataHandler
Definition: MzDataHandler.h:63
OpenMS::Internal::MzDataHandler::cexp_
const MapType * cexp_
map pointer for writing
Definition: MzDataHandler.h:114
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::PeakFileOptions
Options for loading files containing peak data.
Definition: PeakFileOptions.h:47
ProgressLogger.h
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::Internal::MzDataHandler::decoded_list_
std::vector< std::vector< float > > decoded_list_
Definition: MzDataHandler.h:131
MSExperiment.h
OpenMS::ProgressLogger
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:54
OpenMS::UInt
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
OpenMS::Internal::MzDataHandler::decoded_double_list_
std::vector< std::vector< double > > decoded_double_list_
Definition: MzDataHandler.h:132
OpenMS::Internal::MzDataHandler::setOptions
void setOptions(const PeakFileOptions &options)
Sets the options.
Definition: MzDataHandler.h:96
OpenMS::Internal::MzDataHandler::~MzDataHandler
~MzDataHandler() override
Destructor.
Definition: MzDataHandler.h:76
PeakFileOptions.h
OpenMS::Internal::MzDataHandler::precisions_
std::vector< String > precisions_
Definition: MzDataHandler.h:133
OpenMS::Internal::MzDataHandler::data_processing_
boost::shared_ptr< DataProcessing > data_processing_
Definition: MzDataHandler.h:210
OpenMS::Internal::MzDataHandler::logger_
const ProgressLogger & logger_
Progress logger.
Definition: MzDataHandler.h:141
OpenMS::Internal::MzDataHandler::exp_
MapType * exp_
map pointer for reading
Definition: MzDataHandler.h:112
OpenMS::Internal::XMLHandler
Base class for XML handlers.
Definition: XMLHandler.h:151
OpenMS::Internal::MzDataHandler::endians_
std::vector< String > endians_
Definition: MzDataHandler.h:134
OpenMS::Internal::MzDataHandler::meta_id_descs_
std::vector< std::pair< String, MetaInfoDescription > > meta_id_descs_
An array of pairs MetaInfodescriptions and their ids.
Definition: MzDataHandler.h:126
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::MzDataHandler::data_to_decode_
std::vector< String > data_to_decode_
encoded data which is read and has to be decoded
Definition: MzDataHandler.h:128