Pyteomics

raw JSON →
4.7.5 verified Mon Apr 27 auth: no python

Pyteomics is a Python framework for proteomics data analysis, providing parsers and tools for common mass spectrometry formats (mzML, mzXML, MGF, etc.) and sequence database handling. Current version 4.7.5 is stable with monthly releases.

pip install pyteomics
error ModuleNotFoundError: No module named 'pyteomics.mzml'
cause Wrong import path; pyteomics modules are lowercase with no leading underscore.
fix
Use 'from pyteomics import mzml' (not 'pyteomics.MzML' or 'pyteomics.mzML').
error TypeError: 'MzML' object is not callable
cause Using 'mzml.MzML()' as a function instead of as a context manager.
fix
Wrap in 'with mzml.MzML('file') as reader:'
breaking In version 4.x, the API for mzML reader changed from pyteomics.mzml.MzML to context manager with 'with' statement. Old code using mzml.MzML('file') may break if not wrapped in 'with'.
fix Use 'with mzml.MzML('file') as reader:' pattern.
deprecated The 'pyteomics.mzml.MzML' class is deprecated in favor of 'pyteomics.mzml.read' for iteration.
fix Use 'from pyteomics import mzml; for spec in mzml.read('file'):' instead.
gotcha Indexing spectra by scan number is not always sequential; use 'by_id' method rather than list index.
fix Use 'reader[('scan', scan_number)]' or 'reader.by_id(scan_number)' to access by scan ID.

Read an mzML file and print first 5 m/z values of each spectrum.

from pyteomics import mzml

with mzml.MzML('example.mzML') as reader:
    for spectrum in reader:
        print(spectrum['m/z array'][:5])