3.1. Main reader interface

The class Reader has been designed to selectively extract data from a mzML file and to expose the data as a python object. Necessary information are read in and stored in a fast accessible format. The reader itself is an iterator, thus looping over all spectra follows the classical pythonian syntax. Additionally one can random access spectra by their nativeID if the file if not truncated by a conversion Program.

Note

The class Writer is still in development.

class pymzml.run.Reader(path_or_file, MS_precisions=None, obo_version=None, build_index_from_scratch=False, skip_chromatogram=True, index_regex=None, **kwargs)[source]

Initialize Reader object for a given mzML file.

Parameters:

path (str) – path to the mzml file to parse.

Keyword Arguments:
  • MS_precisions (dict) –

    measured precisions for the different MS levels. e.g.:

    {
        1 : 5e-6,
        2 : 20e-6
    }
    

  • obo_version (str, optional) – obo version number as string. If not specified the version will be extracted from the mzML file

Note

Setting the precision for MS1 and MSn spectra has changed in version 1.2. However, the old syntax as kwargs is still compatible ( e.g. ‘MS1_Precision=5e-6’).

Attributes:
file_class

Return file object in use.

Methods

get_chromatogram_count()

Number of chromatograms in file.

get_spectrum_count()

Number of spectra in file.

next()

Function to return the next Spectrum element.

close

__getitem__(identifier)[source]

Access spectrum with native id ‘identifier’.

Parameters:

identifier (str or int) – last number in the id tag of the spectrum element

Returns:

spectrum/chromatogram object with native id ‘identifier’

Return type:

spectrum (Spectrum or Chromatogram)

property file_class

Return file object in use.

get_chromatogram_count()[source]

Number of chromatograms in file.

Returns:

Number of chromatograms in file.

Return type:

chromatogram count (int)

get_spectrum_count()[source]

Number of spectra in file.

Returns:

Number of spectra in file.

Return type:

spectrum count (int)

next()[source]

Function to return the next Spectrum element.