diff msconvert_wrapper.py @ 6:6b6bba73eadb draft

planemo upload commit d56659dd48f8c554a832787e71aca6ae65c90848
author galaxyp
date Tue, 14 Mar 2017 16:52:39 -0400
parents 637e309295cf
children
line wrap: on
line diff
--- a/msconvert_wrapper.py	Mon Dec 12 17:07:11 2016 -0500
+++ b/msconvert_wrapper.py	Tue Mar 14 16:52:39 2017 -0400
@@ -7,6 +7,7 @@
 import subprocess
 import re
 import logging
+import shlex
 
 assert sys.version_info[:2] >= (2, 6)
 
@@ -40,7 +41,8 @@
     try:
         with open(tmp_stderr_name, 'wb') as tmp_stderr:
             with open(tmp_stdout_name, 'wb') as tmp_stdout:
-                proc = subprocess.Popen(args=command, shell=True, stderr=tmp_stderr.fileno(), stdout=tmp_stdout.fileno(), stdin=stdin, env=os.environ)
+                args = shlex.split(command) # handle proper splitting of quoted args
+                proc = subprocess.Popen(args=args, shell=False, stderr=tmp_stderr.fileno(), stdout=tmp_stdout.fileno(), stdin=stdin, env=os.environ)
                 returncode = proc.wait()
                 if returncode != 0:
                     raise Exception("Program returned with non-zero exit code %d. stderr: %s" % (returncode, read_stderr()))
@@ -88,7 +90,7 @@
 
 #ENDTEMPLATE
 
-to_extensions = ['mzML', 'mzXML', 'unindexed_mzML', 'unindexed_mzXML', 'mgf', 'txt', 'ms2', 'cms2']
+to_extensions = ['mzML', 'mzXML', 'unindexed_mzML', 'unindexed_mzXML', 'mgf', 'mz5', 'txt', 'ms2', 'cms2']
 
 
 def str_to_bool(v):
@@ -171,7 +173,7 @@
     return filters_file_path
 
 
-def _build_base_cmd(options):
+def _build_base_cmd(options,args=None):
     to_extension = options.toextension
     if to_extension.startswith("unindexed_"):
         to_extension = to_extension[len("unindexed_"):]
@@ -179,6 +181,8 @@
     else:
         to_params = ""
     cmd = "msconvert --%s %s" % (to_extension, to_params)
+    if args:
+        cmd = "%s %s" % (cmd, ' '.join(args))
     if str_to_bool(options.zlib):
         cmd = "%s %s" % (cmd, "--zlib")
     if options.binaryencoding:
@@ -208,7 +212,10 @@
     parser.add_option('--input', dest='inputs', action='append', default=[])
     parser.add_option('--input_name', dest='input_names', action='append', default=[])
     parser.add_option('--implicit', dest='implicits', action='append', default=[], help='input files that should NOT be on the msconvert command line.')
+    parser.add_option('--ident', dest='idents', action='append', default=[])
+    parser.add_option('--ident_name', dest='ident_names', action='append', default=[])
     parser.add_option('--output', dest='output')
+    parser.add_option('--refinement', dest='refinement')
     parser.add_option('--fromextension', dest='fromextension')
     parser.add_option('--toextension', dest='toextension', default='mzML', choices=to_extensions)
     parser.add_option('--binaryencoding', dest='binaryencoding', choices=['32', '64'])
@@ -253,8 +260,11 @@
         if input in options.implicits:
             continue
         input_files.append(input_file)
+    for i, ident in enumerate(options.idents):
+        ident_file = options.ident_names[i]
+        copy_to_working_directory(ident, ident_file)
 
-    cmd = _build_base_cmd(options)
+    cmd = _build_base_cmd(options,args=args)
     file_column = options.filter_table_file_column
     if not file_column:
         # Apply same filters to all files, just create a unviersal filter files
@@ -275,7 +285,16 @@
         cmd = "%s --merge" % cmd
     output_file = _run(cmd, output_dir='output', inputs=input_files, debug=options.debug)
     shutil.copy(output_file, options.output)
+    if options.refinement:
+        # .mzRefinement.tsv
+        files = os.listdir(os.getcwd())
+        for fname in files:
+            if fname.endswith('.mzRefinement.tsv'):
+                shutil.copy(fname, options.refinement)
+                break
 
+def __main__():
+    run_script()
 
 if __name__ == '__main__':
     __main__()