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