Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
MzXMLFile.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-2015.
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_MZXMLFILE_H
36 #define OPENMS_FORMAT_MZXMLFILE_H
37 
38 #include <OpenMS/FORMAT/XMLFile.h>
43 
44 namespace OpenMS
45 {
46  class String;
47 
53  class OPENMS_DLLAPI MzXMLFile :
54  public Internal::XMLFile,
55  public ProgressLogger
56  {
57 public:
59  MzXMLFile();
61  ~MzXMLFile();
62 
64  PeakFileOptions & getOptions();
65 
67  const PeakFileOptions & getOptions() const;
68 
70  void setOptions(const PeakFileOptions &);
71 
80  template <typename MapType>
81  void load(const String & filename, MapType & map)
82  {
83  map.reset();
84 
85  //set DocumentIdentifier
86  map.setLoadedFileType(filename);
87  map.setLoadedFilePath(filename);
88 
89  Internal::MzXMLHandler<MapType> handler(map, filename, schema_version_, *this);
90  handler.setOptions(options_);
91  parse_(filename, &handler);
92  }
93 
101  template <typename MapType>
102  void store(const String & filename, const MapType & map) const
103  {
104  Internal::MzXMLHandler<MapType> handler(map, filename, schema_version_, *this);
105  save_(filename, &handler);
106  }
107 
126  template <typename MapType>
127  void transform(const String& filename_in, Interfaces::IMSDataConsumer<MapType> * consumer, bool skip_full_count = false)
128  {
129  // First pass through the file -> get the meta-data and hand it to the consumer
130  transformFirstPass_(filename_in, consumer, skip_full_count);
131 
132  // Second pass through the data, now read the spectra!
133  {
134  MapType dummy;
135  Internal::MzXMLHandler<MapType> handler(dummy, filename_in, getVersion(), *this);
136  handler.setOptions(options_);
137  handler.setMSDataConsumer(consumer);
138  parse_(filename_in, &handler);
139  }
140  }
141 
156  template <typename MapType>
157  void transform(const String& filename_in, Interfaces::IMSDataConsumer<MapType> * consumer, MapType& map, bool skip_full_count = false)
158  {
159  // First pass through the file -> get the meta-data and hand it to the consumer
160  transformFirstPass_(filename_in, consumer, skip_full_count);
161 
162  // Second pass through the data, now read the spectra!
163  {
164  PeakFileOptions tmp_options(options_);
165  Internal::MzXMLHandler<MapType> handler(map, filename_in, getVersion(), *this);
166  tmp_options.setAlwaysAppendData(true);
167  handler.setOptions(tmp_options);
168  handler.setMSDataConsumer(consumer);
169 
170  parse_(filename_in, &handler);
171  }
172  }
173 
174 protected:
175 
177  template <typename MapType>
178  void transformFirstPass_(const String& filename_in, Interfaces::IMSDataConsumer<MapType> * consumer, bool skip_full_count)
179  {
180  // Create temporary objects and counters
181  PeakFileOptions tmp_options(options_);
182  Size scount = 0, ccount = 0;
183  MapType experimental_settings;
184  Internal::MzXMLHandler<MapType> handler(experimental_settings, filename_in, getVersion(), *this);
185 
186  // set temporary options for handler
187  tmp_options.setSizeOnly(true);
188  tmp_options.setMetadataOnly( skip_full_count );
189  handler.setOptions(tmp_options);
190 
191  parse_(filename_in, &handler);
192 
193  // After parsing, collect information
194  scount = handler.getScanCount();
195  consumer->setExpectedSize(scount, ccount);
196  consumer->setExperimentalSettings(experimental_settings);
197  }
198 
199 private:
200 
202  };
203 } // namespace OpenMS
204 
205 #endif // OPENMS_FOMAT_MZXMLFILE_H
PeakFileOptions options_
Definition: MzXMLFile.h:201
void store(const String &filename, const MapType &map) const
Stores a map in a MzXML file.
Definition: MzXMLFile.h:102
A more convenient string class.
Definition: String.h:57
File adapter for MzXML 2.1 files.
Definition: MzXMLFile.h:53
void reset()
Resets all internal values.
Definition: MSExperiment.h:660
void setMSDataConsumer(Interfaces::IMSDataConsumer< MapType > *consumer)
Set the IMSDataConsumer consumer which will consume the read data.
Definition: MzXMLHandler.h:129
void load(const String &filename, MapType &map)
Loads a map from a MzXML file.
Definition: MzXMLFile.h:81
XML handlers for MzXMLFile.
Definition: MzXMLHandler.h:62
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
void setLoadedFileType(const String &file_name)
set the file_type according to the type of the file loaded from (see FileHandler::Type) preferably do...
void transform(const String &filename_in, Interfaces::IMSDataConsumer< MapType > *consumer, bool skip_full_count=false)
Transforms a map while loading using the supplied MSDataConsumer.
Definition: MzXMLFile.h:127
void setMetadataOnly(bool only)
sets whether or not to load only meta data
UInt getScanCount()
Gets the scan count.
Definition: MzXMLHandler.h:123
void setOptions(const PeakFileOptions &options)
Sets the options.
Definition: MzXMLHandler.h:117
void transform(const String &filename_in, Interfaces::IMSDataConsumer< MapType > *consumer, MapType &map, bool skip_full_count=false)
Transforms a map while loading using the supplied MSDataConsumer.
Definition: MzXMLFile.h:157
The interface of a consumer of spectra and chromatograms.
Definition: IMSDataConsumer.h:68
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:55
void setLoadedFilePath(const String &file_name)
set the file_name_ according to absolute path of the file loaded from preferably done whilst loading ...
virtual void setExpectedSize(Size expectedSpectra, Size expectedChromatograms)=0
Set expected size of spectra and chromatograms to be consumed.
Base class for loading/storing XML files that have a handler derived from XMLHandler.
Definition: XMLFile.h:53
Options for loading files containing peak data.
Definition: PeakFileOptions.h:48
virtual void setExperimentalSettings(const ExperimentalSettings &exp)=0
Set experimental settings (meta-data) of the data to be consumed.
void setAlwaysAppendData(bool only)
sets whether or not to always append the data to the given map (even if a consumer is given) ...
void transformFirstPass_(const String &filename_in, Interfaces::IMSDataConsumer< MapType > *consumer, bool skip_full_count)
Perform first pass through the file and retrieve the meta-data to initialize the consumer.
Definition: MzXMLFile.h:178
void setSizeOnly(bool only)

OpenMS / TOPP release 2.0.0 Documentation generated on Tue Nov 1 2016 16:34:46 using doxygen 1.8.11