Mercurial > repos > recetox > matchms_split
diff matchms_filtering_wrapper.py @ 19:072c7a101da6 draft
planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit 113433b8b9790405c2c5d054aee4a29a21b77dc7
author | recetox |
---|---|
date | Thu, 30 May 2024 18:11:23 +0000 |
parents | fc1bc38ede0b |
children | 500f473df7e4 |
line wrap: on
line diff
--- a/matchms_filtering_wrapper.py Mon Apr 22 08:35:30 2024 +0000 +++ b/matchms_filtering_wrapper.py Thu May 30 18:11:23 2024 +0000 @@ -2,23 +2,14 @@ import sys from matchms.exporting import save_as_mgf, save_as_msp -from matchms.filtering import add_compound_name, add_fingerprint, add_losses, add_parent_mass, add_precursor_mz,\ +from matchms.filtering import add_compound_name, add_fingerprint, add_losses, add_parent_mass, add_precursor_mz, \ add_retention_index, add_retention_time, clean_compound_name 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, function): - value = spectrum.get(key) - if function(value): - return spectrum - - return None - - def main(argv): parser = argparse.ArgumentParser(description="Compute MSP similarity scores") parser.add_argument("--spectra", type=str, required=True, help="Mass spectra file to be filtered.") @@ -38,10 +29,6 @@ help="Keep only peaks between set m/z range (keep if to_mz >= m/z >= from_mz).") parser.add_argument("--from_mz", type=float, help="Lower bound for m/z filter") parser.add_argument("--to_mz", type=float, help="Upper bound for m/z filter") - parser.add_argument("-require_smiles", action='store_true', - help="Remove spectra that does not contain SMILES.") - parser.add_argument("-require_inchi", action='store_true', - help="Remove spectra that does not contain INCHI.") parser.add_argument("-derive_precursor_mz_from_parent_mass", action='store_true', help="Derives the precursor_mz from the parent mass and adduct or charge.") parser.add_argument("--estimate_from_adduct", type=str, help="estimate from adduct.") @@ -55,8 +42,6 @@ or args.clean_metadata or args.relative_intensity or args.mz_range - or args.require_smiles - or args.require_inchi or args.derive_precursor_mz_from_parent_mass or args.reduce_to_top_n_peaks): raise ValueError('No filter selected.') @@ -96,12 +81,6 @@ precursor_mz = derive_precursor_mz_from_parent_mass(spectrum, args.estimate_from_adduct) spectrum.set("precursor_mz", precursor_mz) - if args.require_smiles and spectrum is not None: - spectrum = require_key(spectrum, "smiles", is_valid_smiles) - - if args.require_inchi and spectrum is not None: - spectrum = require_key(spectrum, "inchi", is_valid_inchi) - if spectrum is not None: filtered_spectra.append(spectrum)