OpenMS
CachedMzMLHandler.h
Go to the documentation of this file.
1 // Copyright (c) 2002-present, 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/CONCEPT/Types.h>
15 #include <OpenMS/CONCEPT/Macros.h>
16 
19 
20 #include <fstream>
21 
22 #define CACHED_MZML_FILE_IDENTIFIER 8094
23 
24 namespace OpenMS
25 {
26 
27 namespace Internal
28 {
29 
39  class OPENMS_DLLAPI CachedMzMLHandler :
40  public ProgressLogger
41  {
42  typedef int IntType;
43  typedef double DoubleType;
44 
45 public:
46 
47  typedef PeakMap MapType;
50 
51  // using double precision to store all data (has to agree with type of BinaryDataArrayPtr)
52  typedef double DatumSingleton;
53 
54  typedef std::vector<DatumSingleton> Datavector;
55 
61 
63  ~CachedMzMLHandler() override;
64 
68 
72 
74  void writeMemdump(const MapType& exp, const String& out) const;
75 
77  void writeMetadata(MapType exp, const String& out_meta, bool addCacheMetaValue=false);
78 
80  void writeMetadata_x(const MapType& exp, const String& out_meta, bool addCacheMetaValue=false);
81 
83  void readMemdump(MapType& exp_reading, const String& filename) const;
85 
90  void createMemdumpIndex(const String& filename);
91 
93  const std::vector<std::streampos>& getSpectraIndex() const;
94 
96  const std::vector<std::streampos>& getChromatogramIndex() const;
98 
102 
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 
146  OpenSwath::BinaryDataArrayPtr& data2, std::ifstream& ifs)
147  {
148  std::vector<OpenSwath::BinaryDataArrayPtr> data = readChromatogramFast(ifs);
149  data1 = data[0];
150  data2 = data[1];
151  }
152 
160  static std::vector<OpenSwath::BinaryDataArrayPtr> readChromatogramFast(std::ifstream& ifs);
162 
171  static void readSpectrum(SpectrumType& spectrum, std::ifstream& ifs);
172 
181  static void readChromatogram(ChromatogramType& chromatogram, std::ifstream& ifs);
182 
183 protected:
184 
186  void writeSpectrum_(const SpectrumType& spectrum, std::ofstream& ofs) const;
187 
189  void writeChromatogram_(const ChromatogramType& chromatogram, std::ofstream& ofs) const;
190 
192  static inline void readDataFast_(std::ifstream& ifs, std::vector<OpenSwath::BinaryDataArrayPtr>& data, const Size& data_size,
193  const Size& nr_float_arrays);
194 
196  std::vector<std::streampos> spectra_index_;
197  std::vector<std::streampos> chrom_index_;
198 
199  };
200 }
201 }
202 
An class that uses on-disk caching to read and write spectra and chromatograms.
Definition: CachedMzMLHandler.h:41
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:54
const std::vector< std::streampos > & getChromatogramIndex() const
Access to a constant copy of the binary chromatogram index.
MSChromatogram ChromatogramType
Definition: CachedMzMLHandler.h:49
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:43
MSSpectrum SpectrumType
Definition: CachedMzMLHandler.h:48
std::vector< std::streampos > chrom_index_
Definition: CachedMzMLHandler.h:197
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:196
int IntType
Definition: CachedMzMLHandler.h:42
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:145
PeakMap MapType
Definition: CachedMzMLHandler.h:47
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:52
~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:30
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:45
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:97
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
boost::shared_ptr< BinaryDataArray > BinaryDataArrayPtr
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/DataStructures.h:53