| OpenMS 2.5.0

Public Member Functions | Protected Attributes | List of all members
MzMLSqliteHandler Class Reference

Sqlite handler for storing spectra and chromatograms in sqMass format. More...

`#include <OpenMS/FORMAT/HANDLERS/MzMLSqliteHandler.h>`

## Public Member Functions

| MzMLSqliteHandler (String filename)
| Constructor of sqMass file. More...

## Protected Attributes

String | filename_
Int | spec_id_
Int | chrom_id_
Int | run_id_
bool | use_lossy_compression_
double | linear_abs_mass_acc_
double | write_full_meta_
int | sql_batch_size_

## Functions for reading files

----------------------------------- Reading of SQL file starts here -----------------------------------
void | readExperiment (MSExperiment &exp, bool meta_only=false) const
| Read an experiment into an MSExperiment structure. More...
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) More...
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) More...
Size | getNrSpectra () const
| Get number of spectra in the file. More...
Size | getNrChromatograms () const
| Get number of chromatograms in the file. More...
void | setConfig (bool write_full_meta, bool use_lossy_compression, double linear_abs_mass_acc, int sql_batch_size=500)
| Set file configuration. More...
std::vector< size_t > | getSpectraIndicesbyRT (double RT, double deltaRT, const std::vector< int > &indices) const
| Get spectral indices around a specific retention time. More...
void | populateChromatogramsWithData_ (sqlite3 *db, std::vector< MSChromatogram > &chromatograms) const
void | populateChromatogramsWithData_ (sqlite3 *db, std::vector< MSChromatogram > &chromatograms, const std::vector< int > &indices) const
void | populateSpectraWithData_ (sqlite3 *db, std::vector< MSSpectrum > &spectra) const
void | populateSpectraWithData_ (sqlite3 *db, std::vector< MSSpectrum > &spectra, const std::vector< int > &indices) const
void | prepareChroms_ (sqlite3 *db, std::vector< MSChromatogram > &chromatograms, const std::vector< int > &indices={}) const
void | prepareSpectra_ (sqlite3 *db, std::vector< MSSpectrum > &spectra, const std::vector< int > &indices={}) const

## Functions for writing files

----------------------------------- Writing to SQL file starts here -----------------------------------
void | writeExperiment (const MSExperiment &exp)
| Write an experiment to disk. More...
void | createTables ()
| Create data tables for a new file. More...
void | writeSpectra (const std::vector< MSSpectrum > &spectra)
| Writes a set of spectra to disk. More...
void | writeChromatograms (const std::vector< MSChromatogram > &chroms)
| Writes a set of chromatograms to disk. More...
void | writeRunLevelInformation (const MSExperiment &exp, bool write_full_meta, int run_id)
| Write the run-level information for an experiment into tables. More...
void | createIndices_ ()

## Detailed Description

Sqlite handler for storing spectra and chromatograms in sqMass format.

Note
  Do not use this class directly, rather use SqMassFile.
  Due to the performance characteristics of the underlying SQLite database, it is highly recommended to read and write data (spectra/chromatograms) in batch. This is supported in this class and essential for reasonable performance. The current class does support batching SQL statements which can be controlled using setConfig and it is recommended to set the batch size to at least 500. The underlying SQLite database only stores the most essential parameters of a MS experiment, to store the complete meta-data, a zipped representation of the mzML data structure can be written directly into the database (and will be retrieved when converting back).

This class also supports writing data using the lossy numpress compression format.

This class contains the internal data structures and SQL statements for communication with the SQLite database

## Constructor & Destructor Documentation

## ◆ MzMLSqliteHandler()

MzMLSqliteHandler | ( | String | filename | ) |

Constructor of sqMass file.

Parameters

  filename | The sqMass filename

## Member Function Documentation

## ◆ createIndices_()

void createIndices_ | ( |  | ) |

protected

## ◆ createTables()

void createTables | ( |  | ) |

Create data tables for a new file.

Note
  It is required to call this function first before writing any data to disk, otherwise the tables will not be set up!
  Be careful with this function, calling this on an existing file will delete the file!

## ◆ getNrChromatograms()

Size getNrChromatograms | ( |  | ) | const

Get number of chromatograms in the file.

Returns
  The number of chromatograms

## ◆ getNrSpectra()

Size getNrSpectra | ( |  | ) | const

Get number of spectra in the file.

Returns
  The number of spectra

## ◆ getSpectraIndicesbyRT()

