matchms.importing.load_spectra module

matchms.importing.load_spectra.load_list_of_spectrum_files(spectrum_files: list[str] | str) list[Spectrum] | Iterator[Spectrum][source]

Combines all spectra in multiple files into a list of spectra

matchms.importing.load_spectra.load_ms2_dataset(file: str, metadata_harmonization: bool = True, ftype: str = 'auto', **kwargs) SpectraCollection[source]

Load spectra from a file as a SpectraCollection.

Parameters:
  • file – Path to file containing spectra.

  • metadata_harmonization – If True, harmonize metadata during import.

  • ftype – File type to use for import. By default, "auto" guesses the file type from the file extension. Alternatively, pass an explicit file type, for example "mzml", "json", "mgf", "msp", "mzxml", or "pickle".

  • **kwargs – Additional keyword arguments to pass to the SpectraCollection constructor, for example mz_precision.

Returns:

Imported spectra as a collection.

Return type:

SpectraCollection

matchms.importing.load_spectra.load_spectra(file: str, metadata_harmonization: bool = True, ftype: str | None = 'auto') list[Spectrum] | Generator[Spectrum, None, None][source]

Load spectra from a file as matchms Spectrum objects.

The following file extensions can be loaded with this function: mzML, json, mgf, msp, mzxml and pickle.

A pickled file is expected to directly contain a list of matchms Spectrum objects.

Parameters:
  • file – Path to file containing spectra.

  • metadata_harmonization – If True, harmonize metadata during import.

  • ftype – File type to use for import. By default, "auto" guesses the file type from the file extension. Alternatively, pass an explicit file type, for example "mzml", "json", "mgf", "msp", "mzxml", or "pickle".

Returns:

Imported spectra.

Return type:

list[Spectrum] or Generator[Spectrum, None, None]