comparison matchms_networking_wrapper.py @ 0:80df426e7e47 draft

planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit 113433b8b9790405c2c5d054aee4a29a21b77dc7
author recetox
date Thu, 30 May 2024 18:07:29 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:80df426e7e47
1 import argparse
2 import sys
3
4 from matchms.importing import scores_from_json
5 from matchms.networking import SimilarityNetwork
6
7
8 def main(argv):
9 parser = argparse.ArgumentParser(description="Create network-graph from similarity scores.")
10 parser.add_argument("--graph_format", type=str, help="Format of the output similarity network.")
11 parser.add_argument("--score_name", type=str, help="Name of the score layer to use for creating the network graph.")
12 parser.add_argument("--identifier", type=str, help="Unique metadata identifier of each spectrum from which scores are computed.")
13 parser.add_argument("--top_n", type=int, help="Number of highest-score edges to keep.")
14 parser.add_argument("--max_links", type=int, help="Maximum number of links to add per node.")
15 parser.add_argument("--score_cutoff", type=float, help="Minimum similarity score value to link two spectra.")
16 parser.add_argument("--link_method", type=str, help="Method for selecting top N edges for each node.")
17 parser.add_argument("--keep_unconnected_nodes", help="Keep unconnected nodes in the network.", action="store_true")
18 parser.add_argument("scores", type=str, help="Path to matchms similarity-scores .json file.")
19 parser.add_argument("output_filename", type=str, help="Path where to store the output similarity network.")
20 args = parser.parse_args()
21
22 scores = scores_from_json(args.scores)
23
24 network = SimilarityNetwork(identifier_key=args.identifier,
25 top_n=args.top_n,
26 max_links=args.max_links,
27 score_cutoff=args.score_cutoff,
28 link_method=args.link_method,
29 keep_unconnected_nodes=args.keep_unconnected_nodes)
30 score_name = next((s for s in scores.score_names if args.score_name in s and "score" in s), None)
31 if score_name is None:
32 raise ValueError(f"Could not find any score name containing '{args.score_name}'.")
33
34 network.create_network(scores, score_name)
35 network.export_to_file(filename=args.output_filename, graph_format=args.graph_format)
36
37 return 0
38
39
40 if __name__ == "__main__":
41 main(argv=sys.argv[1:])
42 pass