annotate matchms_networking_wrapper.py @ 5:a177ac3c752c draft

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