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

Random-access, on-disc reader for imzML mass spectrometry imaging datasets. More...

#include <OpenMS/KERNEL/OnDiscImzMLExperiment.h>

Collaboration diagram for OnDiscImzMLExperiment:
[legend]

Public Member Functions

 OnDiscImzMLExperiment ()
 
 ~OnDiscImzMLExperiment ()
 
 OnDiscImzMLExperiment (const OnDiscImzMLExperiment &)=delete
 
OnDiscImzMLExperimentoperator= (const OnDiscImzMLExperiment &)=delete
 
 OnDiscImzMLExperiment (OnDiscImzMLExperiment &&)
 
OnDiscImzMLExperimentoperator= (OnDiscImzMLExperiment &&)
 
void open (const std::string &imzml_path, const std::string &ibd_path="")
 Open an imzML dataset: parse the XML index, build the imaging geometry, and open the .ibd.
 
void close () noexcept
 Close the companion .ibd file and release on-disc resources.
 
bool isOpen () const noexcept
 
std::size_t getNrSpectra () const noexcept
 
std::size_t size () const noexcept
 
const ImzMLSpectrumIndexgetIndex (std::size_t i) const
 Return the index entry for spectrum i.
 
MSSpectrum getSpectrum (std::size_t i) const
 Decode and return spectrum i from the .ibd file.
 
MSSpectrum operator[] (std::size_t i) const
 Sugar for getSpectrum(i).
 
MSSpectrum getSpectrumAtCoord (uint32_t x, uint32_t y, uint32_t z=1) const
 Return the spectrum at imzML pixel coordinate (x, y[, z]).
 
const ImzMLMetagetImzMLMeta () const noexcept
 Returns imaging metadata parsed during open() — no IBD reads.
 
const MSImagingGeometrygetGeometry () const
 The standard 2D imaging geometry (pixel grid + (x,y)->spectrum map).
 
uint32_t gridWidth () const noexcept
 Shorthand for getImzMLMeta().max_count_x.
 
uint32_t gridHeight () const noexcept
 Shorthand for getImzMLMeta().max_count_y.
 

Private Attributes

std::unique_ptr< Impl > pimpl_
 

Detailed Description

Random-access, on-disc reader for imzML mass spectrometry imaging datasets.

Analogous to OnDiscMSExperiment for indexed mzML files, but designed specifically for imzML's two-file layout (.imzML + .ibd).

Workflow:

exp.open("tissue.imzML"); // parse XML index only — no peak I/O
std::cout << exp.getNrSpectra(); // instant, no IBD peak reads
const auto& meta = exp.getImzMLMeta();
MSSpectrum s = exp.getSpectrum(42); // one fseek + fread per array
MSSpectrum s = exp.getSpectrumAtCoord(3, 7); // pixel lookup (1-based coords)
const ImzMLSpectrumIndex& e = exp.getIndex(42); // IBD offsets, no read
The representation of a 1D spectrum.
Definition MSSpectrum.h:44
Random-access, on-disc reader for imzML mass spectrometry imaging datasets.
Definition OnDiscImzMLExperiment.h:60
const ImzMLSpectrumIndex & getIndex(std::size_t i) const
Return the index entry for spectrum i.
MSSpectrum getSpectrumAtCoord(uint32_t x, uint32_t y, uint32_t z=1) const
Return the spectrum at imzML pixel coordinate (x, y[, z]).
const ImzMLMeta & getImzMLMeta() const noexcept
Returns imaging metadata parsed during open() — no IBD reads.
MSSpectrum getSpectrum(std::size_t i) const
Decode and return spectrum i from the .ibd file.
std::size_t getNrSpectra() const noexcept
void open(const std::string &imzml_path, const std::string &ibd_path="")
Open an imzML dataset: parse the XML index, build the imaging geometry, and open the ....
Per-spectrum binary index entry for an imzML dataset.
Definition ImzMLHandlerHelper.h:95

Design. The PIMPL idiom hides all implementation details (IBD FILE*, index vector, coordinate map) so that this header has no dependency on expat, Xerces, or the native imzml:: parser library. The index is built by running ImzMLFile::loadSpectraIndex() during open() — no peak arrays are decoded until getSpectrum() is called.

Note
This class is not thread-safe. If concurrent reads are needed, construct one instance per thread.
See also
ImzMLFile, ImzMLMeta, ImzMLSpectrumIndex, OnDiscMSExperiment

Constructor & Destructor Documentation

◆ OnDiscImzMLExperiment() [1/3]

◆ ~OnDiscImzMLExperiment()

◆ OnDiscImzMLExperiment() [2/3]

◆ OnDiscImzMLExperiment() [3/3]

