| OpenMS 2.5.0

CachedMzMLHandler.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
37 #include <OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h>
38
39 #include <OpenMS/KERNEL/StandardDeclarations.h>
40 #include <OpenMS/CONCEPT/Types.h>
41 #include <OpenMS/CONCEPT/Exception.h>
42 #include <OpenMS/CONCEPT/Macros.h>
43
44 #include <OpenMS/KERNEL/StandardTypes.h>
45 #include <OpenMS/CONCEPT/ProgressLogger.h>
46
47 #include <fstream>
48
49 #define CACHED_MZML_FILE_IDENTIFIER 8094
50
51 namespace OpenMS
52 {
53
54 namespace Internal
55 {
56
66 class OPENMS_DLLAPI CachedMzMLHandler :
67 public ProgressLogger
68 {
69 typedef int IntType;
70 typedef double DoubleType;
71
72 public:
73
74 typedef PeakMap MapType;
75 typedef MSSpectrum SpectrumType;
76 typedef MSChromatogram ChromatogramType;
77
78 // using double precision to store all data (has to agree with type of BinaryDataArrayPtr)
79 typedef double DatumSingleton;
80
81 typedef std::vector<DatumSingleton> Datavector;
82
86 CachedMzMLHandler();
88
90 ~CachedMzMLHandler();
91
93 CachedMzMLHandler& operator=(const CachedMzMLHandler& rhs);
95
99
101 void writeMemdump(const MapType& exp, const String& out) const;
102
104 void writeMetadata(MapType exp, String out_meta, bool addCacheMetaValue=false);
105
107 void writeMetadata_x(const MapType& exp, const String& out_meta, bool addCacheMetaValue=false);
108
110 void readMemdump(MapType& exp_reading, String filename) const;
112
116 void createMemdumpIndex(String filename);
118
120 const std::vector<std::streampos>& getSpectraIndex() const;
121
123 const std::vector<std::streampos>& getChromatogramIndex() const;
125
129
140 static inline void readSpectrumFast(OpenSwath::BinaryDataArrayPtr& data1,
141 OpenSwath::BinaryDataArrayPtr& data2,
142 std::ifstream& ifs,
143 int& ms_level,
144 double& rt)
145 {
146 std::vector<OpenSwath::BinaryDataArrayPtr> data = readSpectrumFast(ifs, ms_level, rt);
147 data1 = data[0];
148 data2 = data[1];
149 }
150
160 static std::vector<OpenSwath::BinaryDataArrayPtr> readSpectrumFast(std::ifstream& ifs, int& ms_level, double& rt);
161
170 static inline void readChromatogramFast(OpenSwath::BinaryDataArrayPtr& data1,
171 OpenSwath::BinaryDataArrayPtr& data2, std::ifstream& ifs)
172 {
173 std::vector<OpenSwath::BinaryDataArrayPtr> data = readChromatogramFast(ifs);
174 data1 = data[0];
175 data2 = data[1];
176 }
177
185 static std::vector<OpenSwath::BinaryDataArrayPtr> readChromatogramFast(std::ifstream& ifs);
187
196 static void readSpectrum(SpectrumType& spectrum, std::ifstream& ifs);
197
206 static void readChromatogram(ChromatogramType& chromatogram, std::ifstream& ifs);
207
208 protected:
209
211 void writeSpectrum_(const SpectrumType& spectrum, std::ofstream& ofs) const;
212
214 void writeChromatogram_(const ChromatogramType& chromatogram, std::ofstream& ofs) const;
215
217 static inline void readDataFast_(std::ifstream& ifs, std::vector<OpenSwath::BinaryDataArrayPtr>& data, const Size& data_size,
218 const Size& nr_float_arrays);
219
221 std::vector<std::streampos> spectra_index_;
222 std::vector<std::streampos> chrom_index_;
223
224 };
225 }
226 }
227
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::MSChromatogram
The representation of a chromatogram.
Definition: MSChromatogram.h:54
OpenMS::Internal::CachedMzMLHandler::ChromatogramType
MSChromatogram ChromatogramType
Definition: CachedMzMLHandler.h:76
StandardDeclarations.h
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:77
OpenSwath::BinaryDataArrayPtr
boost::shared_ptr< BinaryDataArray > BinaryDataArrayPtr
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/DataStructures.h:79
Exception.h
OpenMS::Internal::CachedMzMLHandler
An class that uses on-disk caching to read and write spectra and chromatograms.
Definition: CachedMzMLHandler.h:66
StandardTypes.h
OpenMS::Internal::CachedMzMLHandler::MapType
PeakMap MapType
Definition: CachedMzMLHandler.h:74
Types.h
OpenMS::Internal::CachedMzMLHandler::IntType
int IntType
Definition: CachedMzMLHandler.h:69
OpenMS::MSSpectrum
The representation of a 1D spectrum.
Definition: MSSpectrum.h:67
OpenMS::Internal::CachedMzMLHandler::SpectrumType
MSSpectrum SpectrumType
Definition: CachedMzMLHandler.h:75
OpenMS::Internal::CachedMzMLHandler::readSpectrumFast
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:140
ProgressLogger.h
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::ProgressLogger
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:54
OpenMS::Internal::CachedMzMLHandler::readChromatogramFast
static void readChromatogramFast(OpenSwath::BinaryDataArrayPtr &data1, OpenSwath::BinaryDataArrayPtr &data2, std::ifstream &ifs)
Fast access to a chromatogram.
Definition: CachedMzMLHandler.h:170
OpenMS::Internal::CachedMzMLHandler::chrom_index_
std::vector< std::streampos > chrom_index_
Definition: CachedMzMLHandler.h:222
OpenMS::Internal::CachedMzMLHandler::spectra_index_
std::vector< std::streampos > spectra_index_
Members.
Definition: CachedMzMLHandler.h:221
Macros.h
OpenMS::Internal::CachedMzMLHandler::Datavector
std::vector< DatumSingleton > Datavector
Definition: CachedMzMLHandler.h:81
ISpectrumAccess.h
OpenMS::Internal::CachedMzMLHandler::DatumSingleton
double DatumSingleton
Definition: CachedMzMLHandler.h:79
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::Internal::CachedMzMLHandler::DoubleType
double DoubleType
Definition: CachedMzMLHandler.h:70