OpenMS
CachedMzMLHandler.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 
14 #include <OpenMS/CONCEPT/Types.h>
16 #include <OpenMS/CONCEPT/Macros.h>
17 
20 
21 #include <fstream>
22 
23 #define CACHED_MZML_FILE_IDENTIFIER 8094
24 
25 namespace OpenMS
26 {
27 
28 namespace Internal
29 {
30 
40  class OPENMS_DLLAPI CachedMzMLHandler :
41  public ProgressLogger
42  {
43  typedef int IntType;
44  typedef double DoubleType;
45 
46 public:
47 
48  typedef PeakMap MapType;
51 
52  // using double precision to store all data (has to agree with type of BinaryDataArrayPtr)
53  typedef double DatumSingleton;
54 
55  typedef std::vector<DatumSingleton> Datavector;
56 
62 
64  ~CachedMzMLHandler() override;
65 
69 
73 
75  void writeMemdump(const MapType& exp, const String& out) const;
76 
78  void writeMetadata(MapType exp, const String& out_meta, bool addCacheMetaValue=false);
79 
81  void writeMetadata_x(const MapType& exp, const String& out_meta, bool addCacheMetaValue=false);
82 
84  void readMemdump(MapType& exp_reading, const String& filename) const;
86 
91  void createMemdumpIndex(const String& filename);
92 
94  const std::vector<std::streampos>& getSpectraIndex() const;
95 
97  const std::vector<std::streampos>& getChromatogramIndex() const;
99 
103 
116  std::ifstream& ifs,
117  int& ms_level,
118  double& rt)
119  {
120  std::vector<OpenSwath::BinaryDataArrayPtr> data = readSpectrumFast(ifs, ms_level, rt);
121  data1 = data[0];
122  data2 = data[1];
123  }
124 
134  static std::vector<OpenSwath::BinaryDataArrayPtr> readSpectrumFast(std::ifstream& ifs, int& ms_level, double& rt);
135 
145  OpenSwath::BinaryDataArrayPtr& data2, std::ifstream& ifs)
146  {
147  std::vector<OpenSwath::BinaryDataArrayPtr> data = readChromatogramFast(ifs);
148  data1 = data[0];
149  data2 = data[1];
150  }
151 
159  static std::vector<OpenSwath::BinaryDataArrayPtr> readChromatogramFast(std::ifstream& ifs);
161 
170  static void readSpectrum(SpectrumType& spectrum, std::ifstream& ifs);
171 
180  static void readChromatogram(ChromatogramType& chromatogram, std::ifstream& ifs);
181 
182 protected:
183 
185  void writeSpectrum_(const SpectrumType& spectrum, std::ofstream& ofs) const;
186 
188  void writeChromatogram_(const ChromatogramType& chromatogram, std::ofstream& ofs) const;
189 
191  static inline void readDataFast_(std::ifstream& ifs, std::vector<OpenSwath::BinaryDataArrayPtr>& data, const Size& data_size,
192  const Size& nr_float_arrays);
193 
195  std::vector<std::streampos> spectra_index_;
196  std::vector<std::streampos> chrom_index_;
197 
198  };
199 }
200 }
201 
An class that uses on-disk caching to read and write spectra and chromatograms.
Definition: CachedMzMLHandler.h:42
static void readDataFast_(std::ifstream &ifs, std::vector< OpenSwath::BinaryDataArrayPtr > &data, const Size &data_size, const Size &nr_float_arrays)
helper method for fast reading of spectra and chromatograms
void writeSpectrum_(const SpectrumType &spectrum, std::ofstream &ofs) const
write a single spectrum to filestream
std::vector< DatumSingleton > Datavector
Definition: CachedMzMLHandler.h:55
const std::vector< std::streampos > & getChromatogramIndex() const
Access to a constant copy of the binary chromatogram index.
MSChromatogram ChromatogramType
Definition: CachedMzMLHandler.h:50
void writeChromatogram_(const ChromatogramType &chromatogram, std::ofstream &ofs) const
write a single chromatogram to filestream
static std::vector< OpenSwath::BinaryDataArrayPtr > readSpectrumFast(std::ifstream &ifs, int &ms_level, double &rt)
Fast access to a spectrum.
static void readSpectrum(SpectrumType &spectrum, std::ifstream &ifs)
Read a single spectrum directly into an OpenMS MSSpectrum (assuming file is already at the correct po...
double DoubleType
Definition: CachedMzMLHandler.h:44
MSSpectrum SpectrumType
Definition: CachedMzMLHandler.h:49
std::vector< std::streampos > chrom_index_
Definition: CachedMzMLHandler.h:196
void readMemdump(MapType &exp_reading, const String &filename) const
Read all spectra from a dump from the disk.
static void readSpectrumFast(OpenSwath::BinaryDataArrayPtr &data1, OpenSwath::BinaryDataArrayPtr &data2, std::ifstream &ifs, int &ms_level, double &rt)
fast access to a spectrum (a direct copy of the data into the provided arrays)
Definition: CachedMzMLHandler.h:114
std::vector< std::streampos > spectra_index_
Members.
Definition: CachedMzMLHandler.h:195
int IntType
Definition: CachedMzMLHandler.h:43
CachedMzMLHandler()
Default constructor.
void writeMetadata_x(const MapType &exp, const String &out_meta, bool addCacheMetaValue=false)
Write only the meta data of an MSExperiment.
void createMemdumpIndex(const String &filename)
Create an index on the location of all the spectra and chromatograms.
static void readChromatogram(ChromatogramType &chromatogram, std::ifstream &ifs)
Read a single chromatogram directly into an OpenMS MSChromatogram (assuming file is already at the co...
const std::vector< std::streampos > & getSpectraIndex() const
Access to a constant copy of the binary spectra index.
static void readChromatogramFast(OpenSwath::BinaryDataArrayPtr &data1, OpenSwath::BinaryDataArrayPtr &data2, std::ifstream &ifs)
Fast access to a chromatogram.
Definition: CachedMzMLHandler.h:144
PeakMap MapType
Definition: CachedMzMLHandler.h:48
CachedMzMLHandler & operator=(const CachedMzMLHandler &rhs)
Assignment operator.
void writeMetadata(MapType exp, const String &out_meta, bool addCacheMetaValue=false)
Write only the meta data of an MSExperiment.
static std::vector< OpenSwath::BinaryDataArrayPtr > readChromatogramFast(std::ifstream &ifs)
Fast access to a chromatogram.
double DatumSingleton
Definition: CachedMzMLHandler.h:53
~CachedMzMLHandler() override
Default destructor.
void writeMemdump(const MapType &exp, const String &out) const
Write complete spectra as a dump to the disk.
The representation of a chromatogram.
Definition: MSChromatogram.h:31
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:46
The representation of a 1D spectrum.
Definition: MSSpectrum.h:44
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:27
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
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22
boost::shared_ptr< BinaryDataArray > BinaryDataArrayPtr
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/DataStructures.h:53