OpenMS  2.7.0
IndexedMzMLFileLoader.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-2021.
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: Hannes Roest $
32 // $Authors: Hannes Roest $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 #include <OpenMS/FORMAT/MzMLFile.h>
40 
41 namespace OpenMS
42 {
43 
53  class OPENMS_DLLAPI IndexedMzMLFileLoader
54  {
55  public:
56 
59 
62 
65 
67  const PeakFileOptions& getOptions() const;
68 
70  void setOptions(const PeakFileOptions &);
71 
82  bool load(const String& filename, OnDiscPeakMap& exp)
83  {
84  return exp.openFile(filename);
85  }
86 
93  void store(const String& filename, OnDiscPeakMap& exp)
94  {
95  // Create a writing data consumer which consumes the experiment (writes it to disk)
96  PlainMSDataWritingConsumer consumer(filename);
97  consumer.setExpectedSize(exp.getNrSpectra(), exp.getNrChromatograms());
98  consumer.setExperimentalSettings(*exp.getExperimentalSettings().get());
99  options_.setWriteIndex(true); // ensure that we write the index
100  consumer.setOptions(options_);
101  for (Size i = 0; i < exp.getNrSpectra(); i++)
102  {
103  MSSpectrum s = exp.getSpectrum(i);
104  consumer.consumeSpectrum(s);
105  }
106  for (Size i = 0; i < exp.getNrChromatograms(); i++)
107  {
109  consumer.consumeChromatogram(c);
110  }
111  }
112 
119  void store(const String& filename, PeakMap& exp)
120  {
121  MzMLFile f;
122  options_.setWriteIndex(true); // ensure that we write the index
123  f.setOptions(options_);
124  f.store(filename, exp);
125  }
126 
127 private:
128 
131 
132  };
133 }
134 
135 
A class to load an indexedmzML file.
Definition: IndexedMzMLFileLoader.h:54
IndexedMzMLFileLoader()
Constructor.
void setOptions(const PeakFileOptions &)
set options for loading/storing
void store(const String &filename, OnDiscPeakMap &exp)
Store a file from an on-disc data-structure.
Definition: IndexedMzMLFileLoader.h:93
const PeakFileOptions & getOptions() const
Non-mutable access to the options for loading/storing.
PeakFileOptions options_
Options for storing.
Definition: IndexedMzMLFileLoader.h:130
PeakFileOptions & getOptions()
Mutable access to the options for loading/storing.
bool load(const String &filename, OnDiscPeakMap &exp)
Load a file.
Definition: IndexedMzMLFileLoader.h:82
void store(const String &filename, PeakMap &exp)
Store a file from an in-memory data-structure.
Definition: IndexedMzMLFileLoader.h:119
void setOptions(const PeakFileOptions &opt)
Set the peak file options.
The representation of a chromatogram.
Definition: MSChromatogram.h:58
void setExpectedSize(Size expectedSpectra, Size expectedChromatograms) override
Set expected size of spectra and chromatograms to be written.
void consumeChromatogram(ChromatogramType &c) override
Consume a chromatogram.
void setExperimentalSettings(const ExperimentalSettings &exp) override
Set experimental settings for the whole file.
void consumeSpectrum(SpectrumType &s) override
Consume a spectrum.
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:80
The representation of a 1D spectrum.
Definition: MSSpectrum.h:71
File adapter for MzML files.
Definition: MzMLFile.h:58
void setOptions(const PeakFileOptions &)
set options for loading/storing
void store(const String &filename, const PeakMap &map) const
Stores a map in an MzML file.
Representation of a mass spectrometry experiment on disk.
Definition: OnDiscMSExperiment.h:69
MSSpectrum getSpectrum(Size id)
returns a single spectrum
Definition: OnDiscMSExperiment.h:197
Size getNrSpectra() const
get the total number of spectra available
Definition: OnDiscMSExperiment.h:164
Size getNrChromatograms() const
get the total number of chromatograms available
Definition: OnDiscMSExperiment.h:170
MSChromatogram getChromatogram(Size id)
returns a single chromatogram
Definition: OnDiscMSExperiment.h:219
bool openFile(const String &filename, bool skipMetaData=false)
Open a specific file on disk.
Definition: OnDiscMSExperiment.h:92
boost::shared_ptr< const ExperimentalSettings > getExperimentalSettings() const
returns the meta information of this experiment (const access)
Definition: OnDiscMSExperiment.h:176
Options for loading files containing peak data.
Definition: PeakFileOptions.h:48
Consumer class that writes MS data to disk using the mzML format.
Definition: MSDataWritingConsumer.h:242
A more convenient string class.
Definition: String.h:61
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
const double c
Definition: Constants.h:209
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47