Mercurial > repos > recetox > matchms
comparison matchms_wrapper.py @ 1:4aecfd6b319b draft
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit d110cb008c3703945fe3718465de36278fa34652"
author | recetox |
---|---|
date | Wed, 17 Mar 2021 11:40:17 +0000 |
parents | 6a736abe431f |
children | a7c9fc186f8c |
comparison
equal
deleted
inserted
replaced
0:6a736abe431f | 1:4aecfd6b319b |
---|---|
1 import argparse | 1 import argparse |
2 import sys | 2 import sys |
3 | 3 |
4 import pandas | |
5 from matchms import calculate_scores | 4 from matchms import calculate_scores |
6 from matchms.importing import load_from_msp | 5 from matchms.importing import load_from_msp |
7 from matchms.similarity import ( | 6 from matchms.similarity import ( |
8 CosineGreedy, | 7 CosineGreedy, |
9 CosineHungarian, | 8 CosineHungarian, |
10 FingerprintSimilarity, | 9 FingerprintSimilarity, |
11 IntersectMz, | 10 IntersectMz, |
12 ModifiedCosine, | 11 ModifiedCosine, |
13 ParentMassMatch | 12 ParentMassMatch |
14 ) | 13 ) |
14 from pandas import DataFrame | |
15 | 15 |
16 | 16 |
17 def main(argv): | 17 def main(argv): |
18 parser = argparse.ArgumentParser(description="Compute MSP similarity scores") | 18 parser = argparse.ArgumentParser(description="Compute MSP similarity scores") |
19 parser.add_argument( | 19 parser.add_argument( |
20 "references_filename", type=str, help="Path to reference MSP library." | 20 "references_filename", type=str, help="Path to reference MSP library." |
21 ) | 21 ) |
22 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("output_filename", type=str, help="Path where to store the output .csv.") | |
24 parser.add_argument("similarity_metric", type=str, help='Metric to use for matching.') | 23 parser.add_argument("similarity_metric", type=str, help='Metric to use for matching.') |
24 parser.add_argument("output_filename_scores", type=str, help="Path where to store the output .csv scores.") | |
25 parser.add_argument("output_filename_matches", type=str, help="Path where to store the output .csv matches.") | |
25 | 26 |
26 args = parser.parse_args() | 27 args = parser.parse_args() |
27 | 28 |
28 if args.similarity_metric == 'CosineGreedy': | 29 if args.similarity_metric == 'CosineGreedy': |
29 similarity_metric = CosineGreedy() | 30 similarity_metric = CosineGreedy() |
49 similarity_function=similarity_metric, | 50 similarity_function=similarity_metric, |
50 ) | 51 ) |
51 | 52 |
52 query_names = [spectra.metadata['name'] for spectra in scores.queries] | 53 query_names = [spectra.metadata['name'] for spectra in scores.queries] |
53 reference_names = [spectra.metadata['name'] for spectra in scores.references] | 54 reference_names = [spectra.metadata['name'] for spectra in scores.references] |
54 dataframe = pandas.DataFrame(data=scores.scores, index=reference_names, columns=query_names) | 55 |
55 dataframe.to_csv(args.output_filename, sep=';') | 56 # Write scores to dataframe |
57 dataframe_scores = DataFrame(data=[entry["score"] for entry in scores.scores], index=reference_names, columns=query_names) | |
58 dataframe_scores.to_csv(args.output_filename_scores, sep=';') | |
59 | |
60 # Write number of matches to dataframe | |
61 dataframe_matches = DataFrame(data=[entry["matches"] for entry in scores.scores], index=reference_names, columns=query_names) | |
62 dataframe_matches.to_csv(args.output_filename_matches, sep=';') | |
56 return 0 | 63 return 0 |
57 | 64 |
58 | 65 |
59 if __name__ == "__main__": | 66 if __name__ == "__main__": |
60 main(argv=sys.argv[1:]) | 67 main(argv=sys.argv[1:]) |