Mercurial > repos > recetox > msmetaenhancer
annotate msmetaenhancer_wrapper.py @ 3:f387ebd6b734 draft
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 6858f7bc3c3cf68fd5002a2241c79923b2ca9acd"
author | recetox |
---|---|
date | Fri, 06 May 2022 12:21:30 +0000 |
parents | 8338640d8676 |
children | 2ada1099f42e |
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.") |
3
f387ebd6b734
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 6858f7bc3c3cf68fd5002a2241c79923b2ca9acd"
recetox
parents:
2
diff
changeset
|
15 parser.add_argument("--log_level", type=str, default='info', |
f387ebd6b734
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 6858f7bc3c3cf68fd5002a2241c79923b2ca9acd"
recetox
parents:
2
diff
changeset
|
16 help="Severity of log messages present in the log file.") |
0
ce612a11b455
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff
changeset
|
17 args = parser.parse_args() |
ce612a11b455
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff
changeset
|
18 |
3
f387ebd6b734
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 6858f7bc3c3cf68fd5002a2241c79923b2ca9acd"
recetox
parents:
2
diff
changeset
|
19 app = Application(log_level=args.log_level, log_file=args.log_file) |
0
ce612a11b455
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff
changeset
|
20 |
2
8338640d8676
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit fc4fc95ed79d03b2f8d075d0df27d75eb93c58ea"
recetox
parents:
0
diff
changeset
|
21 # 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
|
22 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
|
23 # import .msp file |
ce612a11b455
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff
changeset
|
24 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
|
25 |
2
8338640d8676
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit fc4fc95ed79d03b2f8d075d0df27d75eb93c58ea"
recetox
parents:
0
diff
changeset
|
26 # 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
|
27 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
|
28 |
0
ce612a11b455
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff
changeset
|
29 # curate given metadata |
ce612a11b455
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff
changeset
|
30 app.curate_spectra() |
ce612a11b455
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff
changeset
|
31 |
ce612a11b455
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff
changeset
|
32 # 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
|
33 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
|
34 |
ce612a11b455
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff
changeset
|
35 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
|
36 jobs = [] |
ce612a11b455
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff
changeset
|
37 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
|
38 if len(job) != 0: |
ce612a11b455
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff
changeset
|
39 jobs.append(job.split()) |
ce612a11b455
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff
changeset
|
40 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
|
41 else: |
ce612a11b455
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff
changeset
|
42 # 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
|
43 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
|
44 |
ce612a11b455
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff
changeset
|
45 # export .msp file |
ce612a11b455
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff
changeset
|
46 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
|
47 return 0 |
ce612a11b455
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff
changeset
|
48 |
ce612a11b455
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff
changeset
|
49 |
ce612a11b455
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff
changeset
|
50 if __name__ == "__main__": |
ce612a11b455
"planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff
changeset
|
51 main(argv=sys.argv[1:]) |