OpenMS  2.7.0
Public Member Functions | List of all members
MzMLSqliteHandler Class Reference

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

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

Collaboration diagram for MzMLSqliteHandler:
[legend]

Public Member Functions

 MzMLSqliteHandler (const String &filename, const UInt64 run_id)
 Constructor of sqMass file. More...
 

Functions for writing files

----------------------------------- Writing to SQL file starts here -----------------------------------

String filename_
 
Int spec_id_
 
Int chrom_id_
 
UInt64 run_id_
 
bool use_lossy_compression_
 
double linear_abs_mass_acc_
 
double write_full_meta_
 
int sql_batch_size_
 
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)
 Write the run-level information for an experiment into tables. More...
 
void createIndices_ ()
 

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...
 
UInt64 getRunID () const
 
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
 

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 ( const String filename,
const UInt64  run_id 
)

Constructor of sqMass file.

Parameters
filenameThe sqMass filename
run_idUnique identifier which links the sqMass and OSW file. It is currently only used for storing and ignored when reading an sqMass file.

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

◆ getRunID()

UInt64 getRunID ( ) const

extract the RUN::ID from the sqMass file

Exceptions
Exception::SqlOperationFailedmore than on run exists

◆ 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
RTThe retention time
deltaRTTolerance window around RT (if less or equal than zero, only the first spectrum *after* RT is returned)
indicesSpectra 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
expThe result
indicesA list of indices restricting the resulting chromatograms only to those specified here
meta_onlyOnly read the meta data

◆ readExperiment()

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

Read an experiment into an MSExperiment structure.

Parameters
expThe result data structure
meta_onlyOnly 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
expThe result
indicesA list of indices restricting the resulting spectra only to those specified here
meta_onlyOnly 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_metaWhether to write a complete mzML meta data structure into the RUN_EXTRA field (allows complete recovery of the input file)
use_lossy_compressionWhether to use lossy compression (ms numpress)
linear_abs_mass_accAccepted loss in mass accuracy (absolute m/z, in Th)
sql_batch_sizeBatch size of SQL insert statements

◆ writeChromatograms()

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

Writes a set of chromatograms to disk.

Parameters
chromatogramsThe chromatograms to write

◆ writeExperiment()

void writeExperiment ( const MSExperiment exp)

Write an experiment to disk.

Parameters
expThe data to write

◆ writeRunLevelInformation()

void writeRunLevelInformation ( const MSExperiment exp,
bool  write_full_meta 
)

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
expThe result data structure
meta_onlyOnly read the meta data

◆ writeSpectra()

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

Writes a set of spectra to disk.

Parameters
spectraThe 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_

UInt64 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