| OpenMS 2.5.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-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: Hannes Roest $
32 // $Authors: Hannes Roest $
33 // --------------------------------------------------------------------------
34
35 #pragma once
36
37 #include <OpenMS/FORMAT/MzMLFile.h>
38 #include <OpenMS/KERNEL/OnDiscMSExperiment.h>
39 #include <OpenMS/FORMAT/DATAACCESS/MSDataWritingConsumer.h>
40
41 namespace OpenMS
42 {
43
53 class OPENMS_DLLAPI IndexedMzMLFileLoader
54 {
55 public:
56
58 IndexedMzMLFileLoader();
59
61 ~IndexedMzMLFileLoader();
62
64 PeakFileOptions& getOptions();
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 {
108 MSChromatogram c = exp.getChromatogram(i);
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
130 PeakFileOptions options_;
131
132 };
133 }
134
135
OpenMS::OnDiscMSExperiment
Representation of a mass spectrometry experiment on disk.
Definition: OnDiscMSExperiment.h:68
OpenMS::String
A more convenient string class.
Definition: String.h:58
MSDataWritingConsumer.h
OpenMS::IndexedMzMLFileLoader::options_
PeakFileOptions options_
Options for storing.
Definition: IndexedMzMLFileLoader.h:130
OpenMS::OnDiscMSExperiment::getNrSpectra
Size getNrSpectra() const
get the total number of spectra available
Definition: OnDiscMSExperiment.h:156
OpenMS::OnDiscMSExperiment::openFile
bool openFile(const String &filename, bool skipMetaData=false)
Open a specific file on disk.
Definition: OnDiscMSExperiment.h:92
OpenMS::MSChromatogram
The representation of a chromatogram.
Definition: MSChromatogram.h:54
OpenMS::IndexedMzMLFileLoader::store
void store(const String &filename, PeakMap &exp)
Store a file from an in-memory data-structure.
Definition: IndexedMzMLFileLoader.h:119
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:77
OpenMS::Internal::MzMLHandler::setOptions
void setOptions(const PeakFileOptions &opt)
Set the peak file options.
OpenMS::MSDataWritingConsumer::consumeChromatogram
void consumeChromatogram(ChromatogramType &c) override
Consume a chromatogram.
OpenMS::OnDiscMSExperiment::getChromatogram
MSChromatogram getChromatogram(Size id)
returns a single chromatogram
Definition: OnDiscMSExperiment.h:209
OpenMS::MSDataWritingConsumer::setExpectedSize
void setExpectedSize(Size expectedSpectra, Size expectedChromatograms) override
Set expected size of spectra and chromatograms to be written.
OpenMS::MSDataWritingConsumer::setExperimentalSettings
void setExperimentalSettings(const ExperimentalSettings &exp) override
Set experimental settings for the whole file.
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
OpenMS::IndexedMzMLFileLoader::store
void store(const String &filename, OnDiscPeakMap &exp)
Store a file from an on-disc data-structure.
Definition: IndexedMzMLFileLoader.h:93
OpenMS::MzMLFile::store
void store(const String &filename, const PeakMap &map) const
Stores a map in an MzML file.
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::IndexedMzMLFileLoader::load
bool load(const String &filename, OnDiscPeakMap &exp)
Load a file.
Definition: IndexedMzMLFileLoader.h:82
OpenMS::OnDiscMSExperiment::getNrChromatograms
Size getNrChromatograms() const
get the total number of chromatograms available
Definition: OnDiscMSExperiment.h:162
OpenMS::PlainMSDataWritingConsumer
Consumer class that writes MS data to disk using the mzML format.
Definition: MSDataWritingConsumer.h:240
OnDiscMSExperiment.h
OpenMS::Constants::c
const double c
OpenMS::OnDiscMSExperiment::getSpectrum
MSSpectrum getSpectrum(Size id)
returns a single spectrum
Definition: OnDiscMSExperiment.h:189
OpenMS::MzMLFile::setOptions
void setOptions(const PeakFileOptions &)
set options for loading/storing
OpenMS::OnDiscMSExperiment::getExperimentalSettings
boost::shared_ptr< const ExperimentalSettings > getExperimentalSettings() const
returns the meta information of this experiment (const access)
Definition: OnDiscMSExperiment.h:168
OpenMS::MSDataWritingConsumer::consumeSpectrum
void consumeSpectrum(SpectrumType &s) override
Consume a spectrum.
OpenMS::IndexedMzMLFileLoader
A class to load an indexedmzML file.
Definition: IndexedMzMLFileLoader.h:53
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
MzMLFile.h
OpenMS::MzMLFile
File adapter for MzML files.
Definition: MzMLFile.h:55