OpenMS  2.6.0
MSDataWritingConsumer.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 
38 
39 #include <OpenMS/FORMAT/MzMLFile.h>
42 
43 #include <vector>
44 #include <string>
45 #include <fstream>
46 #include <boost/shared_ptr.hpp>
47 
48 namespace OpenMS
49 {
88  class OPENMS_DLLAPI MSDataWritingConsumer :
89  public Internal::MzMLHandler,
91  {
92 
93  public:
94  typedef PeakMap MapType;
97 
103  explicit MSDataWritingConsumer(String filename);
104 
106  ~MSDataWritingConsumer() override;
107 
109 
110 
117  void setExperimentalSettings(const ExperimentalSettings& exp) override;
118 
129  void setExpectedSize(Size expectedSpectra, Size expectedChromatograms) override;
130 
139  void consumeSpectrum(SpectrumType & s) override;
140 
149  void consumeChromatogram(ChromatogramType & c) override;
151 
160  virtual void addDataProcessing(DataProcessing d);
161 
165  virtual Size getNrSpectraWritten();
166 
170  virtual Size getNrChromatogramsWritten();
171 
172  private:
173 
175 
176 
181  virtual void processSpectrum_(SpectrumType & s) = 0;
182 
188  virtual void processChromatogram_(ChromatogramType & c) = 0;
190 
196  virtual void doCleanup_();
197 
198  protected:
199 
201  std::ofstream ofs_;
202 
219 
222 
226  std::vector<std::vector< ConstDataProcessingPtr > > dps_;
229  };
230 
240  class OPENMS_DLLAPI PlainMSDataWritingConsumer :
241  public MSDataWritingConsumer
242  {
243  void processSpectrum_(MapType::SpectrumType & /* s */) override {}
245 
246  public:
247 
248  explicit PlainMSDataWritingConsumer(String filename) : MSDataWritingConsumer(filename) {}
249  };
250 
258  class OPENMS_DLLAPI NoopMSDataWritingConsumer :
259  public MSDataWritingConsumer
260  {
261  public:
262 
263  explicit NoopMSDataWritingConsumer(String filename) : MSDataWritingConsumer(filename) {}
264  void setExperimentalSettings(const ExperimentalSettings& /* exp */) override {}
265  void consumeSpectrum(SpectrumType & /* s */) override {}
266  void consumeChromatogram(ChromatogramType & /* c */) override {}
267 
268  private:
269 
270  void doCleanup_() override {}
271  void processSpectrum_(MapType::SpectrumType & /* s */) override {}
273  };
274 
275 
276 } //end namespace OpenMS
277 
278 
OpenMS::MSDataWritingConsumer
Consumer class that writes MS data to disk using the mzML format.
Definition: MSDataWritingConsumer.h:88
OpenMS::NoopMSDataWritingConsumer::NoopMSDataWritingConsumer
NoopMSDataWritingConsumer(String filename)
Definition: MSDataWritingConsumer.h:263
OpenMS::MSDataWritingConsumer::additional_dataprocessing_
DataProcessingPtr additional_dataprocessing_
The dataprocessing to be added to each spectrum/chromatogram.
Definition: MSDataWritingConsumer.h:228
OpenMS::Interfaces::IMSDataConsumer
The interface of a consumer of spectra and chromatograms.
Definition: IMSDataConsumer.h:69
OpenMS::ExperimentalSettings
Description of the experimental settings.
Definition: ExperimentalSettings.h:59
OpenMS::String
A more convenient string class.
Definition: String.h:59
MzMLFile.h
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:77
OpenMS::MSDataWritingConsumer::SpectrumType
MapType::SpectrumType SpectrumType
Definition: MSDataWritingConsumer.h:95
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::Constants::c
const double c
IMSDataConsumer.h
OpenMS::MSDataWritingConsumer::dps_
std::vector< std::vector< ConstDataProcessingPtr > > dps_
Vector of data processing objects -> will be filled by writeHeader_.
Definition: MSDataWritingConsumer.h:226
OpenMS::NoopMSDataWritingConsumer
Consumer class that perform no operation.
Definition: MSDataWritingConsumer.h:258
OpenMS::MSDataWritingConsumer::ofs_
std::ofstream ofs_
File stream (to write mzML)
Definition: MSDataWritingConsumer.h:201
OpenMS::MSDataWritingConsumer::started_writing_
bool started_writing_
Stores whether we have already started writing any data.
Definition: MSDataWritingConsumer.h:204
OpenMS::MSDataWritingConsumer::add_dataprocessing_
bool add_dataprocessing_
Whether to add dataprocessing term to the data before writing.
Definition: MSDataWritingConsumer.h:218
OpenMS::DataProcessingPtr
boost::shared_ptr< DataProcessing > DataProcessingPtr
Definition: DataProcessing.h:135
OpenMS::MSDataWritingConsumer::spectra_expected_
Size spectra_expected_
Number of spectra expected.
Definition: MSDataWritingConsumer.h:214
OpenMS::PlainMSDataWritingConsumer::PlainMSDataWritingConsumer
PlainMSDataWritingConsumer(String filename)
Definition: MSDataWritingConsumer.h:248
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::NoopMSDataWritingConsumer::consumeSpectrum
void consumeSpectrum(SpectrumType &) override
Consume a spectrum.
Definition: MSDataWritingConsumer.h:265
OpenMS::MSDataWritingConsumer::writing_chromatograms_
bool writing_chromatograms_
Stores whether we are currently writing chromatograms.
Definition: MSDataWritingConsumer.h:208
ProgressLogger.h
OpenMS::NoopMSDataWritingConsumer::processSpectrum_
void processSpectrum_(MapType::SpectrumType &) override
Process a spectrum before storing to disk.
Definition: MSDataWritingConsumer.h:271
OpenMS::MSDataWritingConsumer::ChromatogramType
MapType::ChromatogramType ChromatogramType
Definition: MSDataWritingConsumer.h:96
OpenMS::MSDataWritingConsumer::validator_
Internal::MzMLValidator * validator_
Validator that knows about CV terms.
Definition: MSDataWritingConsumer.h:221
OpenMS::Internal::MzMLValidator
Semantically validates MzXML files.
Definition: MzMLValidator.h:48
OpenMS::MSDataWritingConsumer::settings_
ExperimentalSettings settings_
Experimental settings to use for the whole file.
Definition: MSDataWritingConsumer.h:224
OpenMS::NoopMSDataWritingConsumer::consumeChromatogram
void consumeChromatogram(ChromatogramType &) override
Consume a chromatogram.
Definition: MSDataWritingConsumer.h:266
OpenMS::PlainMSDataWritingConsumer::processChromatogram_
void processChromatogram_(MapType::ChromatogramType &) override
Process a chromatogram before storing to disk.
Definition: MSDataWritingConsumer.h:244
OpenMS::MSDataWritingConsumer::spectra_written_
Size spectra_written_
Number of spectra written.
Definition: MSDataWritingConsumer.h:210
OpenMS::PlainMSDataWritingConsumer
Consumer class that writes MS data to disk using the mzML format.
Definition: MSDataWritingConsumer.h:240
OpenMS::PlainMSDataWritingConsumer::processSpectrum_
void processSpectrum_(MapType::SpectrumType &) override
Process a spectrum before storing to disk.
Definition: MSDataWritingConsumer.h:243
OpenMS::DataProcessing
Description of the applied preprocessing steps.
Definition: DataProcessing.h:51
OpenMS::MSDataWritingConsumer::MapType
PeakMap MapType
Definition: MSDataWritingConsumer.h:94
OpenMS::MSDataWritingConsumer::chromatograms_written_
Size chromatograms_written_
Number of chromatograms written.
Definition: MSDataWritingConsumer.h:212
OpenMS::MSChromatogram
The representation of a chromatogram.
Definition: MSChromatogram.h:54
OpenMS::MSDataWritingConsumer::chromatograms_expected_
Size chromatograms_expected_
Number of chromatograms expected.
Definition: MSDataWritingConsumer.h:216
OpenMS::MSSpectrum
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
MzMLHandler.h
OpenMS::NoopMSDataWritingConsumer::doCleanup_
void doCleanup_() override
Cleanup function called by the destructor.
Definition: MSDataWritingConsumer.h:270
OpenMS::NoopMSDataWritingConsumer::setExperimentalSettings
void setExperimentalSettings(const ExperimentalSettings &) override
Set experimental settings for the whole file.
Definition: MSDataWritingConsumer.h:264
OpenMS::Internal::MzMLHandler
Handler for mzML file format.
Definition: MzMLHandler.h:116
OpenMS::MSDataWritingConsumer::writing_spectra_
bool writing_spectra_
Stores whether we are currently writing spectra.
Definition: MSDataWritingConsumer.h:206
OpenMS::NoopMSDataWritingConsumer::processChromatogram_
void processChromatogram_(MapType::ChromatogramType &) override
Process a chromatogram before storing to disk.
Definition: MSDataWritingConsumer.h:272