OpenMS
MzMLSqliteHandler.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 
13 
15 
16 // forward declarations
17 struct sqlite3;
18 struct sqlite3_stmt;
19 
20 namespace OpenMS
21 {
22  class ProgressLogger;
23 
24  namespace Internal
25  {
26 
51  class OPENMS_DLLAPI MzMLSqliteHandler
52  {
53 
54 public:
55 
62  MzMLSqliteHandler(const String& filename, const UInt64 run_id);
63 
71 
78  void readExperiment(MSExperiment & exp, bool meta_only = false) const;
79 
82  UInt64 getRunID() const;
83 
91  void readSpectra(std::vector<MSSpectrum> & exp, const std::vector<int> & indices, bool meta_only = false) const;
92 
100  void readChromatograms(std::vector<MSChromatogram> & exp, const std::vector<int> & indices, bool meta_only = false) const;
101 
108 
115 
124  void setConfig(bool write_full_meta, bool use_lossy_compression, double linear_abs_mass_acc, int sql_batch_size = 500)
125  {
126  write_full_meta_ = write_full_meta;
127  use_lossy_compression_ = use_lossy_compression;
128  linear_abs_mass_acc_ = linear_abs_mass_acc;
129  sql_batch_size_ = sql_batch_size;
130  }
131 
140  std::vector<size_t> getSpectraIndicesbyRT(double RT, double deltaRT, const std::vector<int> & indices) const;
141 
142 protected:
143 
144  void populateChromatogramsWithData_(sqlite3 *db, std::vector<MSChromatogram>& chromatograms) const;
145 
146  void populateChromatogramsWithData_(sqlite3 *db, std::vector<MSChromatogram>& chromatograms, const std::vector<int> & indices) const;
147 
148  void populateSpectraWithData_(sqlite3 *db, std::vector<MSSpectrum>& spectra) const;
149 
150  void populateSpectraWithData_(sqlite3 *db, std::vector<MSSpectrum>& spectra, const std::vector<int> & indices) const;
151 
152  void prepareChroms_(sqlite3 *db, std::vector<MSChromatogram>& chromatograms, const std::vector<int> & indices = {}) const;
153 
154  void prepareSpectra_(sqlite3 *db, std::vector<MSSpectrum>& spectra, const std::vector<int> & indices = {}) const;
156 
157 public:
158 
166 
172  void writeExperiment(const MSExperiment & exp);
173 
183  void createTables();
184 
190  void writeSpectra(const std::vector<MSSpectrum>& spectra);
191 
197  void writeChromatograms(const std::vector<MSChromatogram>& chroms);
198 
207  void writeRunLevelInformation(const MSExperiment& exp, bool write_full_meta);
208 
209 protected:
210 
213 
215 
216  /*
217  * These are spectra and chromatogram ids that are global for a specific
218  * database file. Keeping track of them allows us to append spectra and
219  * chromatograms multiple times to a database.
220  *
221  * However, currently they are initialized to zero when opening a new
222  * file, so appending to an existing file won't work.
223  */
227 
232  };
233 
234 
235  } // namespace Internal
236 } // namespace OpenMS
237 
238 
Sqlite handler for storing spectra and chromatograms in sqMass format.
Definition: MzMLSqliteHandler.h:52
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:214
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:226
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:224
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:124
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:228
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:230
Int chrom_id_
Definition: MzMLSqliteHandler.h:225
int sql_batch_size_
Definition: MzMLSqliteHandler.h:231
double linear_abs_mass_acc_
Definition: MzMLSqliteHandler.h:229
MzMLSqliteHandler(const String &filename, const UInt64 run_id)
Constructor of sqMass file.
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:45
A more convenient string class.
Definition: String.h:34
int Int
Signed integer type.
Definition: Types.h:72
uint64_t UInt64
Unsigned integer type (64bit)
Definition: Types.h:47
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