comparison matchms_filtering_wrapper.py @ 17:7627b40601f6 draft default tip

planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit 8db07edd3b0d2ff778036dec410027ad58365488
author recetox
date Mon, 15 Jul 2024 08:00:58 +0000
parents ee35dcec350a
children
comparison
equal deleted inserted replaced
16:26c92af1bd28 17:7627b40601f6
1 import argparse 1 import argparse
2 import sys 2 import sys
3 3
4 from matchms.exporting import save_as_mgf, save_as_msp 4 from matchms.exporting import save_as_mgf, save_as_msp
5 from matchms.filtering import add_compound_name, add_fingerprint, add_losses, add_parent_mass, add_precursor_mz, \ 5 from matchms.filtering import add_compound_name, add_fingerprint, add_parent_mass, add_precursor_mz, \
6 add_retention_index, add_retention_time, clean_compound_name 6 add_retention_index, add_retention_time, clean_compound_name
7 from matchms.filtering import default_filters, normalize_intensities, reduce_to_number_of_peaks, select_by_mz, \ 7 from matchms.filtering import default_filters, normalize_intensities, reduce_to_number_of_peaks, select_by_mz, \
8 select_by_relative_intensity 8 select_by_relative_intensity
9 from matchms.filtering.filter_utils.derive_precursor_mz_and_parent_mass import derive_precursor_mz_from_parent_mass 9 from matchms.filtering.filter_utils.derive_precursor_mz_and_parent_mass import derive_precursor_mz_from_parent_mass
10 from matchms.importing import load_from_mgf, load_from_msp 10 from matchms.importing import load_from_mgf, load_from_msp
14 parser = argparse.ArgumentParser(description="Compute MSP similarity scores") 14 parser = argparse.ArgumentParser(description="Compute MSP similarity scores")
15 parser.add_argument("--spectra", type=str, required=True, help="Mass spectra file to be filtered.") 15 parser.add_argument("--spectra", type=str, required=True, help="Mass spectra file to be filtered.")
16 parser.add_argument("--spectra_format", type=str, required=True, help="Format of spectra file.") 16 parser.add_argument("--spectra_format", type=str, required=True, help="Format of spectra file.")
17 parser.add_argument("--output", type=str, required=True, help="Filtered mass spectra file.") 17 parser.add_argument("--output", type=str, required=True, help="Filtered mass spectra file.")
18 parser.add_argument("-normalise_intensities", action='store_true', 18 parser.add_argument("-normalise_intensities", action='store_true',
19 help="Normalize intensities of peaks (and losses) to unit height.") 19 help="Normalize intensities of peaks to unit height.")
20 parser.add_argument("-default_filters", action='store_true', 20 parser.add_argument("-default_filters", action='store_true',
21 help="Collection of filters that are considered default and that do no require any (factory) arguments.") 21 help="Collection of filters that are considered default and that do no require any (factory) arguments.")
22 parser.add_argument("-clean_metadata", action='store_true', 22 parser.add_argument("-clean_metadata", action='store_true',
23 help="Apply all adding and cleaning filters if possible, so that the spectra have canonical metadata.") 23 help="Apply all adding and cleaning filters if possible, so that the spectra have canonical metadata.")
24 parser.add_argument("-relative_intensity", action='store_true', 24 parser.add_argument("-relative_intensity", action='store_true',
60 60
61 if args.default_filters: 61 if args.default_filters:
62 spectrum = default_filters(spectrum) 62 spectrum = default_filters(spectrum)
63 63
64 if args.clean_metadata: 64 if args.clean_metadata:
65 filters = [add_compound_name, add_precursor_mz, add_fingerprint, add_losses, add_parent_mass, 65 filters = [add_compound_name, add_precursor_mz, add_fingerprint, add_parent_mass,
66 add_retention_index, add_retention_time, clean_compound_name] 66 add_retention_index, add_retention_time, clean_compound_name]
67 for metadata_filter in filters: 67 for metadata_filter in filters:
68 spectrum = metadata_filter(spectrum) 68 spectrum = metadata_filter(spectrum)
69 69
70 if args.relative_intensity: 70 if args.relative_intensity: