Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
MzMLFile.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_MZMLFILE_H
36 #define OPENMS_FORMAT_MZMLFILE_H
37 
38 #include <OpenMS/FORMAT/XMLFile.h>
45 
46 namespace OpenMS
47 {
55  class OPENMS_DLLAPI MzMLFile :
56  public Internal::XMLFile,
57  public ProgressLogger
58  {
59 public:
61  MzMLFile();
63  ~MzMLFile();
64 
66  PeakFileOptions& getOptions();
67 
69  const PeakFileOptions& getOptions() const;
70 
72  void setOptions(const PeakFileOptions &);
73 
82  template <typename MapType>
83  void load(const String& filename, MapType& map)
84  {
85  map.reset();
86 
87  //set DocumentIdentifier
88  map.setLoadedFileType(filename);
89  map.setLoadedFilePath(filename);
90 
91  Internal::MzMLHandler<MapType> handler(map, filename, getVersion(), *this);
92  handler.setOptions(options_);
93  safeParse_(filename, &handler);
94  }
95 
99  void loadSize(const String & filename, Size& scount, Size& ccount);
100 
108  template <typename MapType>
109  void store(const String& filename, const MapType& map) const
110  {
111  Internal::MzMLHandler<MapType> handler(map, filename, getVersion(), *this);
112  handler.setOptions(options_);
113  save_(filename, &handler);
114  }
115 
134  template <typename MapType>
135  void transform(const String& filename_in, Interfaces::IMSDataConsumer<MapType> * consumer, bool skip_full_count = false)
136  {
137  // First pass through the file -> get the meta-data and hand it to the consumer
138  transformFirstPass_(filename_in, consumer, skip_full_count);
139 
140  // Second pass through the data, now read the spectra!
141  {
142  MapType dummy;
143  Internal::MzMLHandler<MapType> handler(dummy, filename_in, getVersion(), *this);
144  handler.setOptions(options_);
145  handler.setMSDataConsumer(consumer);
146  safeParse_(filename_in, &handler);
147  }
148  }
149 
164  template <typename MapType>
165  void transform(const String& filename_in, Interfaces::IMSDataConsumer<MapType> * consumer, MapType& map, bool skip_full_count = false)
166  {
167  // First pass through the file -> get the meta-data and hand it to the consumer
168  transformFirstPass_(filename_in, consumer, skip_full_count);
169 
170  // Second pass through the data, now read the spectra!
171  {
172  PeakFileOptions tmp_options(options_);
173  Internal::MzMLHandler<MapType> handler(map, filename_in, getVersion(), *this);
174  tmp_options.setAlwaysAppendData(true);
175  handler.setOptions(tmp_options);
176  handler.setMSDataConsumer(consumer);
177 
178  safeParse_(filename_in, &handler);
179  }
180  }
181 
187  bool isValid(const String& filename, std::ostream& os = std::cerr);
188 
198  bool isSemanticallyValid(const String& filename, StringList& errors, StringList& warnings);
199 
200 protected:
201 
202 
204  template <typename MapType>
205  void transformFirstPass_(const String& filename_in, Interfaces::IMSDataConsumer<MapType> * consumer, bool skip_full_count)
206  {
207  // Create temporary objects and counters
208  PeakFileOptions tmp_options(options_);
209  Size scount = 0, ccount = 0;
210  MapType experimental_settings;
211  Internal::MzMLHandler<MapType> handler(experimental_settings, filename_in, getVersion(), *this);
212 
213  // set temporary options for handler
214  tmp_options.setSizeOnly(true);
215  tmp_options.setMetadataOnly( skip_full_count );
216  handler.setOptions(tmp_options);
217 
218  safeParse_(filename_in, &handler);
219 
220  // After parsing, collect information
221  handler.getCounts(scount, ccount);
222  consumer->setExpectedSize(scount, ccount);
223  consumer->setExperimentalSettings(experimental_settings);
224  }
225 
227  void safeParse_(const String & filename, Internal::XMLHandler * handler);
228 
229 private:
230 
233 
236  };
237 
238 } // namespace OpenMS
239 
240 #endif // OPENMS_FOMAT_MZMLFILE_H
A more convenient string class.
Definition: String.h:57
void reset()
Resets all internal values.
Definition: MSExperiment.h:660
PeakFileOptions options_
Options for loading / storing.
Definition: MzMLFile.h:232
Base class for XML handlers.
Definition: XMLHandler.h:99
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 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: MzMLFile.h:205
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: MzMLFile.h:165
void setMetadataOnly(bool only)
sets whether or not to load only meta data
File adapter for MzML files.
Definition: MzMLFile.h:55
XML handler for MzMLFile.
Definition: MzMLHandler.h:108
void load(const String &filename, MapType &map)
Loads a map from a MzML file. Spectra and chromatograms are sorted by default (this can be disabled u...
Definition: MzMLFile.h:83
void store(const String &filename, const MapType &map) const
Stores a map in a MzML file.
Definition: MzMLFile.h:109
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:74
void getCounts(Size &spectra_counts, Size &chromatogram_counts)
Get the spectra and chromatogram counts of a file.
Definition: MzMLHandler.h:236
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.
void setOptions(const PeakFileOptions &opt)
Set the peak file options.
Definition: MzMLHandler.h:222
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
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: MzMLFile.h:135
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 setMSDataConsumer(Interfaces::IMSDataConsumer< MapType > *consumer)
Set the IMSDataConsumer consumer which will consume the read data.
Definition: MzMLHandler.h:243
String indexed_schema_location_
Location of indexed mzML schema.
Definition: MzMLFile.h:235
void setSizeOnly(bool only)

OpenMS / TOPP release 2.0.0 Documentation generated on Sat May 16 2015 16:13:27 using doxygen 1.8.9.1