Member Function Documentation

◆ close()

void close ( )
noexcept

Close the companion .ibd file and release on-disc resources.

After close(), isOpen() returns false and spectrum decode calls fail until open() is invoked again.

◆ getGeometry()

const MSImagingGeometry & getGeometry ( ) const

The standard 2D imaging geometry (pixel grid + (x,y)->spectrum map).

Returns the shared MSImagingGeometry abstraction (the same type populated by ImzMLFile::load(filename, MSImagingExperiment&)), so on-disc and in-memory access expose pixel coordinates the same way. Coordinates are 0-based; imzML's 1-based coordinates are normalized here, and only the z == 1 plane is represented. Built during open() from the parsed index (no IBD reads); this is a const, O(1) accessor (any duplicate/invalid-coordinate error already surfaced at open()).

◆ getImzMLMeta()

const ImzMLMeta & getImzMLMeta ( ) const
noexcept

Returns imaging metadata parsed during open() — no IBD reads.

◆ getIndex()

const ImzMLSpectrumIndex & getIndex ( std::size_t  i) const

Return the index entry for spectrum i.

Contains pixel coordinates and byte offsets — no IBD read performed.

Parameters
i0-based spectrum index.
Exceptions
Exception::IndexOverflowif i >= getNrSpectra().

◆ getNrSpectra()

std::size_t getNrSpectra ( ) const
noexcept

◆ getSpectrum()

MSSpectrum getSpectrum ( std::size_t  i) const

Decode and return spectrum i from the .ibd file.

The returned MSSpectrum contains peak arrays decoded from the .ibd file and pixel coordinates as MetaValues (imzml:x, imzml:y, imzml:z). mzML scan metadata (RT, MS level, etc.) is not loaded in on-disc mode.

Parameters
i0-based spectrum index.
Exceptions
Exception::IndexOverflowif i >= getNrSpectra().
Exception::FileNotFoundif the .ibd is not open.

◆ getSpectrumAtCoord()

MSSpectrum getSpectrumAtCoord ( uint32_t  x,
uint32_t  y,
uint32_t  z = 1 
) const

Return the spectrum at imzML pixel coordinate (x, y[, z]).

Coordinates are imzML-native 1-based, matching ImzMLSpectrumIndex::x/y/z. The lookup is served by the shared MSImagingGeometry (see getGeometry()), which is 0-based and 2-dimensional; this method converts (x, y) to 0-based and only the z == 1 plane is addressable (consistent with the in-memory ImzMLFile loader, which likewise builds a 2D geometry). The geometry is built once during open(), so this is an O(1) lookup plus one peak-decode read.

Parameters
xPixel column (1-based).
yPixel row (1-based).
zDepth slice (1-based, default 1; only z == 1 is supported).
Exceptions
Exception::ElementNotFoundif no spectrum exists at (x, y, z).

◆ gridHeight()

uint32_t gridHeight ( ) const
noexcept

Shorthand for getImzMLMeta().max_count_y.

◆ gridWidth()

uint32_t gridWidth ( ) const
noexcept

Shorthand for getImzMLMeta().max_count_x.

◆ isOpen()

bool isOpen ( ) const
noexcept

◆ open()

void open ( const std::string &  imzml_path,
const std::string &  ibd_path = "" 
)

Open an imzML dataset: parse the XML index, build the imaging geometry, and open the .ibd.

The .ibd path is inferred from imzml_path unless ibd_path is provided explicitly. No peak data is read — peak arrays are decoded lazily per getSpectrum() call. The 2D pixel geometry (see getGeometry()) is built eagerly here from the parsed index (an in-memory pass, no .ibd reads), so a structurally broken coordinate grid is rejected at open() rather than later.

A UUID-header mismatch between the .ibd and the XML's IMS:1000080, an out-of-grid pixel, or a <1 coordinate are reported as warnings (the dataset still loads); only duplicate pixel coordinates are a hard error.

Parameters
imzml_pathPath to the .imzML file.
ibd_pathOptional override for the .ibd path.
Exceptions
Exception::FileNotFoundif either file cannot be opened.
Exception::ParseErroron malformed XML.
Exception::InvalidValueif the dataset has duplicate pixel coordinates.

◆ operator=() [1/2]

OnDiscImzMLExperiment & operator= ( const OnDiscImzMLExperiment )
delete

◆ operator=() [2/2]

◆ operator[]()

MSSpectrum operator[] ( std::size_t  i) const
inline

Sugar for getSpectrum(i).

◆ size()

std::size_t size ( ) const
inlinenoexcept

Member Data Documentation

◆ pimpl_

std::unique_ptr<Impl> pimpl_
private