comparison msconvert_raw_wrapper.py @ 8:d2c61663e33c draft

Uploaded
author galaxyp
date Fri, 26 Sep 2014 14:44:54 -0400
parents 10f4a0356342
children
comparison
equal deleted inserted replaced
7:37e5502441cc 8:d2c61663e33c
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 import optparse 2 import optparse
3 import os 3 import os
4 import sys 4 import sys
5 import tempfile 5 import tempfile
6 import shutil 6 import shutil
7 import subprocess 7 import subprocess
8 import re 8 import re
9 from os.path import basename 9 from os.path import basename
10 import logging 10 import logging
11 11
31 if not stderr or len(stderr) % buffsize != 0: 31 if not stderr or len(stderr) % buffsize != 0:
32 break 32 break
33 except OverflowError: 33 except OverflowError:
34 pass 34 pass
35 return stderr 35 return stderr
36 36
37 def execute(command, stdin=None): 37 def execute(command, stdin=None):
38 with open(tmp_stderr_name, 'wb') as tmp_stderr: 38 with open(tmp_stderr_name, 'wb') as tmp_stderr:
39 with open(tmp_stdout_name, 'wb') as tmp_stdout: 39 with open(tmp_stdout_name, 'wb') as tmp_stdout:
40 proc = subprocess.Popen(args=command, shell=True, stderr=tmp_stderr.fileno(), stdout=tmp_stdout.fileno(), stdin=stdin, env=os.environ) 40 proc = subprocess.Popen(args=command, shell=True, stderr=tmp_stderr.fileno(), stdout=tmp_stdout.fileno(), stdin=stdin, env=os.environ)
41 returncode = proc.wait() 41 returncode = proc.wait()
42 if returncode != 0: 42 if returncode != 0:
43 raise Exception, "Program returned with non-zero exit code %d. stderr: %s" % (returncode, read_stderr()) 43 raise Exception("Program returned with non-zero exit code %d. stderr: %s" % (returncode, read_stderr()))
44 44
45 def delete_file(path): 45 def delete_file(path):
46 if os.path.exists(path): 46 if os.path.exists(path):
47 try: 47 try:
48 os.remove(path) 48 os.remove(path)
112 cmd = "%s --%s" % (cmd, options.binaryencoding) 112 cmd = "%s --%s" % (cmd, options.binaryencoding)
113 cmd = "%s --mz%s" % (cmd, options.mzencoding) 113 cmd = "%s --mz%s" % (cmd, options.mzencoding)
114 cmd = "%s --inten%s" % (cmd, options.intensityencoding) 114 cmd = "%s --inten%s" % (cmd, options.intensityencoding)
115 cmd = "%s %s" % (cmd, input_file) 115 cmd = "%s %s" % (cmd, input_file)
116 cmd = "%s %s" % (cmd, filter_commands) 116 cmd = "%s %s" % (cmd, filter_commands)
117 print cmd 117 print(cmd)
118 execute(cmd) 118 execute(cmd)
119 output_files = os.listdir('output') 119 output_files = os.listdir('output')
120 assert len(output_files) == 1 120 assert len(output_files) == 1
121 output_file = output_files[0] 121 output_file = output_files[0]
122 shutil.copy(os.path.join('output', output_file), options.output) 122 shutil.copy(os.path.join('output', output_file), options.output)