Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
CachedMzML.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-2017.
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 #ifndef OPENMS_FORMAT_CACHEDMZML_H
36 #define OPENMS_FORMAT_CACHEDMZML_H
37 
39 
41 #include <OpenMS/CONCEPT/Types.h>
43 #include <OpenMS/CONCEPT/Macros.h>
44 
47 
48 #include <fstream>
49 
50 #define CACHED_MZML_FILE_IDENTIFIER 8093
51 
52 namespace OpenMS
53 {
54 
64  class OPENMS_DLLAPI CachedmzML :
65  public ProgressLogger
66  {
68  double dbl_field_;
69 
70 public:
71 
72  typedef PeakMap MapType;
75 
76  // using double precision to store all data (has to agree with type of BinaryDataArrayPtr)
77  typedef double DatumSingleton;
78 
79  typedef std::vector<DatumSingleton> Datavector;
80 
84  CachedmzML();
86 
88  ~CachedmzML();
89 
91  CachedmzML& operator=(const CachedmzML& rhs);
93 
97 
99  void writeMemdump(MapType& exp, String out);
100 
102  void writeMetadata(MapType exp, String out_meta, bool addCacheMetaValue=false);
103 
105  void readMemdump(MapType& exp_reading, String filename) const;
107 
111  void createMemdumpIndex(String filename);
113 
115  const std::vector<std::streampos>& getSpectraIndex() const;
116 
118  const std::vector<std::streampos>& getChromatogramIndex() const;
120 
124 
131  OpenSwath::BinaryDataArrayPtr data2, std::ifstream& ifs, int& ms_level,
132  double& rt)
133  {
134  Size spec_size = -1;
135  ifs.read((char*) &spec_size, sizeof(spec_size));
136  ifs.read((char*) &ms_level, sizeof(ms_level));
137  ifs.read((char*) &rt, sizeof(rt));
138 
139  if ( static_cast<int>(spec_size) < 0)
140  {
141  throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
142  "Read an invalid spectrum length, something is wrong here. Aborting.", "filestream");
143  }
144 
145  data1->data.resize(spec_size);
146  data2->data.resize(spec_size);
147 
148  if (spec_size > 0)
149  {
150  ifs.read((char*) &(data1->data)[0], spec_size * sizeof(double));
151  ifs.read((char*) &(data2->data)[0], spec_size * sizeof(double));
152  }
153  }
154 
161  OpenSwath::BinaryDataArrayPtr data2, std::ifstream& ifs)
162  {
163  Size spec_size = -1;
164  ifs.read((char*) &spec_size, sizeof(spec_size));
165 
166  if ( static_cast<int>(spec_size) < 0)
167  {
168  throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
169  "Read an invalid chromatogram length, something is wrong here. Aborting.", "filestream");
170  }
171 
172  data1->data.resize(spec_size);
173  data2->data.resize(spec_size);
174  ifs.read((char*) &(data1->data)[0], spec_size * sizeof(double));
175  ifs.read((char*) &(data2->data)[0], spec_size * sizeof(double));
176  }
178 
179 protected:
180 
182  void readSpectrum_(Datavector& data1, Datavector& data2, std::ifstream& ifs, int& ms_level, double& rt) const;
183 
185  void readChromatogram_(Datavector& data1, Datavector& data2, std::ifstream& ifs) const;
186 
188  void readSpectrum_(SpectrumType& spectrum, std::ifstream& ifs) const;
189 
191  void readChromatogram_(ChromatogramType& chromatogram, std::ifstream& ifs) const;
192 
194  void writeSpectrum_(const SpectrumType& spectrum, std::ofstream& ofs);
195 
197  void writeChromatogram_(const ChromatogramType& chromatogram, std::ofstream& ofs);
198 
200  std::vector<std::streampos> spectra_index_;
201  std::vector<std::streampos> chrom_index_;
202 
203  };
204 }
205 #endif // OPENMS_FORMAT_CACHEDMZML_H
206 
A more convenient string class.
Definition: String.h:57
The representation of a chromatogram.
Definition: MSChromatogram.h:55
double DatumSingleton
Definition: CachedMzML.h:77
std::vector< std::streampos > chrom_index_
Definition: CachedMzML.h:201
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
boost::shared_ptr< BinaryDataArray > BinaryDataArrayPtr
Definition: openswathalgo/include/OpenMS/ANALYSIS/OPENSWATH/OPENSWATHALGO/DATAACCESS/DataStructures.h:77
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
MSChromatogram ChromatogramType
Definition: CachedMzML.h:74
std::vector< DatumSingleton > Datavector
Definition: CachedMzML.h:79
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:82
MSSpectrum SpectrumType
Definition: CachedMzML.h:73
PeakMap MapType
Definition: CachedMzML.h:72
An class that uses on-disk caching to read and write spectra and chromatograms.
Definition: CachedMzML.h:64
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
static void readChromatogramFast(OpenSwath::BinaryDataArrayPtr data1, OpenSwath::BinaryDataArrayPtr data2, std::ifstream &ifs)
fast access to a chromatogram (a direct copy of the data into the provided arrays) ...
Definition: CachedMzML.h:160
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:55
double dbl_field_
Definition: CachedMzML.h:68
int int_field_
Definition: CachedMzML.h:67
std::vector< std::streampos > spectra_index_
Members.
Definition: CachedMzML.h:200
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: CachedMzML.h:130
Parse Error exception.
Definition: Exception.h:623

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:21:59 using doxygen 1.8.13