std::vector<size_t> getSpectraIndicesbyRT | ( | double | RT,
|  | double | deltaRT,
|  | const std::vector< int > & | indices
| ) |  | const

Get spectral indices around a specific retention time.

Parameters

  RT | The retention time
  deltaRT | Tolerance window around RT (if less or equal than zero, only the first spectrum *after* RT is returned)
  indices | Spectra to consider (if empty, all spectra are considered)

Returns
  The indices of the spectra within RT +/- deltaRT

## ◆ populateChromatogramsWithData_() [1/2]

void populateChromatogramsWithData_ | ( | sqlite3 * | db,
|  | std::vector< MSChromatogram > & | chromatograms
| ) |  | const

protected

## ◆ populateChromatogramsWithData_() [2/2]

void populateChromatogramsWithData_ | ( | sqlite3 * | db,
|  | std::vector< MSChromatogram > & | chromatograms,
|  | const std::vector< int > & | indices
| ) |  | const

protected

## ◆ populateSpectraWithData_() [1/2]

void populateSpectraWithData_ | ( | sqlite3 * | db,
|  | std::vector< MSSpectrum > & | spectra
| ) |  | const

protected

## ◆ populateSpectraWithData_() [2/2]

void populateSpectraWithData_ | ( | sqlite3 * | db,
|  | std::vector< MSSpectrum > & | spectra,
|  | const std::vector< int > & | indices
| ) |  | const

protected

## ◆ prepareChroms_()

void prepareChroms_ | ( | sqlite3 * | db,
|  | std::vector< MSChromatogram > & | chromatograms,
|  | const std::vector< int > & | indices = `{}`
| ) |  | const

protected

## ◆ prepareSpectra_()

void prepareSpectra_ | ( | sqlite3 * | db,
|  | std::vector< MSSpectrum > & | spectra,
|  | const std::vector< int > & | indices = `{}`
| ) |  | const

protected

## ◆ readChromatograms()

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)

Parameters

  exp | The result
  indices | A list of indices restricting the resulting chromatograms only to those specified here
  meta_only | Only read the meta data

## ◆ readExperiment()

void readExperiment | ( | MSExperiment & | exp,
|  | bool | meta_only = `false`
| ) |  | const

Read an experiment into an MSExperiment structure.

Parameters

  exp | The result data structure
  meta_only | Only read the meta data

## ◆ readSpectra()

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)

Parameters

  exp | The result
  indices | A list of indices restricting the resulting spectra only to those specified here
  meta_only | Only read the meta data

## ◆ setConfig()

void setConfig | ( | bool | write_full_meta,
|  | bool | use_lossy_compression,
|  | double | linear_abs_mass_acc,
|  | int | sql_batch_size = `500`
| ) |  |

inline

Set file configuration.

Parameters

  write_full_meta | Whether to write a complete mzML meta data structure into the RUN_EXTRA field (allows complete recovery of the input file)
  use_lossy_compression | Whether to use lossy compression (ms numpress)
  linear_abs_mass_acc | Accepted loss in mass accuracy (absolute m/z, in Th)
  sql_batch_size | Batch size of SQL insert statements

## ◆ writeChromatograms()

void writeChromatograms | ( | const std::vector< MSChromatogram > & | chroms | ) |

Writes a set of chromatograms to disk.

Parameters

  chromatograms | The chromatograms to write

## ◆ writeExperiment()

void writeExperiment | ( | const MSExperiment & | exp | ) |

Write an experiment to disk.

Parameters

  exp | The data to write

## ◆ writeRunLevelInformation()

void writeRunLevelInformation | ( | const MSExperiment & | exp,
|  | bool | write_full_meta,
|  | int | run_id
| ) |  |

Write the run-level information for an experiment into tables.

Note
  This is a low level function, do not call this function unless you know what you are doing!

Parameters

  exp | The result data structure
  meta_only | Only read the meta data

## ◆ writeSpectra()

void writeSpectra | ( | const std::vector< MSSpectrum > & | spectra | ) |

Writes a set of spectra to disk.

Parameters

  spectra | The spectra to write

## Member Data Documentation

## ◆ chrom_id_

Int chrom_id_

protected

## ◆ filename_

String filename_

protected

## ◆ linear_abs_mass_acc_

double linear_abs_mass_acc_

protected

## ◆ run_id_

Int run_id_

protected

## ◆ spec_id_

Int spec_id_

protected

## ◆ sql_batch_size_

int sql_batch_size_

protected

## ◆ use_lossy_compression_

bool use_lossy_compression_

protected

## ◆ write_full_meta_

double write_full_meta_

protected