annotate reverse.py @ 13:6521f577059f draft

Uploaded
author galaxyp
date Fri, 19 Jul 2013 11:32:58 -0400
parents fb591fc7241c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
1 from os.path import dirname, join, abspath
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
2 import sys
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
3 from optparse import OptionParser
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
4 from ConfigParser import SafeConfigParser
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
5 import subprocess
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
6
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
7 DEBUG = False
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
8
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
9
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
10 def main():
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
11 (options, args) = _parse_args()
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
12 format_args = (options.input, options.output)
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
13 _run_shell("cat '%s' > '%s'" % format_args)
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
14 _run_dbtoolkit("com.compomics.dbtoolkit.toolkit.ReverseFASTADB", "'%s' | head --lines -4 >> '%s'" % \
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
15 format_args)
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
16
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
17
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
18 def _run_shell(command):
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
19 if DEBUG:
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
20 print "Running shell command %s" % command
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
21 _exec(command)
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
22
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
23
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
24 def _run_dbtoolkit(java_class, args):
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
25 command_prefix = "java -cp %s" % _dbtoolkit_jar_path()
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
26 _exec("%s %s %s" % (command_prefix, java_class, args))
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
27
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
28
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
29 def _dbtoolkit_jar_path():
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
30 py_path = __file__
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
31 jar_path = join(dirname(py_path), "dbtoolkit-4.2", "dbtoolkit-4.2.jar")
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
32 return jar_path
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
33
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
34 def _exec(command):
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
35 proc = subprocess.Popen(args=command, shell=True)
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
36 return_code = proc.wait()
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
37 if return_code != 0:
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
38 print "Error executing command [%s], return code is %d" % (command, return_code)
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
39 sys.exit(return_code)
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
40
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
41
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
42 def _parse_args():
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
43 parser = OptionParser()
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
44 parser.add_option("-i", "--input")
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
45 parser.add_option("-o", "--output")
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
46 return parser.parse_args()
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
47
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
48
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
49 if __name__ == "__main__":
fb591fc7241c Improved some datatype handling
galaxyp
parents:
diff changeset
50 main()