annotate msmetaenhancer_wrapper.py @ 2:8338640d8676 draft

"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit fc4fc95ed79d03b2f8d075d0df27d75eb93c58ea"
author recetox
date Mon, 25 Apr 2022 06:29:43 +0000
parents ce612a11b455
children f387ebd6b734
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
1 import argparse
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
2 import asyncio
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
3 import sys
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
4
2
8338640d8676 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit fc4fc95ed79d03b2f8d075d0df27d75eb93c58ea"
recetox
parents: 0
diff changeset
5 from matchms import set_matchms_logger_level
0
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
6 from MSMetaEnhancer import Application
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
7
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
8
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
9 def main(argv):
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
10 parser = argparse.ArgumentParser(description="Annotate MSP file.")
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
11 parser.add_argument("--input_file", type=str, help="Path to query spectra file in MSP format.")
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
12 parser.add_argument("--output_file", type=str, help="Path to output spectra file.")
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
13 parser.add_argument("--jobs", type=str, help="Sequence of conversion jobs to be used.")
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
14 parser.add_argument("--log_file", type=str, help="Path to log with details of the annotation process.")
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
15 args = parser.parse_args()
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
16
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
17 app = Application(log_file=args.log_file)
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
18
2
8338640d8676 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit fc4fc95ed79d03b2f8d075d0df27d75eb93c58ea"
recetox
parents: 0
diff changeset
19 # set matchms logging level to avoid extensive messages in stdout while reading file
8338640d8676 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit fc4fc95ed79d03b2f8d075d0df27d75eb93c58ea"
recetox
parents: 0
diff changeset
20 set_matchms_logger_level("ERROR")
0
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
21 # import .msp file
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
22 app.load_spectra(args.input_file, file_format='msp')
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
23
2
8338640d8676 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit fc4fc95ed79d03b2f8d075d0df27d75eb93c58ea"
recetox
parents: 0
diff changeset
24 # set matchms logging level back to warning
8338640d8676 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit fc4fc95ed79d03b2f8d075d0df27d75eb93c58ea"
recetox
parents: 0
diff changeset
25 set_matchms_logger_level("WARNING")
8338640d8676 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit fc4fc95ed79d03b2f8d075d0df27d75eb93c58ea"
recetox
parents: 0
diff changeset
26
0
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
27 # curate given metadata
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
28 app.curate_spectra()
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
29
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
30 # specify requested services and jobs
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
31 services = ['PubChem', 'CTS', 'CIR', 'NLM', 'RDKit', 'IDSM', 'BridgeDB']
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
32
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
33 if len(args.jobs) != 0:
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
34 jobs = []
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
35 for job in args.jobs.split(","):
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
36 if len(job) != 0:
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
37 jobs.append(job.split())
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
38 asyncio.run(app.annotate_spectra(services, jobs))
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
39 else:
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
40 # execute without jobs parameter to run all possible jobs
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
41 asyncio.run(app.annotate_spectra(services))
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
42
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
43 # export .msp file
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
44 app.save_spectra(args.output_file, file_format="msp")
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
45 return 0
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
46
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
47
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
48 if __name__ == "__main__":
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
49 main(argv=sys.argv[1:])