OpenMS  3.0.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-2022.
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 
133  Size getNrSpectra() const;
134 
140  Size getNrChromatograms() const;
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 
237  void createIndices_();
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 
OpenMS::TOPPBase
Base class for TOPP applications.
Definition: TOPPBase.h:147
OpenMS::Internal::MzMLSqliteHandler::filename_
String filename_
Definition: MzMLSqliteHandler.h:240
FileHandler.h
Size
OpenMS::UInt64
OPENMS_UINT64_TYPE UInt64
Unsigned integer type (64bit)
Definition: Types.h:77
OpenMS::MSExperiment::reserveSpaceChromatograms
void reserveSpaceChromatograms(Size s)
SwathMap.h
OpenMS::Internal::MzMLSqliteHandler
Sqlite handler for storing spectra and chromatograms in sqMass format.
Definition: MzMLSqliteHandler.h:77
OpenMS::MzMLFile::store
void store(const String &filename, const PeakMap &map) const
Stores a map in an MzML file.
OpenMS::MzMLFile
File adapter for MzML files.
Definition: MzMLFile.h:57
OpenMS::String
A more convenient string class.
Definition: String.h:58
MzMLFile.h
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:70
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::Internal::MzMLSqliteHandler::linear_abs_mass_acc_
double linear_abs_mass_acc_
Definition: MzMLSqliteHandler.h:255
OpenMS::MSExperiment::reserveSpaceSpectra
void reserveSpaceSpectra(Size s)
OpenMS::Int
int Int
Signed integer type.
Definition: Types.h:102
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
OpenMS::MSExperiment::addSpectrum
void addSpectrum(const MSSpectrum &spectrum)
adds a spectrum to the list
OpenMS::Internal::MzMLSqliteHandler::run_id_
UInt64 run_id_
Definition: MzMLSqliteHandler.h:252
OpenMS::MSExperiment::getChromatograms
const std::vector< MSChromatogram > & getChromatograms() const
returns the chromatogram list
OpenMS::MzMLFile::load
void load(const String &filename, PeakMap &map)
Loads a map from a MzML file. Spectra and chromatograms are sorted by default (this can be disabled u...
OpenMS::Internal::MzMLSqliteHandler::setConfig
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
OpenMS::Internal::MzMLSqliteHandler::spec_id_
Int spec_id_
Definition: MzMLSqliteHandler.h:250
OpenMS::String::toQString
QString toQString() const
Conversion to Qt QString.
OpenMS::Internal::MzMLSqliteHandler::chrom_id_
Int chrom_id_
Definition: MzMLSqliteHandler.h:251
ExperimentalSettings.h
OpenMS::Internal::MzMLSqliteHandler::write_full_meta_
double write_full_meta_
Definition: MzMLSqliteHandler.h:256
OpenMS::MSExperiment::addChromatogram
void addChromatogram(const MSChromatogram &chromatogram)
adds a chromatogram to the list
main
int main(int argc, const char **argv)
Definition: INIFileEditor.cpp:71
MSExperiment.h
OpenMS::Internal::MzMLSqliteHandler::use_lossy_compression_
bool use_lossy_compression_
Definition: MzMLSqliteHandler.h:254
OpenMS::MSExperiment::getSpectra
const std::vector< MSSpectrum > & getSpectra() const
returns the spectrum list
OpenMS::FileHandler::stripExtension
static String stripExtension(const String &filename)
If filename contains an extension, it will be removed (including the '.'). Special extensions,...
OpenMS::Internal::MzMLSqliteHandler::sql_batch_size_
int sql_batch_size_
Definition: MzMLSqliteHandler.h:257
OpenMS::DataProcessing::FILTERING
Data filtering or extraction.
Definition: DataProcessing.h:71
File.h
TOPPBase.h