Mercurial > repos > recetox > matchms
comparison matchms_wrapper.py @ 9:f06923bdd2f2 draft
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit 5bd7d3aa1063b0a5a90577dd6c79504fdd93f73c"
author | recetox |
---|---|
date | Mon, 10 Jan 2022 12:21:43 +0000 |
parents | 4571641de47a |
children |
comparison
equal
deleted
inserted
replaced
8:8b1e1b2edecc | 9:f06923bdd2f2 |
---|---|
1 import argparse | 1 import argparse |
2 import sys | 2 import sys |
3 | 3 |
4 from matchms import calculate_scores | 4 from matchms import calculate_scores |
5 from matchms.filtering import add_precursor_mz, default_filters, normalize_intensities | 5 from matchms.filtering import add_precursor_mz, default_filters, normalize_intensities |
6 from matchms.importing import load_from_msp | 6 from matchms.importing import load_from_mgf, load_from_msp |
7 from matchms.similarity import ( | 7 from matchms.similarity import ( |
8 CosineGreedy, | 8 CosineGreedy, |
9 CosineHungarian, | 9 CosineHungarian, |
10 ModifiedCosine, | 10 ModifiedCosine, |
11 ) | 11 ) |
15 def main(argv): | 15 def main(argv): |
16 parser = argparse.ArgumentParser(description="Compute MSP similarity scores") | 16 parser = argparse.ArgumentParser(description="Compute MSP similarity scores") |
17 parser.add_argument("-f", dest="default_filters", action='store_true', help="Apply default filters") | 17 parser.add_argument("-f", dest="default_filters", action='store_true', help="Apply default filters") |
18 parser.add_argument("-n", dest="normalize_intensities", action='store_true', help="Normalize intensities.") | 18 parser.add_argument("-n", dest="normalize_intensities", action='store_true', help="Normalize intensities.") |
19 parser.add_argument("-s", dest="symmetric", action='store_true', help="Computation is symmetric.") | 19 parser.add_argument("-s", dest="symmetric", action='store_true', help="Computation is symmetric.") |
20 parser.add_argument("--ref", dest="references_filename", type=str, help="Path to reference MSP library.") | 20 parser.add_argument("--ref", dest="references_filename", type=str, help="Path to reference spectra library.") |
21 parser.add_argument("--ref_format", dest="references_format", type=str, help="Reference spectra library file format.") | |
21 parser.add_argument("queries_filename", type=str, help="Path to query spectra.") | 22 parser.add_argument("queries_filename", type=str, help="Path to query spectra.") |
23 parser.add_argument("queries_format", type=str, help="Query spectra file format.") | |
22 parser.add_argument("similarity_metric", type=str, help='Metric to use for matching.') | 24 parser.add_argument("similarity_metric", type=str, help='Metric to use for matching.') |
23 parser.add_argument("tolerance", type=float, help="Tolerance to use for peak matching.") | 25 parser.add_argument("tolerance", type=float, help="Tolerance to use for peak matching.") |
24 parser.add_argument("mz_power", type=float, help="The power to raise mz to in the cosine function.") | 26 parser.add_argument("mz_power", type=float, help="The power to raise mz to in the cosine function.") |
25 parser.add_argument("intensity_power", type=float, help="The power to raise intensity to in the cosine function.") | 27 parser.add_argument("intensity_power", type=float, help="The power to raise intensity to in the cosine function.") |
26 parser.add_argument("output_filename_scores", type=str, help="Path where to store the output .csv scores.") | 28 parser.add_argument("output_filename_scores", type=str, help="Path where to store the output .tsv scores.") |
27 parser.add_argument("output_filename_matches", type=str, help="Path where to store the output .csv matches.") | 29 parser.add_argument("output_filename_matches", type=str, help="Path where to store the output .tsv matches.") |
28 args = parser.parse_args() | 30 args = parser.parse_args() |
29 | 31 |
30 queries_spectra = list(load_from_msp(args.queries_filename)) | 32 if args.queries_format == 'msp': |
33 queries_spectra = list(load_from_msp(args.queries_filename)) | |
34 elif args.queries_format == 'mgf': | |
35 queries_spectra = list(load_from_mgf(args.queries_filename)) | |
36 else: | |
37 raise ValueError(f'File format {args.queries_format} not supported for query spectra.') | |
38 | |
31 if args.symmetric: | 39 if args.symmetric: |
32 reference_spectra = [] | 40 reference_spectra = [] |
33 else: | 41 else: |
34 reference_spectra = list(load_from_msp(args.references_filename)) | 42 if args.references_format == 'msp': |
43 reference_spectra = list(load_from_msp(args.references_filename)) | |
44 elif args.references_format == 'mgf': | |
45 reference_spectra = list(load_from_mgf(args.references_filename)) | |
46 else: | |
47 raise ValueError(f'File format {args.references_format} not supported for reference spectra library.') | |
35 | 48 |
36 if args.default_filters is True: | 49 if args.default_filters is True: |
37 print("Applying default filters...") | 50 print("Applying default filters...") |
38 queries_spectra = list(map(default_filters, queries_spectra)) | 51 queries_spectra = list(map(default_filters, queries_spectra)) |
39 reference_spectra = list(map(default_filters, reference_spectra)) | 52 reference_spectra = list(map(default_filters, reference_spectra)) |