matchms.importing.load_from_mgf module

matchms.importing.load_from_mgf.load_from_mgf(source: Union[str, TextIO], metadata_harmonization: bool = True) Generator[matchms.Spectrum.Spectrum, None, None][source]

Load spectrum(s) from mgf file.

This function will create ~matchms.Spectrum for every spectrum in the given .mgf file (or the file-like object).

Examples:

from matchms.importing import load_from_mgf

file_mgf = "pesticides.mgf"
spectra_from_path = list(load_from_mgf(file_mgf))

# Or you can read the file in your application
with open(file_mgf, 'r') as spectra_file:
    spectra_from_file = list(load_from_mgf(spectra_file))
Parameters
  • source – Accepts both filename (with path) for .mgf file or a file-like object from a preloaded MGF file.

  • metadata_harmonization (bool, optional) – Set to False if metadata harmonization to default keys is not desired. The default is True.