OpenMS
MSDataWritingConsumer.h
Go to the documentation of this file.
1 // Copyright (c) 2002-2023, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2 // SPDX-License-Identifier: BSD-3-Clause
3 //
4 // --------------------------------------------------------------------------
5 // $Maintainer: Hannes Roest $
6 // $Authors: Hannes Roest $
7 // --------------------------------------------------------------------------
8 
9 #pragma once
10 
12 
13 #include <OpenMS/FORMAT/MzMLFile.h>
16 
17 #include <vector>
18 #include <string>
19 #include <fstream>
20 #include <boost/shared_ptr.hpp>
21 
22 namespace OpenMS
23 {
62  class OPENMS_DLLAPI MSDataWritingConsumer :
63  public Internal::MzMLHandler,
65  {
66 
67  public:
68  typedef PeakMap MapType;
71 
77  explicit MSDataWritingConsumer(const String& filename);
78 
81 
83 
84 
91  void setExperimentalSettings(const ExperimentalSettings& exp) override;
92 
103  void setExpectedSize(Size expectedSpectra, Size expectedChromatograms) override;
104 
113  void consumeSpectrum(SpectrumType & s) override;
114 
125 
135 
140 
145 
146  private:
147 
149 
150 
155  virtual void processSpectrum_(SpectrumType & s) = 0;
156 
164 
170  virtual void doCleanup_();
171 
172  protected:
173 
175  std::ofstream ofs_;
176 
193 
196 
200  std::vector<std::vector< ConstDataProcessingPtr > > dps_;
203  };
204 
214  class OPENMS_DLLAPI PlainMSDataWritingConsumer :
215  public MSDataWritingConsumer
216  {
217  void processSpectrum_(MapType::SpectrumType & /* s */) override {}
219 
220  public:
221 
222  explicit PlainMSDataWritingConsumer(String filename) : MSDataWritingConsumer(filename) {}
223  };
224 
232  class OPENMS_DLLAPI NoopMSDataWritingConsumer :
233  public MSDataWritingConsumer
234  {
235  public:
236 
237  explicit NoopMSDataWritingConsumer(String filename) : MSDataWritingConsumer(filename) {}
238  void setExperimentalSettings(const ExperimentalSettings& /* exp */) override {}
239  void consumeSpectrum(SpectrumType & /* s */) override {}
240  void consumeChromatogram(ChromatogramType & /* c */) override {}
241 
242  private:
243 
244  void doCleanup_() override {}
245  void processSpectrum_(MapType::SpectrumType & /* s */) override {}
247  };
248 
249 
250 } //end namespace OpenMS
251 
252 
Description of the applied preprocessing steps.
Definition: DataProcessing.h:27
Description of the experimental settings.
Definition: ExperimentalSettings.h:36
The interface of a consumer of spectra and chromatograms.
Definition: IMSDataConsumer.h:44
Handler for mzML file format.
Definition: MzMLHandler.h:94
Semantically validates MzXML files.
Definition: MzMLValidator.h:25
The representation of a chromatogram.
Definition: MSChromatogram.h:31
Consumer class that writes MS data to disk using the mzML format.
Definition: MSDataWritingConsumer.h:65
virtual void processChromatogram_(ChromatogramType &c)=0
Process a chromatogram before storing to disk.
~MSDataWritingConsumer() override
Destructor.
std::ofstream ofs_
File stream (to write mzML)
Definition: MSDataWritingConsumer.h:175
virtual Size getNrChromatogramsWritten()
Return the number of chromatograms written.
Size spectra_expected_
Number of spectra expected.
Definition: MSDataWritingConsumer.h:188
void setExpectedSize(Size expectedSpectra, Size expectedChromatograms) override
Set expected size of spectra and chromatograms to be written.
bool writing_spectra_
Stores whether we are currently writing spectra.
Definition: MSDataWritingConsumer.h:180
Size spectra_written_
Number of spectra written.
Definition: MSDataWritingConsumer.h:184
virtual void addDataProcessing(DataProcessing d)
Optionally add a data processing method to each chromatogram and spectrum.
std::vector< std::vector< ConstDataProcessingPtr > > dps_
Vector of data processing objects -> will be filled by writeHeader_.
Definition: MSDataWritingConsumer.h:200
bool add_dataprocessing_
Whether to add dataprocessing term to the data before writing.
Definition: MSDataWritingConsumer.h:192
MSDataWritingConsumer(const String &filename)
Constructor.
MapType::ChromatogramType ChromatogramType
Definition: MSDataWritingConsumer.h:70
virtual void processSpectrum_(SpectrumType &s)=0
Process a spectrum before storing to disk.
void consumeChromatogram(ChromatogramType &c) override
Consume a chromatogram.
DataProcessingPtr additional_dataprocessing_
The dataprocessing to be added to each spectrum/chromatogram.
Definition: MSDataWritingConsumer.h:202
virtual void doCleanup_()
Cleanup function called by the destructor.
Size chromatograms_expected_
Number of chromatograms expected.
Definition: MSDataWritingConsumer.h:190
bool writing_chromatograms_
Stores whether we are currently writing chromatograms.
Definition: MSDataWritingConsumer.h:182
PeakMap MapType
Definition: MSDataWritingConsumer.h:68
void setExperimentalSettings(const ExperimentalSettings &exp) override
Set experimental settings for the whole file.
void consumeSpectrum(SpectrumType &s) override
Consume a spectrum.
MapType::SpectrumType SpectrumType
Definition: MSDataWritingConsumer.h:69
virtual Size getNrSpectraWritten()
Return the number of spectra written.
bool started_writing_
Stores whether we have already started writing any data.
Definition: MSDataWritingConsumer.h:178
ExperimentalSettings settings_
Experimental settings to use for the whole file.
Definition: MSDataWritingConsumer.h:198
Size chromatograms_written_
Number of chromatograms written.
Definition: MSDataWritingConsumer.h:186
Internal::MzMLValidator * validator_
Validator that knows about CV terms.
Definition: MSDataWritingConsumer.h:195
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:46
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
Consumer class that perform no operation.
Definition: MSDataWritingConsumer.h:234
void consumeChromatogram(ChromatogramType &) override
Consume a chromatogram.
Definition: MSDataWritingConsumer.h:240
void processChromatogram_(MapType::ChromatogramType &) override
Process a chromatogram before storing to disk.
Definition: MSDataWritingConsumer.h:246
NoopMSDataWritingConsumer(String filename)
Definition: MSDataWritingConsumer.h:237
void doCleanup_() override
Cleanup function called by the destructor.
Definition: MSDataWritingConsumer.h:244
void setExperimentalSettings(const ExperimentalSettings &) override
Set experimental settings for the whole file.
Definition: MSDataWritingConsumer.h:238
void processSpectrum_(MapType::SpectrumType &) override
Process a spectrum before storing to disk.
Definition: MSDataWritingConsumer.h:245
void consumeSpectrum(SpectrumType &) override
Consume a spectrum.
Definition: MSDataWritingConsumer.h:239
Consumer class that writes MS data to disk using the mzML format.
Definition: MSDataWritingConsumer.h:216
void processChromatogram_(MapType::ChromatogramType &) override
Process a chromatogram before storing to disk.
Definition: MSDataWritingConsumer.h:218
void processSpectrum_(MapType::SpectrumType &) override
Process a spectrum before storing to disk.
Definition: MSDataWritingConsumer.h:217
PlainMSDataWritingConsumer(String filename)
Definition: MSDataWritingConsumer.h:222
A more convenient string class.
Definition: String.h:34
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:101
const double c
Definition: Constants.h:188
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22
boost::shared_ptr< DataProcessing > DataProcessingPtr
Definition: DataProcessing.h:110