annotate matchms_filtering_wrapper.py @ 8:f30b53a817af draft

planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit 98223db312c30b0e121a1422a9534a3db3fbf0c0
author recetox
date Thu, 14 Dec 2023 13:46:31 +0000
parents 3f96c93f8566
children 44e7027714d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
1 import argparse
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
2 import sys
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
3
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
4 from matchms.exporting import save_as_mgf, save_as_msp
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
5 from matchms.filtering import add_compound_name, add_fingerprint, add_losses, add_parent_mass, add_precursor_mz,\
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
6 add_retention_index, add_retention_time, clean_compound_name
1
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
7 from matchms.filtering import default_filters, normalize_intensities, reduce_to_number_of_peaks, select_by_mz, \
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
8 select_by_relative_intensity
8
f30b53a817af planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit 98223db312c30b0e121a1422a9534a3db3fbf0c0
recetox
parents: 1
diff changeset
9 from matchms.filtering.filter_utils.derive_precursor_mz_and_parent_mass import derive_precursor_mz_from_parent_mass
0
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
10 from matchms.importing import load_from_mgf, load_from_msp
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
11
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
12
1
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
13 def require_key(spectrum, key):
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
14 if spectrum.get(key):
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
15 return spectrum
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
16
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
17 return None
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
18
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
19
0
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
20 def main(argv):
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
21 parser = argparse.ArgumentParser(description="Compute MSP similarity scores")
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
22 parser.add_argument("--spectra", type=str, required=True, help="Mass spectra file to be filtered.")
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
23 parser.add_argument("--spectra_format", type=str, required=True, help="Format of spectra file.")
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
24 parser.add_argument("--output", type=str, required=True, help="Filtered mass spectra file.")
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
25 parser.add_argument("-normalise_intensities", action='store_true',
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
26 help="Normalize intensities of peaks (and losses) to unit height.")
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
27 parser.add_argument("-default_filters", action='store_true',
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
28 help="Collection of filters that are considered default and that do no require any (factory) arguments.")
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
29 parser.add_argument("-clean_metadata", action='store_true',
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
30 help="Apply all adding and cleaning filters if possible, so that the spectra have canonical metadata.")
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
31 parser.add_argument("-relative_intensity", action='store_true',
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
32 help="Keep only peaks within set relative intensity range (keep if to_intensity >= intensity >= from_intensity).")
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
33 parser.add_argument("--from_intensity", type=float, help="Lower bound for intensity filter")
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
34 parser.add_argument("--to_intensity", type=float, help="Upper bound for intensity filter")
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
35 parser.add_argument("-mz_range", action='store_true',
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
36 help="Keep only peaks between set m/z range (keep if to_mz >= m/z >= from_mz).")
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
37 parser.add_argument("--from_mz", type=float, help="Lower bound for m/z filter")
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
38 parser.add_argument("--to_mz", type=float, help="Upper bound for m/z filter")
1
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
39 parser.add_argument("-require_smiles", action='store_true',
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
40 help="Remove spectra that does not contain SMILES.")
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
41 parser.add_argument("-require_inchi", action='store_true',
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
42 help="Remove spectra that does not contain INCHI.")
8
f30b53a817af planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit 98223db312c30b0e121a1422a9534a3db3fbf0c0
recetox
parents: 1
diff changeset
43 parser.add_argument("-derive_precursor_mz_from_parent_mass", action='store_true',
f30b53a817af planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit 98223db312c30b0e121a1422a9534a3db3fbf0c0
recetox
parents: 1
diff changeset
44 help="Derives the precursor_mz from the parent mass and adduct or charge.")
f30b53a817af planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit 98223db312c30b0e121a1422a9534a3db3fbf0c0
recetox
parents: 1
diff changeset
45 parser.add_argument("--estimate_from_adduct", type=str, help="estimate from adduct.")
1
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
46 parser.add_argument("-reduce_to_top_n_peaks", action='store_true',
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
47 help="reduce to top n peaks filter.")
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
48 parser.add_argument("--n_max", type=int, help="Maximum number of peaks. Remove peaks if more peaks are found.")
0
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
49 args = parser.parse_args()
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
50
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
51 if not (args.normalise_intensities
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
52 or args.default_filters
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
53 or args.clean_metadata
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
54 or args.relative_intensity
1
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
55 or args.mz_range
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
56 or args.require_smiles
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
57 or args.require_inchi
8
f30b53a817af planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit 98223db312c30b0e121a1422a9534a3db3fbf0c0
recetox
parents: 1
diff changeset
58 or args.derive_precursor_mz_from_parent_mass
1
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
59 or args.reduce_to_top_n_peaks):
0
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
60 raise ValueError('No filter selected.')
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
61
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
62 if args.spectra_format == 'msp':
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
63 spectra = list(load_from_msp(args.spectra))
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
64 elif args.queries_format == 'mgf':
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
65 spectra = list(load_from_mgf(args.spectra))
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
66 else:
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
67 raise ValueError(f'File format {args.spectra_format} not supported for mass spectra file.')
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
68
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
69 filtered_spectra = []
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
70 for spectrum in spectra:
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
71 if args.normalise_intensities:
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
72 spectrum = normalize_intensities(spectrum)
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
73
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
74 if args.default_filters:
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
75 spectrum = default_filters(spectrum)
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
76
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
77 if args.clean_metadata:
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
78 filters = [add_compound_name, add_precursor_mz, add_fingerprint, add_losses, add_parent_mass,
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
79 add_retention_index, add_retention_time, clean_compound_name]
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
80 for metadata_filter in filters:
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
81 spectrum = metadata_filter(spectrum)
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
82
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
83 if args.relative_intensity:
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
84 spectrum = select_by_relative_intensity(spectrum, args.from_intensity, args.to_intensity)
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
85
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
86 if args.mz_range:
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
87 spectrum = select_by_mz(spectrum, args.from_mz, args.to_mz)
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
88
1
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
89 if args.reduce_to_top_n_peaks:
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
90 spectrum = reduce_to_number_of_peaks(spectrum_in=spectrum, n_max=args.n_max)
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
91
8
f30b53a817af planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit 98223db312c30b0e121a1422a9534a3db3fbf0c0
recetox
parents: 1
diff changeset
92 if args.derive_precursor_mz_from_parent_mass:
f30b53a817af planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit 98223db312c30b0e121a1422a9534a3db3fbf0c0
recetox
parents: 1
diff changeset
93 spectrum.set("parent_mass", float(spectrum.get('parent_mass')))
f30b53a817af planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit 98223db312c30b0e121a1422a9534a3db3fbf0c0
recetox
parents: 1
diff changeset
94 precursor_mz = derive_precursor_mz_from_parent_mass(spectrum, args.estimate_from_adduct)
f30b53a817af planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit 98223db312c30b0e121a1422a9534a3db3fbf0c0
recetox
parents: 1
diff changeset
95 spectrum.set("precursor_mz", precursor_mz)
f30b53a817af planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit 98223db312c30b0e121a1422a9534a3db3fbf0c0
recetox
parents: 1
diff changeset
96
1
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
97 if args.require_smiles and spectrum is not None:
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
98 spectrum = require_key(spectrum, "smiles")
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
99
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
100 if args.require_inchi and spectrum is not None:
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
101 spectrum = require_key(spectrum, "inchi")
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
102
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
103 if spectrum is not None:
3f96c93f8566 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit b1cc1aebf796f170d93e3dd46ffcdefdc7b8018a
recetox
parents: 0
diff changeset
104 filtered_spectra.append(spectrum)
0
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
105
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
106 if args.spectra_format == 'msp':
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
107 save_as_msp(filtered_spectra, args.output)
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
108 else:
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
109 save_as_mgf(filtered_spectra, args.output)
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
110
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
111 return 0
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
112
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
113
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
114 if __name__ == "__main__":
9ff95a1a2705 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f79a5b51599254817727bc9028b9797ea994cb4e
recetox
parents:
diff changeset
115 main(argv=sys.argv[1:])