annotate matchms_networking_wrapper.py @ 0:aa77b38aede8 draft

planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
author recetox
date Tue, 18 Oct 2022 13:21:09 +0000
parents
children ce2f8af32ea7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
aa77b38aede8 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
1 import argparse
aa77b38aede8 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
2 import sys
aa77b38aede8 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
3
aa77b38aede8 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
aa77b38aede8 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
aa77b38aede8 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
6
aa77b38aede8 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
7
aa77b38aede8 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
8 def main(argv):
aa77b38aede8 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.")
aa77b38aede8 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.")
aa77b38aede8 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.")
aa77b38aede8 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.")
aa77b38aede8 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.")
aa77b38aede8 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.")
aa77b38aede8 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.")
aa77b38aede8 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")
aa77b38aede8 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.")
aa77b38aede8 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.")
aa77b38aede8 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
19 args = parser.parse_args()
aa77b38aede8 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
20
aa77b38aede8 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)
aa77b38aede8 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
22
aa77b38aede8 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,
aa77b38aede8 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,
aa77b38aede8 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,
aa77b38aede8 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,
aa77b38aede8 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,
aa77b38aede8 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)
aa77b38aede8 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
29
aa77b38aede8 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
30 network.create_network(scores)
aa77b38aede8 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)
aa77b38aede8 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
32
aa77b38aede8 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
33 return 0
aa77b38aede8 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
34
aa77b38aede8 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
35
aa77b38aede8 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
36 if __name__ == "__main__":
aa77b38aede8 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:])
aa77b38aede8 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/matchms commit f7bab98744e338dcdbdc9cf6f9de287632c76ea2
recetox
parents:
diff changeset
38 pass