annotate matchms_networking_wrapper.py @ 3:10bb45d24c10 draft

planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit 701733d99742a8e567ed6db7384be66c5ecb4a58
author recetox
date Thu, 18 May 2023 13:24:06 +0000
parents e4ec3592507f
children 8147d93d372d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
1 import argparse
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
2 import sys
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
3
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
4 from matchms.importing import scores_from_json
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
5 from matchms.networking import SimilarityNetwork
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
6
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
7
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
8 def main(argv):
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
9 parser = argparse.ArgumentParser(description="Create network-graph from similarity scores.")
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
10 parser.add_argument("--graph_format", type=str, help="Format of the output similarity network.")
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
11 parser.add_argument("--identifier", type=str, help="Unique metadata identifier of each spectrum from which scores are computed.")
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
12 parser.add_argument("--top_n", type=int, help="Number of highest-score edges to keep.")
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
13 parser.add_argument("--max_links", type=int, help="Maximum number of links to add per node.")
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
14 parser.add_argument("--score_cutoff", type=float, help="Minimum similarity score value to link two spectra.")
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
15 parser.add_argument("--link_method", type=str, help="Method for selecting top N edges for each node.")
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
16 parser.add_argument("--keep_unconnected_nodes", help="Keep unconnected nodes in the network.", action="store_true")
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
17 parser.add_argument("scores", type=str, help="Path to matchMS similarity-scores .json file.")
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
18 parser.add_argument("output_filename", type=str, help="Path where to store the output similarity network.")
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
19 args = parser.parse_args()
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
20
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
21 scores = scores_from_json(args.scores)
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
22
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
23 network = SimilarityNetwork(identifier_key=args.identifier,
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
24 top_n=args.top_n,
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
25 max_links=args.max_links,
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
26 score_cutoff=args.score_cutoff,
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
27 link_method=args.link_method,
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
28 keep_unconnected_nodes=args.keep_unconnected_nodes)
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
29
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
30 network.create_network(scores)
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
31 network.export_to_file(filename=args.output_filename, graph_format=args.graph_format)
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
32
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
33 return 0
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
34
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
35
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
36 if __name__ == "__main__":
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
37 main(argv=sys.argv[1:])
e4ec3592507f planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
38 pass