OpenMS
Loading...
Searching...
No Matches
OpenSwathOSWWriter Class Reference

Class to write out an OpenSwath OSW SQLite output (PyProphet input). More...

#include <OpenMS/ANALYSIS/OPENSWATH/OpenSwathOSWWriter.h>

Collaboration diagram for OpenSwathOSWWriter:
[legend]

Classes

struct  OSWData
 Buffered OSW table rows ready for insertion through prepared statements. More...
 
struct  OSWValue
 Typed OSW cell value used for direct SQLite binding. More...
 

Public Types

using FeatureRow = std::array< OSWValue, FEATURE_COLUMN_COUNT >
 
using FeatureMS1Row = std::array< OSWValue, FEATURE_MS1_COLUMN_COUNT >
 
using FeatureMS2Row = std::array< OSWValue, FEATURE_MS2_COLUMN_COUNT >
 
using FeaturePrecursorRow = std::array< OSWValue, FEATURE_PRECURSOR_COLUMN_COUNT >
 
using FeatureTransitionRow = std::array< OSWValue, FEATURE_TRANSITION_COLUMN_COUNT >
 

Public Member Functions

 OpenSwathOSWWriter (const std::string &output_filename, bool uis_scores=false)
 
bool isActive () const
 
void writeHeader ()
 Initializes file by generating SQLite tables.
 
void addRun (const UInt64 run_id, const std::string &input_filename)
 Add a RUN entry to the OSW file. Can be called multiple times to register multiple runs.
 
void setRunId (const UInt64 run_id)
 Set the current run id used when prepareLine generates FEATURE entries.
 
std::string getScore (const Feature &feature, const std::string &score_name) const
 Prepare scores for SQLite insertion.
 
std::vector< std::string > getSeparateScore (const Feature &feature, const std::string &score_name) const
 Prepare concatenated scores for SQLite insertion.
 
OSWData prepareRows (const OpenSwath::LightCompound &pep, const OpenSwath::LightTransition *transition, const FeatureMap &output, const std::string &id) const
 Prepare feature rows for SQLite insertion.
 
void prepareRowsInto (OSWData &rows, const OpenSwath::LightCompound &pep, const OpenSwath::LightTransition *transition, const FeatureMap &output, const std::string &id) const
 Append feature rows for SQLite insertion into an existing buffer.
 
std::string prepareLine (const OpenSwath::LightCompound &pep, const OpenSwath::LightTransition *transition, const FeatureMap &output, const std::string &id) const
 Prepare a single line (feature) for output.
 
void writeRows (const OSWData &osw_output)
 Write buffered OSW rows to disk.
 
void writeLines (const std::vector< std::string > &to_osw_output)
 Write data to disk.
 

Static Public Attributes

static constexpr Size FEATURE_COLUMN_COUNT = 11
 
static constexpr Size FEATURE_MS1_COLUMN_COUNT = 18
 
static constexpr Size FEATURE_MS2_COLUMN_COUNT = 38
 
static constexpr Size FEATURE_PRECURSOR_COLUMN_COUNT = 4
 
static constexpr Size FEATURE_TRANSITION_COLUMN_COUNT = 43
 

Private Attributes

std::string output_filename_
 
OpenMS::UInt64 run_id_ = 0
 
bool doWrite_
 
bool enable_uis_scoring_
 
std::unique_ptr< SqliteConnectorconn_
 
std::mutex conn_mutex_
 

Detailed Description

Class to write out an OpenSwath OSW SQLite output (PyProphet input).

The class can take a FeatureMap and create buffered rows from it suitable for output to OSW using the prepareRows function. The SQL data is directly linked to the PQP file format described in the TransitionPQPFile class. See also OpenSwathTSVWriter for another output format.

The file format has the following tables:

RUN
ID INT Primary Key (run id)
FILENAME TEXT Original filename associated with the run
FEATURE
ID INT Primary Key (feature id)
RUN_ID INT Foreign Key (RUN.ID)
PRECURSOR_ID INT Foreign Key (TransitionPQPFile PRECURSOR.ID)
EXP_RT REAL Experimental RT (retention time) of the feature
NORM_RT REAL Normalized RT (retention time) of the feature. The position of the peak group in the normalized retention time space (e.g. fx(RT) where fx describes the transformation fx)
DELTA_RT REAL The difference in retention between expected retention time of the assay and the measured feature retention time (EXP_RT)
LEFT_WIDTH REAL Retention time start of the peak (left width) in seconds
RIGHT_WIDTH REAL Retention time end of the peak (right width) in seconds
FEATURE_MS1
FEATURE_ID INT Foreign Key (FEATURE.ID)
AREA_INTENSITY REAL Precursor intensity (area)
APEX_INTENSITY REAL Precursor intensity (apex)
VAR_... REAL Precursor score used in pyProphet
FEATURE_MS2
FEATURE_ID INT Foreign Key (FEATURE.ID)
AREA_INTENSITY REAL Summed fragment ion intensity (area)
TOTAL_AREA_INTENSITY REAL Summed total XIC of the whole chromatogram
APEX_INTENSITY REAL Summed fragment ion intensity (apex)
TOTAL_MI REAL Total mutual information (MI)
VAR_... REAL Fragment ion score used in pyProphet
FEATURE_PRECURSOR
FEATURE_ID INT Foreign Key (FEATURE.ID)
ISOTOPE INT Isotope identifier
AREA_INTENSITY REAL Precursor isotope ion intensity (area)
APEX_INTENSITY REAL Precursor isotope ion intensity (apex)
FEATURE_TRANSITION
FEATURE_ID INT Foreign Key (FEATURE.ID)
TRANSITION_ID INT Foreign Key (transition identifier)
AREA_INTENSITY REAL Fragment ion intensity (area)
TOTAL_AREA_INTENSITY REAL Total XIC of the whole chromatogram
APEX_INTENSITY REAL Fragment ion intensity (apex)
TOTAL_MI REAL Total mutual information (MI)
VAR_... REAL Fragment ion score used in pyProphet

