# 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, MS_precisions=None, obo_version=None, **kwargs)

  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’).

  `__getitem__`(identifier)

    Access spectrum with native id ‘identifier’.

    Parameters: | identifier (str or int) – last number in the id tag of the spectrum element
    Returns: | spectrum – spectrum/chromatogram object with native id ‘identifier’
    Return type: | Spectrum or Chromatogram

  `file_class`

    Return file object in use.

  `get_chromatogram_count`()

    Number of chromatograms in file.

    Returns: | chromatogram count – Number of chromatograms in file.
    Return type: | int

  `get_spectrum_count`()

    Number of spectra in file.

    Returns: | spectrum count – Number of spectra in file.
    Return type: | int

  `next`()

    Function to return the next Spectrum element.