OpenMS
MSDataSqlConsumer Class Reference

A data consumer that inserts MS data into a SQLite database. More...

#include <OpenMS/FORMAT/DATAACCESS/MSDataSqlConsumer.h>

Inheritance diagram for MSDataSqlConsumer:
[legend]
Collaboration diagram for MSDataSqlConsumer:
[legend]

Public Member Functions

 MSDataSqlConsumer (const String &sql_filename, UInt64 run_id, int buffer_size=500, bool full_meta=true, bool lossy_compression=false, double linear_mass_acc=1e-4)
 Constructor. More...
 
 ~MSDataSqlConsumer () override
 Destructor. More...
 
void flush ()
 Flushes the data for good. More...
 
void consumeSpectrum (SpectrumType &s) override
 Write a spectrum to the output file. More...
 
void consumeChromatogram (ChromatogramType &c) override
 Write a chromatogram to the output file. More...
 
void setExpectedSize (Size, Size) override
 Set expected size of spectra and chromatograms to be consumed. More...
 
void setExperimentalSettings (const ExperimentalSettings &) override
 Set experimental settings (meta-data) of the data to be consumed. More...
 
- Public Member Functions inherited from IMSDataConsumer
virtual ~IMSDataConsumer ()
 

Protected Attributes

String filename_
 
OpenMS::Internal::MzMLSqliteHandlerhandler_
 
size_t flush_after_
 
bool full_meta_
 
std::vector< SpectrumTypespectra_
 
std::vector< ChromatogramTypechromatograms_
 
MSExperiment peak_meta_
 

Private Types

typedef MSExperiment MapType
 
typedef MapType::SpectrumType SpectrumType
 
typedef MapType::ChromatogramType ChromatogramType
 

Additional Inherited Members

- Public Types inherited from IMSDataConsumer
typedef MSSpectrum SpectrumType
 
typedef MSChromatogram ChromatogramType
 

Detailed Description

A data consumer that inserts MS data into a SQLite database.

Consumes spectra and chromatograms and inserts them into an file-based SQL database using SQLite. As SQLite is highly inefficient when inserting one spectrum/chromatogram at a time, the consumer collects the data in an internal buffer and then flushes them all together to disk.

It uses MzMLSqliteHandler internally to write batches of data to disk.

Member Typedef Documentation

◆ ChromatogramType

◆ MapType

typedef MSExperiment MapType
private

◆ SpectrumType

Constructor & Destructor Documentation

◆ MSDataSqlConsumer()

MSDataSqlConsumer ( const String sql_filename,
UInt64  run_id,
int  buffer_size = 500,
bool  full_meta = true,
bool  lossy_compression = false,
double  linear_mass_acc = 1e-4 
)

Constructor.

Opens the SQLite file and writes the tables.

Parameters
sql_filenameThe filename of the SQLite database
run_idUnique identifier which links the sqMass and OSW file
buffer_sizeHow large the internal buffer size should be (defaults to 500 spectra / chromatograms)
full_metaWhether to write the full meta-data in the SQLite header
lossy_compressionWhether to use lossy compression (numpress)
linear_mass_accDesired mass accuracy for RT or m/z space (absolute value)

◆ ~MSDataSqlConsumer()

~MSDataSqlConsumer ( )
override

Destructor.

Flushes the data for good.

Member Function Documentation

◆ consumeChromatogram()

void consumeChromatogram ( ChromatogramType c)
overridevirtual

Write a chromatogram to the output file.

Implements IMSDataConsumer.

◆ consumeSpectrum()

void consumeSpectrum ( SpectrumType s)
overridevirtual

Write a spectrum to the output file.

Implements IMSDataConsumer.

◆ flush()

void flush ( )

Flushes the data for good.

After calling this function, no more data is held in the buffer but the class is still able to receive new data.

◆ setExpectedSize()

void setExpectedSize ( Size  expectedSpectra,
Size  expectedChromatograms 
)
overridevirtual

Set expected size of spectra and chromatograms to be consumed.

Some implementations might care about the number of spectra and chromatograms to be consumed and need to be informed about this (usually before consuming starts).

Note
Calling this method is optional but good practice.
Parameters
expectedSpectraNumber of spectra expected
expectedChromatogramsNumber of chromatograms expected

Implements IMSDataConsumer.

◆ setExperimentalSettings()

void setExperimentalSettings ( const ExperimentalSettings exp)
overridevirtual

Set experimental settings (meta-data) of the data to be consumed.

Some implementations might need to know about the meta-data (or the context) of the spectra and chromatograms to be consumed. This method allows them learn this.

Note
Calling this method is optional but good practice.
Parameters
expExperimental settings meta data for the data to be consumed

Implements IMSDataConsumer.

Member Data Documentation

◆ chromatograms_

std::vector<ChromatogramType> chromatograms_
protected

◆ filename_

String filename_
protected

◆ flush_after_

size_t flush_after_
protected

◆ full_meta_

bool full_meta_
protected

◆ handler_

◆ peak_meta_

MSExperiment peak_meta_
protected

◆ spectra_

std::vector<SpectrumType> spectra_
protected