Member Typedef Documentation

◆ FeatureMS1Row

◆ FeatureMS2Row

◆ FeaturePrecursorRow

◆ FeatureRow

◆ FeatureTransitionRow

Constructor & Destructor Documentation

◆ OpenSwathOSWWriter()

OpenSwathOSWWriter ( const std::string &  output_filename,
bool  uis_scores = false 
)

Member Function Documentation

◆ addRun()

void addRun ( const UInt64  run_id,
const std::string &  input_filename 
)

Add a RUN entry to the OSW file. Can be called multiple times to register multiple runs.

◆ getScore()

std::string getScore ( const Feature feature,
const std::string &  score_name 
) const

Prepare scores for SQLite insertion.

Some scores might not be defined, those are reported as NULL

Parameters
[in]featureThe feature being evaluated
[in]score_nameThe name of the queried score
Returns
A string with the queried score

◆ getSeparateScore()

std::vector< std::string > getSeparateScore ( const Feature feature,
const std::string &  score_name 
) const

Prepare concatenated scores for SQLite insertion.

Some scores might not be defined, those are reported as NULL

Parameters
[in]featureThe feature being evaluated
[in]score_nameThe name of the queried score
Returns
A vector of strings with the queried scores

◆ isActive()

bool isActive ( ) const

◆ prepareLine()

std::string prepareLine ( const OpenSwath::LightCompound pep,
const OpenSwath::LightTransition transition,
const FeatureMap output,
const std::string &  id 
) const

Prepare a single line (feature) for output.

The result can be flushed to disk using writeLines (either line by line or after collecting several lines).

Parameters
[in]pepThe compound (peptide/metabolite) used for extraction
[in]transitionThe transition used for extraction
[in]outputThe feature map containing all features (each feature will generate one entry in the output)
[in]idThe transition group identifier (peptide/metabolite id)
Returns
A string to be written using writeLines

◆ prepareRows()

OSWData prepareRows ( const OpenSwath::LightCompound pep,
const OpenSwath::LightTransition transition,
const FeatureMap output,
const std::string &  id 
) const

Prepare feature rows for SQLite insertion.

This is the preferred high-throughput path. It avoids constructing full SQL statements for every feature and lets writeRows bind values into reusable prepared statements.

Parameters
[in]pepThe compound (peptide/metabolite) used for extraction
[in]transitionThe transition used for extraction
[in]outputThe feature map containing all features
[in]idThe transition group identifier (peptide/metabolite id)
Returns
Buffered OSW table rows

◆ prepareRowsInto()

void prepareRowsInto ( OSWData rows,
const OpenSwath::LightCompound pep,
const OpenSwath::LightTransition transition,
const FeatureMap output,
const std::string &  id 
) const

Append feature rows for SQLite insertion into an existing buffer.

This avoids constructing small per-assay OSWData buffers in high-throughput schedulers.

Parameters
[in,out]rowsThe row buffer to append to
[in]pepThe compound (peptide/metabolite) used for extraction
[in]transitionThe transition used for extraction
[in]outputThe feature map containing all features
[in]idThe transition group identifier (peptide/metabolite id)

◆ setRunId()

void setRunId ( const UInt64  run_id)

Set the current run id used when prepareLine generates FEATURE entries.

◆ writeHeader()

void writeHeader ( )

Initializes file by generating SQLite tables.

◆ writeLines()

void writeLines ( const std::vector< std::string > &  to_osw_output)

Write data to disk.

Takes a set of pre-prepared data statements from prepareLine and flushes them to disk

Parameters
[in]to_osw_outputStatements generated by prepareLine
Note
Try to call this function as little as possible (it opens a new database connection each time)
Only call inside an OpenMP critical section

◆ writeRows()

void writeRows ( const OSWData osw_output)

Write buffered OSW rows to disk.

Uses one SQLite transaction and reusable prepared statements for each OSW table. This is the preferred writer path for newly generated output.

Parameters
[in]osw_outputRows generated by prepareRows
Note
Try to call this function as little as possible (it opens a new database connection each time)
Only call inside an OpenMP critical section

Member Data Documentation

◆ conn_

std::unique_ptr<SqliteConnector> conn_
mutableprivate

◆ conn_mutex_

std::mutex conn_mutex_
mutableprivate

◆ doWrite_

bool doWrite_
private

◆ enable_uis_scoring_

bool enable_uis_scoring_
private

◆ FEATURE_COLUMN_COUNT

constexpr Size FEATURE_COLUMN_COUNT = 11
staticconstexpr

◆ FEATURE_MS1_COLUMN_COUNT

constexpr Size FEATURE_MS1_COLUMN_COUNT = 18
staticconstexpr

◆ FEATURE_MS2_COLUMN_COUNT

constexpr Size FEATURE_MS2_COLUMN_COUNT = 38
staticconstexpr

◆ FEATURE_PRECURSOR_COLUMN_COUNT

constexpr Size FEATURE_PRECURSOR_COLUMN_COUNT = 4
staticconstexpr

◆ FEATURE_TRANSITION_COLUMN_COUNT

constexpr Size FEATURE_TRANSITION_COLUMN_COUNT = 43
staticconstexpr

◆ output_filename_

std::string output_filename_
private

◆ run_id_

OpenMS::UInt64 run_id_ = 0
private