annotate msmetaenhancer_wrapper.py @ 8:2ada1099f42e draft

planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
author recetox
date Thu, 18 May 2023 12:57:50 +0000
parents f387ebd6b734
children 791bf4d9b06c
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
8
2ada1099f42e planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 3
diff changeset
3 import os
2ada1099f42e planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 3
diff changeset
4 import shutil
0
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
5 import sys
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
6
2
8338640d8676 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit fc4fc95ed79d03b2f8d075d0df27d75eb93c58ea"
recetox
parents: 0
diff changeset
7 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
8 from MSMetaEnhancer import Application
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
9
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
10
8
2ada1099f42e planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 3
diff changeset
11 def handle_xlsx_file(app, filename):
2ada1099f42e planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 3
diff changeset
12 basename = os.path.splitext(filename)[0]
2ada1099f42e planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 3
diff changeset
13 temp_file = basename + '.xlsx'
2ada1099f42e planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 3
diff changeset
14 app.save_data(temp_file, file_format='xlsx')
2ada1099f42e planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 3
diff changeset
15 shutil.copyfile(temp_file, filename)
2ada1099f42e planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 3
diff changeset
16
2ada1099f42e planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 3
diff changeset
17
0
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
18 def main(argv):
8
2ada1099f42e planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 3
diff changeset
19 parser = argparse.ArgumentParser(description="Annotate spectra file.")
2ada1099f42e planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 3
diff changeset
20 parser.add_argument("--input_file", type=str, help="Path to query spectra file.")
2ada1099f42e planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 3
diff changeset
21 parser.add_argument("--file_format", type=str, help="Format of the input and the output files.")
0
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
22 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
23 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
24 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
25 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
26 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
27 args = parser.parse_args()
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
28
3
f387ebd6b734 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 6858f7bc3c3cf68fd5002a2241c79923b2ca9acd"
recetox
parents: 2
diff changeset
29 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
30
2
8338640d8676 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit fc4fc95ed79d03b2f8d075d0df27d75eb93c58ea"
recetox
parents: 0
diff changeset
31 # 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
32 set_matchms_logger_level("ERROR")
8
2ada1099f42e planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 3
diff changeset
33 # import spectra file
2ada1099f42e planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 3
diff changeset
34 app.load_data(args.input_file, file_format=args.file_format)
0
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
35
2
8338640d8676 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit fc4fc95ed79d03b2f8d075d0df27d75eb93c58ea"
recetox
parents: 0
diff changeset
36 # 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
37 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
38
0
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
39 # curate given metadata
8
2ada1099f42e planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 3
diff changeset
40 app.curate_metadata()
0
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
41
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
42 # specify requested services and jobs
8
2ada1099f42e planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 3
diff changeset
43 services = ['PubChem', 'CTS', 'CIR', 'RDKit', 'IDSM', 'BridgeDb']
0
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 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
46 jobs = []
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
47 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
48 if len(job) != 0:
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
49 jobs.append(job.split())
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
50 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
51 else:
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
52 # 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
53 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
54
8
2ada1099f42e planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 3
diff changeset
55 # export spectra file
2ada1099f42e planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 3
diff changeset
56 if args.file_format == 'xlsx':
2ada1099f42e planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 3
diff changeset
57 handle_xlsx_file(app, args.output_file)
2ada1099f42e planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 3
diff changeset
58 else:
2ada1099f42e planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 3
diff changeset
59 app.save_data(args.output_file, file_format=args.file_format)
0
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
60 return 0
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
61
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
62
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
63 if __name__ == "__main__":
ce612a11b455 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 26bede767f65ec97ac84b8cc3309db0aced22d53"
recetox
parents:
diff changeset
64 main(argv=sys.argv[1:])