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

OpenSwath::ISpectrumAccess implementation backed by an sqMass (SQLite) spectrum store. More...

#include <OpenMS/ANALYSIS/OPENSWATH/DATAACCESS/SpectrumAccessSqMass.h>

Inheritance diagram for SpectrumAccessSqMass:
ISpectrumAccess

Public Types

typedef OpenMS::MSSpectrum MSSpectrumType
 
typedef OpenMS::MSChromatogram MSChromatogramType
 

Public Member Functions

 SpectrumAccessSqMass (const OpenMS::Internal::MzMLSqliteHandler &handler)
 Construct from an sqMass handler exposing every spectrum it contains.
 
 SpectrumAccessSqMass (const OpenMS::Internal::MzMLSqliteHandler &handler, const std::vector< int > &indices)
 Construct from an sqMass handler exposing only the spectra at the given indices.
 
 SpectrumAccessSqMass (const SpectrumAccessSqMass &sp, const std::vector< int > &indices)
 Construct a narrower view of an existing accessor.
 
 ~SpectrumAccessSqMass () override
 Destructor.
 
 SpectrumAccessSqMass (const SpectrumAccessSqMass &rhs)
 Copy constructor.
 
std::shared_ptr< OpenSwath::ISpectrumAccess > lightClone () const override
 Return a copy of this accessor as a new OpenSwath::ISpectrumAccess pointer.
 
OpenSwath::SpectrumPtr getSpectrumById (int id) override
 Load one spectrum by index in the visible view.
 
OpenSwath::SpectrumMeta getSpectrumMetaById (int id) const override
 Load metadata (native id, RT, MS level) for one spectrum.
 
void getAllSpectra (std::vector< OpenSwath::SpectrumPtr > &spectra, std::vector< OpenSwath::SpectrumMeta > &spectra_meta) const
 Batch-load every spectrum in the visible view into memory.
 
std::vector< std::size_t > getSpectraByRT (double RT, double deltaRT) const override
 Indices into the visible view of spectra whose RT lies within an absolute window.
 
size_t getNrSpectra () const override
 Number of spectra in the visible view.
 
OpenSwath::ChromatogramPtr getChromatogramById (int id) override
 Not supported on sqMass.
 
size_t getNrChromatograms () const override
 Number of chromatograms in the underlying sqMass file.
 
std::string getChromatogramNativeID (int id) const override
 Not supported on sqMass.
 
- Public Member Functions inherited from ISpectrumAccess
virtual ~ISpectrumAccess ()
 Destructor.
 
SpectrumPtr getSpectrumById (int id, double drift_start, double drift_end)
 Return pointer to a spectrum at the given id, the spectrum will be filtered by drift time.
 
SpectrumSequence getMultipleSpectra (double RT, int nr_spectra_to_fetch)
 
SpectrumSequence getMultipleSpectra (double RT, int nr_spectra_to_fetch, double drift_start, double drift_end)
 

Private Attributes

OpenMS::Internal::MzMLSqliteHandler handler_
 Handler for the underlying sqMass file (copied by value into each accessor / clone)
 
std::vector< int > sidx_
 Optional subset of absolute spectrum indices; empty means "all spectra in the file are visible".
 

Additional Inherited Members

- Static Public Member Functions inherited from ISpectrumAccess
static SpectrumPtr filterByDrift (const SpectrumPtr &input, double drift_start, double drift_end)
 filters a spectrum by drift time, spectrum pointer returned is a copy
 

Detailed Description

OpenSwath::ISpectrumAccess implementation backed by an sqMass (SQLite) spectrum store.

Wraps an OpenMS::Internal::MzMLSqliteHandler to expose its spectra through the OpenSWATH spectrum-access interface. Optionally restricts the visible set to a subset of spectra via a vector of indices, so the same on-disk store can back several views (e.g. one per SWATH window, or MS1-only / MS2-only).

Subsetting

