matchms.exporting package

Functions for exporting mass spectral data

Individual Spectrum(), or lists of Spectrum() can be exported to json, mgf, or msp files.

matchms.exporting.save_as_json(spectrums: List[matchms.Spectrum.Spectrum], filename: str)[source]

Save spectrum(s) as json file.

losses of spectrum will not be saved.

Example:

import numpy
from matchms import Spectrum
from matchms.exporting import save_as_json

# Create dummy spectrum
spectrum = Spectrum(mz=numpy.array([100, 200, 300], dtype="float"),
                    intensities=numpy.array([10, 10, 500], dtype="float"),
                    metadata={"charge": -1,
                              "inchi": '"InChI=1S/C6H12"',
                              "precursor_mz": 222.2})

# Write spectrum to test file
save_as_json(spectrum, "test.json")
Parameters
  • spectrums – Expected input is a list of Spectrum objects.

  • filename – Provide filename to save spectrum(s).

matchms.exporting.save_as_mgf(spectrums: List[matchms.Spectrum.Spectrum], filename: str)[source]

Save spectrum(s) as mgf file.

losses of spectrum will not be saved.

Example:

import numpy
from matchms import Spectrum
from matchms.exporting import save_as_mgf

# Create dummy spectrum
spectrum = Spectrum(mz=numpy.array([100, 200, 300], dtype="float"),
                    intensities=numpy.array([10, 10, 500], dtype="float"),
                    metadata={"charge": -1,
                              "inchi": '"InChI=1S/C6H12"',
                              "precursor_mz": 222.2})

# Write spectrum to test file
save_as_mgf(spectrum, "test.mgf")
Parameters
  • spectrums – Expected input are match.Spectrum.Spectrum() objects.

  • filename – Provide filename to save spectrum(s).

matchms.exporting.save_as_msp(spectra: List[matchms.Spectrum.Spectrum], filename: str, write_peak_comments: bool = True)[source]

Save spectrum(s) as msp file.

losses of spectrum will not be saved.

Example:

import numpy
from matchms import Spectrum
from matchms.exporting import save_as_msp

# Create dummy spectrum
spectrum = Spectrum(mz=numpy.array([100, 200, 300], dtype="float"),
                    intensities=numpy.array([10, 10, 500], dtype="float"),
                    metadata={"charge": -1,
                              "inchi": '"InChI=1S/C6H12"',
                              "precursor_mz": 222.2})

# Write spectrum to test file
save_as_msp(spectrum, "test.msp")
Parameters
  • spectra – Expected input are match.Spectrum.Spectrum() objects.

  • filename – Provide filename to save spectrum(s).

  • write_peak_comments – Writes peak comments to individual peaks after the respective mz/intensity pair when set to True. Default is True.