OpenMS  2.8.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
IndexedMzMLHandler Class Reference

A low-level class to read an indexedmzML file. More...

#include <OpenMS/FORMAT/HANDLERS/IndexedMzMLHandler.h>

Collaboration diagram for IndexedMzMLHandler:
[legend]

Public Member Functions

 IndexedMzMLHandler ()
 Default constructor. More...
 
 IndexedMzMLHandler (const String &filename)
 Constructor. More...
 
 IndexedMzMLHandler (const IndexedMzMLHandler &source)
 Copy constructor. More...
 
 ~IndexedMzMLHandler ()
 Destructor. More...
 
void openFile (const String &filename)
 Open a file. More...
 
bool getParsingSuccess () const
 Returns whether parsing was successful. More...
 
size_t getNrSpectra () const
 Returns the number of spectra available. More...
 
size_t getNrChromatograms () const
 Returns the number of chromatograms available. More...
 
OpenMS::Interfaces::SpectrumPtr getSpectrumById (int id)
 Retrieve the raw data for the spectrum at position "id". More...
 
const OpenMS::MSSpectrum getMSSpectrumById (int id)
 Retrieve the raw data for the spectrum at position "id". More...
 
void getMSSpectrumByNativeId (std::string id, OpenMS::MSSpectrum &s)
 Retrieve the raw data for the spectrum with native id "id". More...
 
void getMSSpectrumById (int id, OpenMS::MSSpectrum &s)
 Retrieve the raw data for the spectrum at position "id". More...
 
OpenMS::Interfaces::ChromatogramPtr getChromatogramById (int id)
 Retrieve the raw data for the chromatogram at position "id". More...
 
const OpenMS::MSChromatogram getMSChromatogramById (int id)
 Retrieve the raw data for the chromatogram at position "id". More...
 
void getMSChromatogramByNativeId (const std::string &id, OpenMS::MSChromatogram &c)
 Retrieve the raw data for the chromatogram with native id "id". More...
 
void getMSChromatogramById (int id, OpenMS::MSChromatogram &c)
 Retrieve the raw data for the chromatogram at position "id". More...
 
void setSkipXMLChecks (bool skip)
 Whether to skip some XML checks (removing whitespace from base64 arrays) and be fast instead. More...
 

Private Member Functions

void parseFooter_ ()
 Try to parse the footer of the indexedmzML. More...
 
std::string getChromatogramById_helper_ (int id)
 
std::string getSpectrumById_helper_ (int id)
 

Private Attributes

String filename_
 Name of the file. More...
 
std::vector< std::streampos > spectra_offsets_
 Binary offsets to all spectra. More...
 
std::unordered_map< std::string, Sizespectra_native_ids_
 Mapping of spectra native ids to offsets. More...
 
std::vector< std::streampos > chromatograms_offsets_
 Binary offsets to all chromatograms. More...
 
std::unordered_map< std::string, Sizechromatograms_native_ids_
 Mapping of chromatogram native ids to offsets. More...
 
std::streampos index_offset_
 offset to the <indexList> element More...
 
bool spectra_before_chroms_
 Whether spectra are written before chromatograms in this file. More...
 
std::ifstream filestream_
 The current filestream (opened by openFile) More...
 
bool parsing_success_
 Whether parsing the indexedmzML file was successful. More...
 
bool skip_xml_checks_
 Whether to skip XML checks. More...
 

Detailed Description

A low-level class to read an indexedmzML file.

This class provides low-level access to the underlying data structures, if you simply want to read an indexed mzML file you probably want to use IndexedMzMLFileLoader instead.

This class implements access to an indexedmzML file and the contained spectra and chromatogram data through the getSpectrumById and getChromatogramById functions. It thus allows random access to spectra and chromatograms data without having to read the whole file into memory. It does not provide the same interface as MSExperiment, if this is desired, please use IndexedMzMLFileLoader and OnDiscMSExperiment.

Internally, it uses the IndexedMzMLDecoder for initial parsing and extracting all the offsets of the <chromatogram> and <spectrum> tags. These offsets are stored as members of this class as well as the offset to the <indexList> element

Note
This implementation is not thread-safe since it keeps internally a single file access pointer which it moves when accessing a specific data item. The caller is responsible to ensure that access is performed atomically.

Constructor & Destructor Documentation

◆ IndexedMzMLHandler() [1/3]

Default constructor.

◆ IndexedMzMLHandler() [2/3]

IndexedMzMLHandler ( const String filename)
explicit

Constructor.

Tries to parse the file, success can be checked with getParsingSuccess()

◆ IndexedMzMLHandler() [3/3]

Copy constructor.

◆ ~IndexedMzMLHandler()

Destructor.

Member Function Documentation

◆ getChromatogramById()

OpenMS::Interfaces::ChromatogramPtr getChromatogramById ( int  id)

Retrieve the raw data for the chromatogram at position "id".

Exceptions
Exceptionif getParsingSuccess() returns false
Exceptionif id is not within [0, getNrChromatograms()-1]
Returns
The chromatogram at position id

◆ getChromatogramById_helper_()

std::string getChromatogramById_helper_ ( int  id)
private

