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

OpenSwath::ISpectrumAccess implementation backed by an on-disk OpenMS::CachedmzML cache. More...

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

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

Public Types

typedef OpenMS::PeakMap MSExperimentType
 
typedef OpenMS::MSSpectrum MSSpectrumType
 

Public Member Functions

 SpectrumAccessOpenMSCached (const std::string &filename)
 Open the cached .mzML pair at filename.
 
 ~SpectrumAccessOpenMSCached () override
 Destructor; the inherited OpenMS::CachedmzML destructor closes the side-car stream.
 
 SpectrumAccessOpenMSCached (const SpectrumAccessOpenMSCached &rhs)
 Copy constructor.
 
std::shared_ptr< OpenSwath::ISpectrumAccesslightClone () const override
 Return a clone of this accessor as a new OpenSwath::ISpectrumAccess.
 
OpenSwath::SpectrumPtr getSpectrumById (int id) override
 Read one spectrum from the side-car file.
 
OpenSwath::SpectrumMeta getSpectrumMetaById (int id) const override
 Return the RT and MS level of one spectrum.
 
std::vector< std::size_t > getSpectraByRT (double RT, double deltaRT) const override
 Indices of cached spectra whose RT lies in [RT - deltaRT, RT + deltaRT].
 
size_t getNrSpectra () const override
 Number of spectra in the loaded metadata.
 
SpectrumSettings getSpectraMetaInfo (int id) const
 Return the full SpectrumSettings of one spectrum.
 
OpenSwath::ChromatogramPtr getChromatogramById (int id) override
 Read one chromatogram from the side-car file.
 
size_t getNrChromatograms () const override
 Number of chromatograms in the loaded metadata.
 
ChromatogramSettings getChromatogramMetaInfo (int id) const
 Return the ChromatogramSettings of one chromatogram.
 
std::string getChromatogramNativeID (int id) const override
 Native id of one cached chromatogram.
 
- 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)
 
- Public Member Functions inherited from CachedmzML
 CachedmzML ()
 Default constructor.
 
 CachedmzML (const std::string &filename)
 Construct and load metadata + side-car index from filename in one step.
 
 CachedmzML (const CachedmzML &rhs)
 Copy constructor.
 
 ~CachedmzML ()
 Destructor.
 
MSSpectrum getSpectrum (Size id)
 Read one spectrum from the side-car file.
 
MSChromatogram getChromatogram (Size id)
 Read one chromatogram from the side-car file.
 
size_t getNrSpectra () const
 Number of spectra in the loaded experiment.
 
size_t getNrChromatograms () const
 Number of chromatograms in the loaded experiment.
 
const MSExperimentgetMetaData () const
 Experiment-level metadata loaded from the .mzML file.
 

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
 
- Static Public Member Functions inherited from CachedmzML
static void store (const std::string &filename, const PeakMap &map)
 Write map to disk as a cached .mzML pair.
 
static void load (const std::string &filename, CachedmzML &map)
 Load a cached .mzML pair into map.
 
- Protected Member Functions inherited from CachedmzML
void load_ (const std::string &filename)
 
- Protected Attributes inherited from CachedmzML
MSExperiment meta_ms_experiment_
 Meta data.
 
std::ifstream ifs_
 Internal filestream.
 
std::string filename_
 Name of the mzML file.
 
std::string filename_cached_
 Name of the cached mzML file.
 
std::vector< std::streampos > spectra_index_
 Indices.
 
std::vector< std::streampos > chrom_index_
 

Detailed Description

OpenSwath::ISpectrumAccess implementation backed by an on-disk OpenMS::CachedmzML cache.

Combines the in-memory index of OpenMS::CachedmzML with the OpenSWATH spectrum-access interface: spectrum and chromatogram metadata are served from the in-memory MSExperiment, and the binary payloads are read on demand from the side-car .mzML.cached file.

Note
This implementation is not thread-safe: a single file stream is maintained and seeked per request, so concurrent calls would race on the stream position. Callers must serialise access externally.

Member Typedef Documentation

◆ MSExperimentType

◆ MSSpectrumType

Constructor & Destructor Documentation

◆ SpectrumAccessOpenMSCached() [1/2]

SpectrumAccessOpenMSCached ( const std::string &  filename)
explicit

Open the cached .mzML pair at filename.

Delegates to OpenMS::CachedmzML's filename constructor: the metadata is loaded from filename and the side-car index for filename + ".cached" is built; subsequent accessor calls read the payloads from that side-car on demand.