Three constructors are provided:

  • (handler) — expose every spectrum in handler.
  • (handler, indices) — expose only the spectra at the given indices.
  • (parent, indices) — narrow an existing SpectrumAccessSqMass further; indices are interpreted against the parent's already-filtered view. Out-of-range entries throw Exception::IllegalArgument.

All getXxxById methods honour the subset: id i refers to the i-th element of the visible view, not the i-th row of the underlying SQLite table.

Performance and concurrency

Per-spectrum access (getSpectrumById / getSpectrumMetaById) is implemented but each call performs one OpenMS::Internal::MzMLSqliteHandler::readSpectra invocation and incurs the per-query SQLite overhead. Callers that need many spectra should prefer getAllSpectra, which issues a single batched read.

The class is read-only and SQLite supports parallel reads from independent connections, so cloning via lightClone gives a clone safe to use from another thread.

Chromatogram support

Spectrum-side operations are fully supported. On the chromatogram side, only the count getNrChromatograms is implemented; both getChromatogramById and getChromatogramNativeID throw Exception::NotImplemented. Use a different accessor (e.g. read via OpenMS::Internal::MzMLSqliteHandler directly) for chromatogram payloads.

Sample usage

// Obtain swath_map with boundaries first
std::vector<int> indices = sql_mass_reader.readSpectraForWindow(swath_map);
OpenMS::Internal::MzMLSqliteHandler handler(file, 0); // the run ID is only used when writing
swath_maps[k].sptr = sptr;
Sqlite handler for storing spectra and chromatograms in sqMass format.
Definition MzMLSqliteHandler.h:49
OpenSwath::ISpectrumAccess implementation backed by an sqMass (SQLite) spectrum store.
Definition SpectrumAccessSqMass.h:76
std::shared_ptr< ISpectrumAccess > SpectrumAccessPtr
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:146

Member Typedef Documentation

◆ MSChromatogramType

◆ MSSpectrumType

Constructor & Destructor Documentation

◆ SpectrumAccessSqMass() [1/4]

Construct from an sqMass handler exposing every spectrum it contains.

Parameters
[in]handlerRead-only handler to the underlying sqMass file.

◆ SpectrumAccessSqMass() [2/4]

SpectrumAccessSqMass ( const OpenMS::Internal::MzMLSqliteHandler &  handler,
const std::vector< int > &  indices 
)

Construct from an sqMass handler exposing only the spectra at the given indices.

Parameters
[in]handlerRead-only handler to the underlying sqMass file.
[in]indicesAbsolute spectrum indices to expose; an empty vector falls back to "all spectra" semantics.

◆ SpectrumAccessSqMass() [3/4]

SpectrumAccessSqMass ( const SpectrumAccessSqMass &  sp,
const std::vector< int > &  indices 
)

Construct a narrower view of an existing accessor.