◆ getMSChromatogramById() [1/2]

const OpenMS::MSChromatogram getMSChromatogramById ( int  id)

Retrieve the raw data for the chromatogram at position "id".

Exceptions
Exceptionif getParsingSuccess() returns false
Exceptionif id is not within [0, getNrChromatograms()-1]
Returns
The chromatogram at position id

◆ getMSChromatogramById() [2/2]

void getMSChromatogramById ( int  id,
OpenMS::MSChromatogram c 
)

Retrieve the raw data for the chromatogram at position "id".

Exceptions
Exceptionif getParsingSuccess() returns false
Exceptionif id is not within [0, getNrChromatograms()-1]
Parameters
idThe chromatogram id
cThe chromatogram to be used and filled with data

◆ getMSChromatogramByNativeId()

void getMSChromatogramByNativeId ( const std::string &  id,
OpenMS::MSChromatogram c 
)

Retrieve the raw data for the chromatogram with native id "id".

Exceptions
Exceptionif getParsingSuccess() returns false
Exceptionif id cannot be found
Parameters
idThe chromatogram native id
sThe chromatogram to be used and filled with data

◆ getMSSpectrumById() [1/2]

const OpenMS::MSSpectrum getMSSpectrumById ( int  id)

Retrieve the raw data for the spectrum at position "id".

Exceptions
Exceptionif getParsingSuccess() returns false
Exceptionif id is not within [0, getNrSpectra()-1]
Returns
The spectrum at position id

◆ getMSSpectrumById() [2/2]

void getMSSpectrumById ( int  id,
OpenMS::MSSpectrum s 
)

Retrieve the raw data for the spectrum at position "id".

Exceptions
Exceptionif getParsingSuccess() returns false
Exceptionif id is not within [0, getNrSpectra()-1]
Parameters
idThe spectrum id
sThe spectrum to be used and filled with data

◆ getMSSpectrumByNativeId()

void getMSSpectrumByNativeId ( std::string  id,
OpenMS::MSSpectrum s 
)

Retrieve the raw data for the spectrum with native id "id".

Exceptions
Exceptionif getParsingSuccess() returns false
Exceptionif id cannot be found
Parameters
idThe spectrum native id
sThe spectrum to be used and filled with data

◆ getNrChromatograms()

size_t getNrChromatograms ( ) const

Returns the number of chromatograms available.

Referenced by TOPPViewBase::addDataFile().

◆ getNrSpectra()

size_t getNrSpectra ( ) const

Returns the number of spectra available.

Referenced by TOPPViewBase::addDataFile().

◆ getParsingSuccess()

bool getParsingSuccess ( ) const

Returns whether parsing was successful.

Note
Callable after openFile or the constructor using a filename
It is invalid to call getSpectrumById or getChromatogramById if this function returns false
Returns
Whether the parsing of the file was successful (if false, the file most likely was not an indexed mzML file)

Referenced by TOPPViewBase::addDataFile().

◆ getSpectrumById()

OpenMS::Interfaces::SpectrumPtr getSpectrumById ( int  id)

Retrieve the raw data for the spectrum at position "id".

Exceptions
Exceptionif getParsingSuccess() returns false
Exceptionif id is not within [0, getNrSpectra()-1]
Returns
The spectrum at position id

◆ getSpectrumById_helper_()

std::string getSpectrumById_helper_ ( int  id)
private

◆ openFile()

void openFile ( const String filename)

Open a file.

Tries to parse the file, success can be checked with getParsingSuccess()

Referenced by TOPPViewBase::addDataFile().

◆ parseFooter_()

void parseFooter_ ( )
private

Try to parse the footer of the indexedmzML.

Upon success, the chromatogram and spectra offsets will be populated and parsing_success_ will be set to true.

Note
You *need* to check getParsingSuccess after calling this!

◆ setSkipXMLChecks()

void setSkipXMLChecks ( bool  skip)
inline

Whether to skip some XML checks (removing whitespace from base64 arrays) and be fast instead.

Member Data Documentation

◆ chromatograms_native_ids_

std::unordered_map< std::string, Size > chromatograms_native_ids_
private

Mapping of chromatogram native ids to offsets.

◆ chromatograms_offsets_

std::vector< std::streampos > chromatograms_offsets_
private

Binary offsets to all chromatograms.

◆ filename_

String filename_
private

Name of the file.

◆ filestream_

std::ifstream filestream_
private

The current filestream (opened by openFile)

◆ index_offset_

std::streampos index_offset_
private

offset to the <indexList> element

◆ parsing_success_

bool parsing_success_
private

Whether parsing the indexedmzML file was successful.

◆ skip_xml_checks_

bool skip_xml_checks_
private

Whether to skip XML checks.

◆ spectra_before_chroms_

bool spectra_before_chroms_
private

Whether spectra are written before chromatograms in this file.

◆ spectra_native_ids_

std::unordered_map< std::string, Size > spectra_native_ids_
private

Mapping of spectra native ids to offsets.

◆ spectra_offsets_

std::vector< std::streampos > spectra_offsets_
private

Binary offsets to all spectra.