annotate msmetaenhancer_wrapper.py @ 13:f4a90c68e2de draft default tip

planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 1d1ecf792f5ea1c8a8f443dd1c3f55c810c5b00d
author recetox
date Mon, 27 May 2024 12:40:12 +0000
parents 25319f346ad4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
1 import argparse
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
2 import asyncio
11
25319f346ad4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 6
diff changeset
3 import os
25319f346ad4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 6
diff changeset
4 import shutil
0
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
5 import sys
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
6
5
1d649315904c "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit fc4fc95ed79d03b2f8d075d0df27d75eb93c58ea"
recetox
parents: 3
diff changeset
7 from matchms import set_matchms_logger_level
0
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
8 from MSMetaEnhancer import Application
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
9
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
10
11
25319f346ad4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 6
diff changeset
11 def handle_xlsx_file(app, filename):
25319f346ad4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 6
diff changeset
12 basename = os.path.splitext(filename)[0]
25319f346ad4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 6
diff changeset
13 temp_file = basename + '.xlsx'
25319f346ad4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 6
diff changeset
14 app.save_data(temp_file, file_format='xlsx')
25319f346ad4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 6
diff changeset
15 shutil.copyfile(temp_file, filename)
25319f346ad4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 6
diff changeset
16
25319f346ad4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 6
diff changeset
17
0
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
18 def main(argv):
11
25319f346ad4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 6
diff changeset
19 parser = argparse.ArgumentParser(description="Annotate spectra file.")
25319f346ad4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 6
diff changeset
20 parser.add_argument("--input_file", type=str, help="Path to query spectra file.")
25319f346ad4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 6
diff changeset
21 parser.add_argument("--file_format", type=str, help="Format of the input and the output files.")
0
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
22 parser.add_argument("--output_file", type=str, help="Path to output spectra file.")
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
23 parser.add_argument("--jobs", type=str, help="Sequence of conversion jobs to be used.")
2
4ae5b466a805 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit f09a5b3ee451d78dc025baee5eccb099f71be2b4"
recetox
parents: 0
diff changeset
24 parser.add_argument("--log_file", type=str, help="Path to log with details of the annotation process.")
6
f30b5c473b65 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 6858f7bc3c3cf68fd5002a2241c79923b2ca9acd"
recetox
parents: 5
diff changeset
25 parser.add_argument("--log_level", type=str, default='info',
f30b5c473b65 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 6858f7bc3c3cf68fd5002a2241c79923b2ca9acd"
recetox
parents: 5
diff changeset
26 help="Severity of log messages present in the log file.")
0
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
27 args = parser.parse_args()
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
28
6
f30b5c473b65 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 6858f7bc3c3cf68fd5002a2241c79923b2ca9acd"
recetox
parents: 5
diff changeset
29 app = Application(log_level=args.log_level, log_file=args.log_file)
0
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
30
5
1d649315904c "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit fc4fc95ed79d03b2f8d075d0df27d75eb93c58ea"
recetox
parents: 3
diff changeset
31 # set matchms logging level to avoid extensive messages in stdout while reading file
1d649315904c "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit fc4fc95ed79d03b2f8d075d0df27d75eb93c58ea"
recetox
parents: 3
diff changeset
32 set_matchms_logger_level("ERROR")
11
25319f346ad4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 6
diff changeset
33 # import spectra file
25319f346ad4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 6
diff changeset
34 app.load_data(args.input_file, file_format=args.file_format)
0
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
35
5
1d649315904c "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit fc4fc95ed79d03b2f8d075d0df27d75eb93c58ea"
recetox
parents: 3
diff changeset
36 # set matchms logging level back to warning
1d649315904c "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit fc4fc95ed79d03b2f8d075d0df27d75eb93c58ea"
recetox
parents: 3
diff changeset
37 set_matchms_logger_level("WARNING")
1d649315904c "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit fc4fc95ed79d03b2f8d075d0df27d75eb93c58ea"
recetox
parents: 3
diff changeset
38
0
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
39 # curate given metadata
11
25319f346ad4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 6
diff changeset
40 app.curate_metadata()
0
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
41
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
42 # specify requested services and jobs
11
25319f346ad4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 6
diff changeset
43 services = ['PubChem', 'CTS', 'CIR', 'RDKit', 'IDSM', 'BridgeDb']
0
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
44
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
45 if len(args.jobs) != 0:
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
46 jobs = []
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
47 for job in args.jobs.split(","):
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
48 if len(job) != 0:
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
49 jobs.append(job.split())
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
50 asyncio.run(app.annotate_spectra(services, jobs))
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
51 else:
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
52 # execute without jobs parameter to run all possible jobs
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
53 asyncio.run(app.annotate_spectra(services))
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
54
11
25319f346ad4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 6
diff changeset
55 # export spectra file
25319f346ad4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 6
diff changeset
56 if args.file_format == 'xlsx':
25319f346ad4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 6
diff changeset
57 handle_xlsx_file(app, args.output_file)
25319f346ad4 planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 538d6c063bb049fe7a08d7d4bd88af91c0d696e8
recetox
parents: 6
diff changeset
58 else:
13
f4a90c68e2de planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 1d1ecf792f5ea1c8a8f443dd1c3f55c810c5b00d
recetox
parents: 11
diff changeset
59 if args.file_format == 'csv':
f4a90c68e2de planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 1d1ecf792f5ea1c8a8f443dd1c3f55c810c5b00d
recetox
parents: 11
diff changeset
60 app.save_data(args.output_file, file_format="tsv")
f4a90c68e2de planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 1d1ecf792f5ea1c8a8f443dd1c3f55c810c5b00d
recetox
parents: 11
diff changeset
61 else:
f4a90c68e2de planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 1d1ecf792f5ea1c8a8f443dd1c3f55c810c5b00d
recetox
parents: 11
diff changeset
62 app.save_data(args.output_file, file_format=args.file_format)
0
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
63 return 0
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
64
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
65
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
66 if __name__ == "__main__":
053ce79ed564 "planemo upload for repository https://github.com/RECETOX/galaxytools/tree/master/tools/msmetaenhancer commit 2c9c75f7d0c5fcadf1fe0284dd767ea5c6f6be51"
recetox
parents:
diff changeset
67 main(argv=sys.argv[1:])