If sp already has a subset configured, indices are interpreted against that subset (i.e. indices[k] is a position within sp's already-visible view, not within the raw sqMass file).

Parameters
[in]spParent accessor.
[in]indicesIndices into sp's already-filtered view; empty inherits sp's subset unchanged.
Exceptions
Exception::IllegalArgumentIf any entry of indices is out of range of sp's subset.

◆ ~SpectrumAccessSqMass()

~SpectrumAccessSqMass ( )
override

Destructor.

◆ SpectrumAccessSqMass() [4/4]

Copy constructor.

Duplicates the OpenMS::Internal::MzMLSqliteHandler value and the optional subset-index vector; no shared mutable state remains between the copy and the original.

Parameters
[in]rhsSource accessor to copy.

Member Function Documentation

◆ getAllSpectra()

void getAllSpectra ( std::vector< OpenSwath::SpectrumPtr > &  spectra,
std::vector< OpenSwath::SpectrumMeta > &  spectra_meta 
) const

Batch-load every spectrum in the visible view into memory.

Preferred over repeated getSpectrumById calls — issues a single batched read.

Parameters
[out]spectraReceives one SpectrumPtr per visible spectrum.
[out]spectra_metaReceives the parallel metadata records.

◆ getChromatogramById()

OpenSwath::ChromatogramPtr getChromatogramById ( int  id)
overridevirtual

Not supported on sqMass.

Parameters
[in]idIgnored.
Returns
Never returns normally.
Exceptions
Exception::NotImplementedAlways — sqMass-backed access does not implement per-chromatogram payload retrieval. Use a different accessor for chromatogram payloads.

Implements ISpectrumAccess.

◆ getChromatogramNativeID()

std::string getChromatogramNativeID ( int  id) const
overridevirtual

Not supported on sqMass.

Parameters
[in]idIgnored.
Returns
Never returns normally.
Exceptions
Exception::NotImplementedAlways — sqMass-backed access does not expose chromatogram native ids.

Implements ISpectrumAccess.

◆ getNrChromatograms()

size_t getNrChromatograms ( ) const
overridevirtual

Number of chromatograms in the underlying sqMass file.

The count is supported even though per-chromatogram payload / native-id access is not.

Returns
Total chromatogram count.

Implements ISpectrumAccess.

◆ getNrSpectra()

size_t getNrSpectra ( ) const
overridevirtual

Number of spectra in the visible view.

Returns
Subset size when a subset is configured, otherwise the total spectrum count of the underlying sqMass file.

Implements ISpectrumAccess.

◆ getSpectraByRT()

std::vector< std::size_t > getSpectraByRT ( double  RT,
double  deltaRT 
) const
overridevirtual

Indices into the visible view of spectra whose RT lies within an absolute window.

A deltaRT of zero returns only the first spectrum at or after RT (or no spectrum if there is none); getMultipleSpectra relies on this first-at-or-after behaviour.

Parameters
[in]RTCentre of the RT window (same units as the underlying spectra).
[in]deltaRTHalf-width of the RT window. A positive value matches spectra in \([RT - \mathrm{deltaRT}, RT + \mathrm{deltaRT}]\); zero matches only the first spectrum at or after RT (spectra are assumed to be stored in RT order).
Returns
Indices into the visible view (already remapped through the subset, if any).
Note
Aborts via OPENMS_PRECONDITION if deltaRT is negative.

Implements ISpectrumAccess.

◆ getSpectrumById()

OpenSwath::SpectrumPtr getSpectrumById ( int  id)
overridevirtual

Load one spectrum by index in the visible view.

Issues a single OpenMS::Internal::MzMLSqliteHandler::readSpectra call per invocation, so the SQLite per-query overhead applies to each call.

Parameters
[in]idSpectrum index in the visible view (0-based; honours the optional subset).
Returns
Pointer to the loaded spectrum.
Warning
Prefer getAllSpectra when many spectra are needed; per-call cost is dominated by the SQLite query overhead.

Implements ISpectrumAccess.

◆ getSpectrumMetaById()

OpenSwath::SpectrumMeta getSpectrumMetaById ( int  id) const
overridevirtual

Load metadata (native id, RT, MS level) for one spectrum.

Same per-call cost trade-off as getSpectrumById.

Parameters
[in]idSpectrum index in the visible view (0-based).
Returns
Metadata record for the requested spectrum.

Implements ISpectrumAccess.

◆ lightClone()

std::shared_ptr< OpenSwath::ISpectrumAccess > lightClone ( ) const
overridevirtual

Return a copy of this accessor as a new OpenSwath::ISpectrumAccess pointer.

The clone uses an independent OpenMS::Internal::MzMLSqliteHandler value, so it is safe to use from another thread (SQLite supports parallel reads from independent connections).

Returns
Shared pointer to a new accessor with the same visible view as this one.

Implements ISpectrumAccess.

Member Data Documentation

◆ handler_

Handler for the underlying sqMass file (copied by value into each accessor / clone)

◆ sidx_

std::vector<int> sidx_
private

Optional subset of absolute spectrum indices; empty means "all spectra in the file are visible".