Mercurial > repos > recetox > matchms
comparison matchms_wrapper.py @ 4:57959596262d draft
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit 3c7f3cf3f925215a23b2f6665432c32b5ebdc2aa"
author | recetox |
---|---|
date | Tue, 08 Jun 2021 11:28:40 +0000 |
parents | a7c9fc186f8c |
children | 672c22d7f004 |
comparison
equal
deleted
inserted
replaced
3:72adeb3ca264 | 4:57959596262d |
---|---|
13 | 13 |
14 | 14 |
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( | 17 parser.add_argument( |
18 "references_filename", type=str, help="Path to reference MSP library." | 18 "--ref", type=str, dest="references_filename", help="Path to reference MSP library." |
19 ) | 19 ) |
20 parser.add_argument("queries_filename", type=str, help="Path to query spectra.") | 20 parser.add_argument("queries_filename", type=str, help="Path to query spectra.") |
21 parser.add_argument("similarity_metric", type=str, help='Metric to use for matching.') | 21 parser.add_argument("similarity_metric", type=str, help='Metric to use for matching.') |
22 parser.add_argument("output_filename_scores", type=str, help="Path where to store the output .csv scores.") | 22 parser.add_argument("output_filename_scores", type=str, help="Path where to store the output .csv scores.") |
23 parser.add_argument("output_filename_matches", type=str, help="Path where to store the output .csv matches.") | 23 parser.add_argument("output_filename_matches", type=str, help="Path where to store the output .csv matches.") |
25 parser.add_argument("mz_power", type=float, help="The power to raise mz to in the cosine function.") | 25 parser.add_argument("mz_power", type=float, help="The power to raise mz to in the cosine function.") |
26 parser.add_argument("intensity_power", type=float, help="The power to raise intensity to in the cosine function.") | 26 parser.add_argument("intensity_power", type=float, help="The power to raise intensity to in the cosine function.") |
27 | 27 |
28 args = parser.parse_args() | 28 args = parser.parse_args() |
29 | 29 |
30 reference_spectra = load_from_msp(args.references_filename) | 30 queries_spectra = list(load_from_msp(args.queries_filename)) |
31 queries_spectra = load_from_msp(args.queries_filename) | 31 if(args.references_filename): |
32 reference_spectra = list(load_from_msp(args.references_filename)) | |
33 symmetric = False | |
34 else: | |
35 reference_spectra = queries_spectra.copy() | |
36 symmetric = True | |
32 | 37 |
33 if args.similarity_metric == 'CosineGreedy': | 38 if args.similarity_metric == 'CosineGreedy': |
34 similarity_metric = CosineGreedy(args.tolerance, args.mz_power, args.intensity_power) | 39 similarity_metric = CosineGreedy(args.tolerance, args.mz_power, args.intensity_power) |
35 elif args.similarity_metric == 'CosineHungarian': | 40 elif args.similarity_metric == 'CosineHungarian': |
36 similarity_metric = CosineHungarian(args.tolerance, args.mz_power, args.intensity_power) | 41 similarity_metric = CosineHungarian(args.tolerance, args.mz_power, args.intensity_power) |
43 | 48 |
44 scores = calculate_scores( | 49 scores = calculate_scores( |
45 references=list(reference_spectra), | 50 references=list(reference_spectra), |
46 queries=list(queries_spectra), | 51 queries=list(queries_spectra), |
47 similarity_function=similarity_metric, | 52 similarity_function=similarity_metric, |
53 is_symmetric=symmetric | |
48 ) | 54 ) |
49 | 55 |
50 query_names = [spectra.metadata['name'] for spectra in scores.queries] | 56 query_names = [spectra.metadata['name'] for spectra in scores.queries] |
51 reference_names = [spectra.metadata['name'] for spectra in scores.references] | 57 reference_names = [spectra.metadata['name'] for spectra in scores.references] |
52 | 58 |