Mercurial > repos > recetox > matchms_split
diff matchms_filtering_wrapper.py @ 13:fc1bc38ede0b draft
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b797ce0fea5cb3d9a0cf0ec31a21f9b73f112b4e
author | recetox |
---|---|
date | Mon, 15 Jan 2024 12:28:02 +0000 |
parents | eba733715eaf |
children | 072c7a101da6 |
line wrap: on
line diff
--- a/matchms_filtering_wrapper.py Thu Dec 14 13:44:53 2023 +0000 +++ b/matchms_filtering_wrapper.py Mon Jan 15 12:28:02 2024 +0000 @@ -7,11 +7,13 @@ from matchms.filtering import default_filters, normalize_intensities, reduce_to_number_of_peaks, select_by_mz, \ select_by_relative_intensity from matchms.filtering.filter_utils.derive_precursor_mz_and_parent_mass import derive_precursor_mz_from_parent_mass +from matchms.filtering.filter_utils.smile_inchi_inchikey_conversions import is_valid_inchi, is_valid_smiles from matchms.importing import load_from_mgf, load_from_msp -def require_key(spectrum, key): - if spectrum.get(key): +def require_key(spectrum, key, function): + value = spectrum.get(key) + if function(value): return spectrum return None @@ -95,10 +97,10 @@ spectrum.set("precursor_mz", precursor_mz) if args.require_smiles and spectrum is not None: - spectrum = require_key(spectrum, "smiles") + spectrum = require_key(spectrum, "smiles", is_valid_smiles) if args.require_inchi and spectrum is not None: - spectrum = require_key(spectrum, "inchi") + spectrum = require_key(spectrum, "inchi", is_valid_inchi) if spectrum is not None: filtered_spectra.append(spectrum)