diff 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
line wrap: on
line diff
--- a/msmetaenhancer_wrapper.py	Tue May 09 09:18:10 2023 +0000
+++ b/msmetaenhancer_wrapper.py	Thu May 18 12:57:50 2023 +0000
@@ -1,14 +1,24 @@
 import argparse
 import asyncio
+import os
+import shutil
 import sys
 
 from matchms import set_matchms_logger_level
 from MSMetaEnhancer import Application
 
 
+def handle_xlsx_file(app, filename):
+    basename = os.path.splitext(filename)[0]
+    temp_file = basename + '.xlsx'
+    app.save_data(temp_file, file_format='xlsx')
+    shutil.copyfile(temp_file, filename)
+
+
 def main(argv):
-    parser = argparse.ArgumentParser(description="Annotate MSP file.")
-    parser.add_argument("--input_file", type=str, help="Path to query spectra file in MSP format.")
+    parser = argparse.ArgumentParser(description="Annotate spectra file.")
+    parser.add_argument("--input_file", type=str, help="Path to query spectra file.")
+    parser.add_argument("--file_format", type=str, help="Format of the input and the output files.")
     parser.add_argument("--output_file", type=str, help="Path to output spectra file.")
     parser.add_argument("--jobs", type=str, help="Sequence of conversion jobs to be used.")
     parser.add_argument("--log_file", type=str, help="Path to log with details of the annotation process.")
@@ -20,17 +30,17 @@
 
     # set matchms logging level to avoid extensive messages in stdout while reading file
     set_matchms_logger_level("ERROR")
-    # import .msp file
-    app.load_spectra(args.input_file, file_format='msp')
+    # import spectra file
+    app.load_data(args.input_file, file_format=args.file_format)
 
     # set matchms logging level back to warning
     set_matchms_logger_level("WARNING")
 
     # curate given metadata
-    app.curate_spectra()
+    app.curate_metadata()
 
     # specify requested services and jobs
-    services = ['PubChem', 'CTS', 'CIR', 'NLM', 'RDKit', 'IDSM', 'BridgeDB']
+    services = ['PubChem', 'CTS', 'CIR', 'RDKit', 'IDSM', 'BridgeDb']
 
     if len(args.jobs) != 0:
         jobs = []
@@ -42,8 +52,11 @@
         # execute without jobs parameter to run all possible jobs
         asyncio.run(app.annotate_spectra(services))
 
-    # export .msp file
-    app.save_spectra(args.output_file, file_format="msp")
+    # export spectra file
+    if args.file_format == 'xlsx':
+        handle_xlsx_file(app, args.output_file)
+    else:
+        app.save_data(args.output_file, file_format=args.file_format)
     return 0