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

File adapter for MzML files. More...

#include <OpenMS/FORMAT/MzMLFile.h>

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

Classes

struct  SpecInfo
 

Public Member Functions

 MzMLFile ()
 Default constructor.
 
 ~MzMLFile () override
 Destructor.
 
PeakFileOptionsgetOptions ()
 Mutable access to the options for loading/storing.
 
const PeakFileOptionsgetOptions () const
 Non-mutable access to the options for loading/storing.
 
void setOptions (const PeakFileOptions &)
 set options for loading/storing
 
void load (const std::string &filename, PeakMap &map)
 Loads a map from a MzML file. Spectra and chromatograms are sorted by default (this can be disabled using PeakFileOptions).
 
void loadBuffer (const std::string &buffer, PeakMap &map)
 Loads a map from a MzML file stored in a buffer (in memory).
 
void loadSize (const std::string &filename, Size &scount, Size &ccount)
 Only count the number of spectra and chromatograms from a file.
 
void store (const std::string &filename, const PeakMap &map) const
 Stores a map in an MzML file.
 
void storeBuffer (std::string &output, const PeakMap &map) const
 Stores a map in an output string.
 
void transform (const std::string &filename_in, Interfaces::IMSDataConsumer *consumer, bool skip_full_count=false, bool skip_first_pass=false)
 Transforms a map while loading using the supplied MSDataConsumer.
 
void transform (const std::string &filename_in, Interfaces::IMSDataConsumer *consumer, PeakMap &map, bool skip_full_count=false, bool skip_first_pass=false)
 Transforms a map while loading using the supplied MSDataConsumer.
 
bool isValid (const std::string &filename, std::ostream &os=std::cerr)
 Checks if a file validates against the XML schema.
 
bool isSemanticallyValid (const std::string &filename, StringList &errors, StringList &warnings)
 Checks if a file is valid with respect to the mapping file and the controlled vocabulary.
 
bool hasIndex (const std::string &filename)
 Checks if a file is an indexed MzML file or not.
 
std::map< UInt, SpecInfogetCentroidInfo (const std::string &filename, const Size first_n_spectra_only=10)
 Check type of spectra based on their metadata (if available) or by inspecting the peaks itself.
 
- Public Member Functions inherited from XMLFile
 XMLFile ()
 Construct an XMLFile without schema info; schema_location_ remains unset, so isValid cannot be used until derived-class logic initializes schema_location_ before calling isValid.
 
 XMLFile (const std::string &schema_location, const std::string &version)
 Construct with a schema location for later isValid calls.
 
virtual ~XMLFile ()
 Virtual destructor — defaulted; allows safe deletion through a base-class pointer.
 
bool isValid (const std::string &filename, std::ostream &os)
 Check if filename validates against the bound XML schema.
 
const std::string & getVersion () const
 Return the schema version string passed to the parameterised constructor; empty for default-constructed instances.
 
- Public Member Functions inherited from ProgressLogger
 ProgressLogger ()
 Constructor.
 
virtual ~ProgressLogger ()
 Destructor.
 
 ProgressLogger (const ProgressLogger &other)
 Copy constructor.
 
ProgressLoggeroperator= (const ProgressLogger &other)
 Assignment Operator.
 
void setLogType (LogType type) const
 Sets the progress log that should be used. The default type is NONE!
 
LogType getLogType () const
 Returns the type of progress log being used.
 
void setLogger (ProgressLoggerImpl *logger)
 Sets the logger to be used for progress logging.
 
void startProgress (SignedSize begin, SignedSize end, const std::string &label) const
 Initializes the progress display.
 
void setProgress (SignedSize value) const
 Sets the current progress.
 
void endProgress (UInt64 bytes_processed=0) const
 
void nextProgress () const
 increment progress by 1 (according to range begin-end)
 

Protected Member Functions

void transformFirstPass_ (const std::string &filename_in, Interfaces::IMSDataConsumer *consumer, bool skip_full_count)
 Perform first pass through the file and retrieve the meta-data to initialize the consumer.
 
void safeParse_ (const std::string &filename, Internal::XMLHandler *handler)
 Safe parse that catches exceptions and handles them accordingly.
 
- Protected Member Functions inherited from XMLFile
void parse_ (const std::string &filename, XMLHandler *handler)
 Parse the XML file at filename through handler.
 