Parameters
[in]filenamePath to the .mzML metadata file; the side-car is expected next to it at filename + ".cached".
Exceptions
Exception::FileNotFoundwhen either file cannot be opened.
Exception::ParseErrorwhen the metadata cannot be parsed or the side-car index cannot be built.

◆ ~SpectrumAccessOpenMSCached()

Destructor; the inherited OpenMS::CachedmzML destructor closes the side-car stream.

◆ SpectrumAccessOpenMSCached() [2/2]

Copy constructor.

Each copy keeps its own file handle on the .mzML.cached side-car (a fresh stream is opened on the same path by the inherited OpenMS::CachedmzML copy constructor). The in-memory metadata and side-car index are duplicated; the spectrum and chromatogram binary payloads are not.

Parameters
[in]rhsSource accessor to copy.

Member Function Documentation

◆ getChromatogramById()

OpenSwath::ChromatogramPtr getChromatogramById ( int  id)
overridevirtual

Read one chromatogram from the side-car file.

Parameters
[in]idChromatogram index in [0, getNrChromatograms()). Out-of-range access is a programming error (checked in debug builds).
Returns
Decoded chromatogram.
Exceptions
Exception::ParseErrorwhen seekg on the side-car stream fails.

Implements ISpectrumAccess.

◆ getChromatogramMetaInfo()

ChromatogramSettings getChromatogramMetaInfo ( int  id) const

Return the ChromatogramSettings of one chromatogram.

Parameters
[in]idChromatogram index in [0, getNrChromatograms()). Out-of-range access is a programming error (checked in debug builds).
Returns
Copy of the stored ChromatogramSettings.

◆ getChromatogramNativeID()

std::string getChromatogramNativeID ( int  id) const
overridevirtual

Native id of one cached chromatogram.

Parameters
[in]idChromatogram index in [0, getNrChromatograms()). Out-of-range access is a programming error (checked in debug builds).
Returns
Native-id string from the stored metadata.

Implements ISpectrumAccess.

◆ getNrChromatograms()

size_t getNrChromatograms ( ) const
overridevirtual

Number of chromatograms in the loaded metadata.

Implements ISpectrumAccess.

◆ getNrSpectra()

size_t getNrSpectra ( ) const
overridevirtual

Number of spectra in the loaded metadata.

Implements ISpectrumAccess.

◆ getSpectraByRT()

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

Indices of cached spectra whose RT lies in [RT - deltaRT, RT + deltaRT].

Walks the metadata MSExperiment forward from the first spectrum with RT >= RT - deltaRT.

Parameters
[in]RTCentre of the RT window.
[in]deltaRTHalf-width of the RT window. Must be non-negative; a negative value is a programming error (checked in debug builds).
Returns
Indices into the in-memory metadata for spectra inside the window.

Implements ISpectrumAccess.

◆ getSpectraMetaInfo()

SpectrumSettings getSpectraMetaInfo ( int  id) const

Return the full SpectrumSettings of one spectrum.

Unlike getSpectrumMetaById (which returns only RT and ms_level), this returns the full per-spectrum metadata read at construction time.

Parameters
[in]idSpectrum index. No bounds check is performed.
Returns
Copy of the stored SpectrumSettings for that spectrum.

◆ getSpectrumById()

OpenSwath::SpectrumPtr getSpectrumById ( int  id)
overridevirtual

Read one spectrum from the side-car file.

Parameters
[in]idSpectrum index in [0, getNrSpectra()). Out-of-range access is a programming error (checked in debug builds).
Returns
Decoded spectrum.
Exceptions
Exception::ParseErrorwhen seekg on the side-car stream fails (e.g. an overflow on a 32-bit system reading a > 2 GB cache file).

Implements ISpectrumAccess.

◆ getSpectrumMetaById()

OpenSwath::SpectrumMeta getSpectrumMetaById ( int  id) const
overridevirtual

Return the RT and MS level of one spectrum.

Only RT and ms_level are filled on the returned SpectrumMeta; for the full spectrum settings use getSpectraMetaInfo.

Parameters
[in]idSpectrum index in [0, getNrSpectra()). Out-of-range access is a programming error (checked in debug builds).
Returns
SpectrumMeta carrying only RT and ms_level.

Implements ISpectrumAccess.

◆ lightClone()

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

Return a clone of this accessor as a new OpenSwath::ISpectrumAccess.

Equivalent to copy-constructing through SpectrumAccessOpenMSCached(const SpectrumAccessOpenMSCached&); the clone reads payloads lazily from its own stream on the same side-car file.

Returns
Shared pointer to the cloned accessor.

Implements ISpectrumAccess.