matchms.Metadata module
- class matchms.Metadata.Metadata(metadata: dict = None, matchms_key_style: bool = True)[source]
Bases:
objectClass 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: 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.
- harmonize_keys()[source]
Runs default harmonization of metadata.
Method harmonized metadata field names which include setting them to lower-case and running a series of regex replacements followed by the default field name replacements (such as precursor_mass –> precursor_mz).
- harmonize_values()[source]
Runs default harmonization of metadata.
This includes harmonizing entries for ionmode, retention time and index, charge, as well as the removal of invalid entries (“”, “NA”, “N/A”, “NaN”).
- static set_key_replacements(keys: dict)[source]
Set key replacements for metadata harmonization.
- Parameters:
keys – Dictionary with key replacements.