OpenMS  2.8.0
MzMLSqliteHandler.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-2021.
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 
39 
41 
42 // forward declarations
43 struct sqlite3;
44 struct sqlite3_stmt;
45 
46 namespace OpenMS
47 {
48  class ProgressLogger;
49 
50  namespace Internal
51  {
52 
77  class OPENMS_DLLAPI MzMLSqliteHandler
78  {
79 
80 public:
81 
88  MzMLSqliteHandler(const String& filename, const UInt64 run_id);
89 
97 
104  void readExperiment(MSExperiment & exp, bool meta_only = false) const;
105 
108  UInt64 getRunID() const;
109 
117  void readSpectra(std::vector<MSSpectrum> & exp, const std::vector<int> & indices, bool meta_only = false) const;
118 
126  void readChromatograms(std::vector<MSChromatogram> & exp, const std::vector<int> & indices, bool meta_only = false) const;
127 
134 
141 
150  void setConfig(bool write_full_meta, bool use_lossy_compression, double linear_abs_mass_acc, int sql_batch_size = 500)
151  {
152  write_full_meta_ = write_full_meta;
153  use_lossy_compression_ = use_lossy_compression;
154  linear_abs_mass_acc_ = linear_abs_mass_acc;
155  sql_batch_size_ = sql_batch_size;
156  }
157 
166  std::vector<size_t> getSpectraIndicesbyRT(double RT, double deltaRT, const std::vector<int> & indices) const;
167 
168 protected:
169 
170  void populateChromatogramsWithData_(sqlite3 *db, std::vector<MSChromatogram>& chromatograms) const;
171 
172  void populateChromatogramsWithData_(sqlite3 *db, std::vector<MSChromatogram>& chromatograms, const std::vector<int> & indices) const;
173 
174  void populateSpectraWithData_(sqlite3 *db, std::vector<MSSpectrum>& spectra) const;
175 
176  void populateSpectraWithData_(sqlite3 *db, std::vector<MSSpectrum>& spectra, const std::vector<int> & indices) const;
177 
178  void prepareChroms_(sqlite3 *db, std::vector<MSChromatogram>& chromatograms, const std::vector<int> & indices = {}) const;
179 
180  void prepareSpectra_(sqlite3 *db, std::vector<MSSpectrum>& spectra, const std::vector<int> & indices = {}) const;
182 
183 public:
184 
192 
198  void writeExperiment(const MSExperiment & exp);
199 
209  void createTables();
210 
216  void writeSpectra(const std::vector<MSSpectrum>& spectra);
217 
223  void writeChromatograms(const std::vector<MSChromatogram>& chroms);
224 
233  void writeRunLevelInformation(const MSExperiment& exp, bool write_full_meta);
234 
235 protected:
236 
239 
241 
242  /*
243  * These are spectra and chromatogram ids that are global for a specific
244  * database file. Keeping track of them allows us to append spectra and
245  * chromatograms multiple times to a database.
246  *
247  * However, currently they are initialized to zero when opening a new
248  * file, so appending to an existing file won't work.
249  */
253 
258  };
259 
260 
261  } // namespace Internal
262 } // namespace OpenMS
263 
264 
Sqlite handler for storing spectra and chromatograms in sqMass format.
Definition: MzMLSqliteHandler.h:78
std::vector< size_t > getSpectraIndicesbyRT(double RT, double deltaRT, const std::vector< int > &indices) const
Get spectral indices around a specific retention time.
void writeExperiment(const MSExperiment &exp)
Write an experiment to disk.
Size getNrSpectra() const
Get number of spectra in the file.
String filename_
Definition: MzMLSqliteHandler.h:240
void populateSpectraWithData_(sqlite3 *db, std::vector< MSSpectrum > &spectra) const
void prepareChroms_(sqlite3 *db, std::vector< MSChromatogram > &chromatograms, const std::vector< int > &indices={}) const
UInt64 run_id_
Definition: MzMLSqliteHandler.h:252
void createTables()
Create data tables for a new file.
Size getNrChromatograms() const
Get number of chromatograms in the file.
void readChromatograms(std::vector< MSChromatogram > &exp, const std::vector< int > &indices, bool meta_only=false) const
Read an set of chromatograms (potentially restricted to a subset)
Int spec_id_
Definition: MzMLSqliteHandler.h:250
void setConfig(bool write_full_meta, bool use_lossy_compression, double linear_abs_mass_acc, int sql_batch_size=500)
Set file configuration.
Definition: MzMLSqliteHandler.h:150
void readExperiment(MSExperiment &exp, bool meta_only=false) const
Read an experiment into an MSExperiment structure.
void prepareSpectra_(sqlite3 *db, std::vector< MSSpectrum > &spectra, const std::vector< int > &indices={}) const
void writeRunLevelInformation(const MSExperiment &exp, bool write_full_meta)
Write the run-level information for an experiment into tables.
void readSpectra(std::vector< MSSpectrum > &exp, const std::vector< int > &indices, bool meta_only=false) const
Read an set of spectra (potentially restricted to a subset)
void populateChromatogramsWithData_(sqlite3 *db, std::vector< MSChromatogram > &chromatograms) const
bool use_lossy_compression_
Definition: MzMLSqliteHandler.h:254
void populateSpectraWithData_(sqlite3 *db, std::vector< MSSpectrum > &spectra, const std::vector< int > &indices) const
void writeSpectra(const std::vector< MSSpectrum > &spectra)
Writes a set of spectra to disk.
void writeChromatograms(const std::vector< MSChromatogram > &chroms)
Writes a set of chromatograms to disk.
void populateChromatogramsWithData_(sqlite3 *db, std::vector< MSChromatogram > &chromatograms, const std::vector< int > &indices) const
double write_full_meta_
Definition: MzMLSqliteHandler.h:256
Int chrom_id_
Definition: MzMLSqliteHandler.h:251
int sql_batch_size_
Definition: MzMLSqliteHandler.h:257
double linear_abs_mass_acc_
Definition: MzMLSqliteHandler.h:255
MzMLSqliteHandler(const String &filename, const UInt64 run_id)
Constructor of sqMass file.
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:73
A more convenient string class.
Definition: String.h:60
OPENMS_UINT64_TYPE UInt64
Unsigned integer type (64bit)
Definition: Types.h:77
int Int
Signed integer type.
Definition: Types.h:102
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47