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(identifier)

Access chromatogram with the given identifier.

get_chromatogram_count()

Number of chromatograms in file.

get_spectrum(identifier)

Access spectrum with the given identifier.

get_spectrum_count()

Number of spectra in file.

next()

Function to return the next Spectrum element.

term_is_a_member(tested_term, member_of_term)

Use translated obo file to check if given term is_a member of the

close

__getitem__(identifier)[source]

Access spectrum or chromatogram with native id ‘identifier’.

Parameters:

identifier (str or int) – last number in the id tag of the spectrum element or a chromatogram identifier like ‘TIC’

Returns:

spectrum/chromatogram object with native id ‘identifier’

Return type:

spectrum (Spectrum or Chromatogram)

property file_class

Return file object in use.

get_chromatogram(identifier)[source]

Access chromatogram with the given identifier.

Parameters:

identifier (str or int) – Either a string identifier like ‘TIC’ or an index (0-based) to access chromatograms in order.

Returns:

chromatogram object with the given identifier

Return type:

chromatogram (Chromatogram)

Note

This method is only useful when skip_chromatogram is set to False if you want to access chromatograms by index. If skip_chromatogram is True, you can still access chromatograms by string identifiers (e.g., ‘TIC’).

get_chromatogram_count()[source]

Number of chromatograms in file.

Returns:

Number of chromatograms in file.

Return type:

chromatogram count (int)

get_spectrum(identifier)[source]

Access spectrum with the given identifier.

Parameters:

identifier (str or int) – Either a string identifier or an index (0-based) to access spectra in order.

Returns:

spectrum object with the given identifier

Return type:

spectrum (Spectrum)

Note

This method provides the same functionality as using the indexing syntax (e.g., run[0]), but with a more explicit method name.

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.

term_is_a_member(tested_term, member_of_term)[source]

Use translated obo file to check if given term is_a member of the

Returns:

is_member (bool) whether given term is a member of member_of_term