void parseBuffer_ (const std::string &buffer, XMLHandler *handler)
 Parse an in-memory XML buffer through handler.
 
void save_ (const std::string &filename, XMLHandler *handler) const
 Stores the contents of the XML handler given by handler in the file given by filename.
 
void enforceEncoding_ (const std::string &encoding)
 Set or clear the XML-encoding override applied to subsequent parse_ / parseBuffer_ calls.
 

Private Attributes

PeakFileOptions options_
 Options for loading / storing.
 
std::string indexed_schema_location_
 Location of indexed mzML schema.
 

Additional Inherited Members

- Public Types inherited from ProgressLogger
enum  LogType { CMD , GUI , NONE }
 Possible log types. More...
 
- Protected Attributes inherited from XMLFile
std::string schema_location_
 Path of the XML schema for validation; empty when the default constructor was used (isValid then throws NotImplemented).
 
std::string schema_version_
 Schema version string returned by getVersion.
 
std::string enforced_encoding_
 Optional XML encoding override applied to the InputSource in parse_ and parseBuffer_; empty disables the override. Used as a workaround for XTandem output XML which carries an encoding the parser otherwise stumbles on.
 
- Protected Attributes inherited from ProgressLogger
LogType type_
 
time_t last_invoke_
 
ProgressLoggerImplcurrent_logger_
 
- Static Protected Attributes inherited from ProgressLogger
static int recursion_depth_
 

Detailed Description

File adapter for MzML files.

This implementation does currently not support the whole functionality of MzML.


Class Documentation

◆ OpenMS::MzMLFile::SpecInfo

struct OpenMS::MzMLFile::SpecInfo
Collaboration diagram for MzMLFile::SpecInfo:
[legend]
Class Members
Size count_centroided = 0
Size count_profile = 0
Size count_unknown = 0

Constructor & Destructor Documentation

◆ MzMLFile()

MzMLFile ( )

Default constructor.

◆ ~MzMLFile()

~MzMLFile ( )
override

Destructor.

Member Function Documentation

◆ getCentroidInfo()

std::map< UInt, SpecInfo > getCentroidInfo ( const std::string &  filename,
const Size  first_n_spectra_only = 10 
)

Check type of spectra based on their metadata (if available) or by inspecting the peaks itself.

By default, only the first first_n_spectra_only, which are NOT 'unknown' are checked to save time. The current PeakFileOptions, e.g. which MS-level to read/skip, are honored, e.g. skipped spectra do not count towards first_n_spectra_only.

You can use this function to estimate the spectrum type, but it should be done for each MS-level separately. Otherwise you might get mixed (PROFILE+CENTROIDED) results.

Parameters
[in]filenameFile name of the mzML file to be checked
[in]first_n_spectra_onlyOnly inspect this many spectra (UNKNOWN spectra do not count) and then end parsing the file
Returns
Map of MS level to counts (centroided, profile, unknown)
Exceptions
Exception::FileNotFoundis thrown if the file could not be opened

◆ getOptions() [1/2]

PeakFileOptions & getOptions ( )

Mutable access to the options for loading/storing.

Referenced by NuXLRTPrediction::train().

◆ getOptions() [2/2]

const PeakFileOptions & getOptions ( ) const

Non-mutable access to the options for loading/storing.

◆ hasIndex()

bool hasIndex ( const std::string &  filename)

Checks if a file is an indexed MzML file or not.

Parameters
[in]filenameFile name of the file to be checked.
Exceptions
Exception::FileNotFoundis thrown if the file could not be opened

◆ isSemanticallyValid()

bool isSemanticallyValid ( const std::string &  filename,
StringList errors,
StringList warnings 
)

Checks if a file is valid with respect to the mapping file and the controlled vocabulary.

Parameters
[in]filenameFile name of the file to be checked.
[out]errorsErrors during the validation are returned in this output parameter.
[out]warningsWarnings during the validation are returned in this output parameter.
Exceptions
Exception::FileNotFoundis thrown if the file could not be opened

◆ isValid()

bool isValid ( const std::string &  filename,
std::ostream &  os = std::cerr 
)

Checks if a file validates against the XML schema.

Exceptions
Exception::FileNotFoundis thrown if the file cannot be found.

