| OpenMS 2.5.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-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/KERNEL/MSExperiment.h>
38 #include <OpenMS/METADATA/ExperimentalSettings.h>
39
40 #include <OpenMS/OPENSWATHALGO/DATAACCESS/SwathMap.h>
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
87 MzMLSqliteHandler(String filename);
88
96
103 void readExperiment(MSExperiment & exp, bool meta_only = false) const;
104
112 void readSpectra(std::vector<MSSpectrum> & exp, const std::vector<int> & indices, bool meta_only = false) const;
113
121 void readChromatograms(std::vector<MSChromatogram> & exp, const std::vector<int> & indices, bool meta_only = false) const;
122
128 Size getNrSpectra() const;
129
135 Size getNrChromatograms() const;
136
145 void setConfig(bool write_full_meta, bool use_lossy_compression, double linear_abs_mass_acc, int sql_batch_size = 500)
146 {
147 write_full_meta_ = write_full_meta;
148 use_lossy_compression_ = use_lossy_compression;
149 linear_abs_mass_acc_ = linear_abs_mass_acc;
150 sql_batch_size_ = sql_batch_size;
151 }
152
161 std::vector<size_t> getSpectraIndicesbyRT(double RT, double deltaRT, const std::vector<int> & indices) const;
162
163 protected:
164
165 void populateChromatogramsWithData_(sqlite3 *db, std::vector<MSChromatogram>& chromatograms) const;
166
167 void populateChromatogramsWithData_(sqlite3 *db, std::vector<MSChromatogram>& chromatograms, const std::vector<int> & indices) const;
168
169 void populateSpectraWithData_(sqlite3 *db, std::vector<MSSpectrum>& spectra) const;
170
171 void populateSpectraWithData_(sqlite3 *db, std::vector<MSSpectrum>& spectra, const std::vector<int> & indices) const;
172
173 void prepareChroms_(sqlite3 *db, std::vector<MSChromatogram>& chromatograms, const std::vector<int> & indices = {}) const;
174
175 void prepareSpectra_(sqlite3 *db, std::vector<MSSpectrum>& spectra, const std::vector<int> & indices = {}) const;
177
178 public:
179
187
193 void writeExperiment(const MSExperiment & exp);
194
204 void createTables();
205
211 void writeSpectra(const std::vector<MSSpectrum>& spectra);
212
218 void writeChromatograms(const std::vector<MSChromatogram>& chroms);
219
228 void writeRunLevelInformation(const MSExperiment & exp, bool write_full_meta, int run_id);
229
230 protected:
231
232 void createIndices_();
234
235 String filename_;
236
237 /*
238 * These are spectra and chromatogram ids that are global for a specific
239 * database file. Keeping track of them allows us to append spectra and
240 * chromatograms multiple times to a database.
241 *
242 * However, currently they are initialized to zero when opening a new
243 * file, so appending to an existing file won't work.
244 */
245 Int spec_id_;
246 Int chrom_id_;
247 Int run_id_;
248
249 bool use_lossy_compression_;
250 double linear_abs_mass_acc_;
251 double write_full_meta_;
252 int sql_batch_size_;
253 };
254
255
256 } // namespace Internal
257 } // namespace OpenMS
258
259
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:145
OpenMS::String
A more convenient string class.
Definition: String.h:58
OpenMS::Internal::MzMLSqliteHandler::chrom_id_
Int chrom_id_
Definition: MzMLSqliteHandler.h:246
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:77
OpenMS::Internal::MzMLSqliteHandler::use_lossy_compression_
bool use_lossy_compression_
Definition: MzMLSqliteHandler.h:249
ExperimentalSettings.h
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
MSExperiment.h
OpenMS::Internal::MzMLSqliteHandler
Sqlite handler for storing spectra and chromatograms in sqMass format.
Definition: MzMLSqliteHandler.h:77
OpenMS::Internal::MzMLSqliteHandler::filename_
String filename_
Definition: MzMLSqliteHandler.h:235
int
SwathMap.h
OpenMS::Internal::MzMLSqliteHandler::run_id_
Int run_id_
Definition: MzMLSqliteHandler.h:247
OpenMS::Internal::MzMLSqliteHandler::spec_id_
Int spec_id_
Definition: MzMLSqliteHandler.h:245
OpenMS::Internal::MzMLSqliteHandler::write_full_meta_
double write_full_meta_
Definition: MzMLSqliteHandler.h:251
OpenMS::Internal::MzMLSqliteHandler::linear_abs_mass_acc_
double linear_abs_mass_acc_
Definition: MzMLSqliteHandler.h:250
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::sql_batch_size_
int sql_batch_size_
Definition: MzMLSqliteHandler.h:252