matchms.Metadata module

class matchms.Metadata.Metadata(metadata: Optional[dict] = None, matchms_key_style: bool = True)[source]

Bases: object

Class to handle spectrum metadata in matchms.

Metadata entries will be stored as PickyDict dictionary in metadata.data. Unlike normal Python dictionaries, not all key names will be accepted. Key names will be forced to be lower-case to avoid confusions between key such as “Precursor_MZ” and “precursor_mz”.

To avoid the default harmonization of the metadata dictionary use the option matchms_key_style=False.

Code example:

metadata = Metadata({"Precursor_MZ": 201.5, "Compound Name": "SuperStuff"})
print(metadata["precursor_mz"])  # => 201.5
print(metadata["compound_name"])  # => SuperStuff

Or if the matchms default metadata harmonization should not take place:

metadata = Metadata({"Precursor_MZ": 201.5, "Compound Name": "SuperStuff"},
                    matchms_key_style=False)
print(metadata["precursor_mz"])  # => 201.5
print(metadata["compound_name"])  # => None (now you need to use "compound name")
__init__(metadata: Optional[dict] = None, matchms_key_style: bool = True)[source]
Parameters
  • metadata – Spectrum metadata as a dictionary.

  • matchms_key_style – Set to False if metadata harmonization to default keys is not desired. The default is True.

get(key: str, default=None)[source]

Retrieve value from metadata dict.

harmonize_metadata()[source]

Runs default harmonization of metadata.

Method harmonized metadata field names which includes setting them to lower-case and runing a series of regex replacements followed by default field name replacements (such as precursor_mass –> precursor_mz).

items()[source]

Retrieve all items (key, value pairs) of metadata dict.

keys()[source]

Retrieve all keys of metadata dict.

set(key: str, value)[source]

Set value in metadata dict.

values()[source]

Retrieve all values of metadata dict.