◆ load()

void load ( const std::string &  filename,
PeakMap map 
)

Loads a map from a MzML file. Spectra and chromatograms are sorted by default (this can be disabled using PeakFileOptions).

Parameters
[in]filenameThe filename with the data
[out]mapIs an MSExperiment
Exceptions
Exception::FileNotFoundis thrown if the file could not be opened
Exception::ParseErroris thrown if an error occurs during parsing

Referenced by NuXLRTPrediction::train().

◆ loadBuffer()

void loadBuffer ( const std::string &  buffer,
PeakMap map 
)

Loads a map from a MzML file stored in a buffer (in memory).

Parameters
[in]bufferThe buffer with the data (i.e. string with content of an mzML file)
[out]mapIs an MSExperiment
Exceptions
Exception::ParseErroris thrown if an error occurs during parsing

◆ loadSize()

void loadSize ( const std::string &  filename,
Size scount,
Size ccount 
)

Only count the number of spectra and chromatograms from a file.

This method honors PeakOptions (if specified) for spectra, i.e. only spectra within the specified RT range and MS levels are counted. If PeakOptions have no filters set (the default), then spectra and chromatogram counts are taken from the counts attribute of the spectrumList/chromatogramList tags (the parsing skips all intermediate data and ends as soon as both counts are available).

◆ safeParse_()

void safeParse_ ( const std::string &  filename,
Internal::XMLHandler handler 
)
protected

Safe parse that catches exceptions and handles them accordingly.

◆ setOptions()

void setOptions ( const PeakFileOptions )

set options for loading/storing

◆ store()

void store ( const std::string &  filename,
const PeakMap map 
) const

Stores a map in an MzML file.

map has to be an MSExperiment or have the same interface.

Exceptions
Exception::UnableToCreateFileis thrown if the file could not be created

◆ storeBuffer()

void storeBuffer ( std::string &  output,
const PeakMap map 
) const

Stores a map in an output string.

output An empty string to store the result map has to be an MSExperiment

◆ transform() [1/2]

void transform ( const std::string &  filename_in,
Interfaces::IMSDataConsumer consumer,
bool  skip_full_count = false,
bool  skip_first_pass = false 
)

Transforms a map while loading using the supplied MSDataConsumer.

The result will not be stored directly but is available through the events triggered by the parser and caught by the provided IMSDataConsumer object.

This function should be used if processing and storage of the result can be performed directly in the provided IMSDataConsumer object.

Note
Transformation can be speed up by setting skip_full_count which does not require a full first pass through the file to compute the correct number of spectra and chromatograms in the input file.
Parameters
[in]filename_inFilename of input mzML file to transform
[in]consumerConsumer class to operate on the input filename (implementing a transformation)
[in]skip_full_countWhether to skip computing the correct number of spectra and chromatograms in the input file
[in]skip_first_passSkip first file parsing pass, which hands only meta-data (number of spectra/chroms and experimental settings) to the consumer

◆ transform() [2/2]

void transform ( const std::string &  filename_in,
Interfaces::IMSDataConsumer consumer,
PeakMap map,
bool  skip_full_count = false,
bool  skip_first_pass = false 
)

Transforms a map while loading using the supplied MSDataConsumer.

The result will be stored in the provided map.

This function should be used if a specific pre-processing should be applied to the data before storing them in a map (e.g. if data-reduction should be applied to the data before loading all data into memory).

Parameters
[in]filename_inFilename of input mzML file to transform
[in]consumerConsumer class to operate on the input filename (implementing a transformation)
[in]mapMap to store the resulting spectra and chromatograms
[in]skip_full_countWhether to skip computing the correct number of spectra and chromatograms in the input file
[in]skip_first_passSkip first file parsing pass, which hands only meta-data (number of spectra/chroms and experimental settings) to the consumer

◆ transformFirstPass_()

void transformFirstPass_ ( const std::string &  filename_in,
Interfaces::IMSDataConsumer consumer,
bool  skip_full_count 
)
protected

Perform first pass through the file and retrieve the meta-data to initialize the consumer.

Member Data Documentation

◆ indexed_schema_location_

std::string indexed_schema_location_
private

Location of indexed mzML schema.

◆ options_

PeakFileOptions options_
private

Options for loading / storing.