| 105 | 1 #!/usr/bin/env python | 
|  | 2 from os.path import join | 
|  | 3 import sys | 
|  | 4 from optparse import OptionParser | 
|  | 5 from ConfigParser import SafeConfigParser | 
|  | 6 import subprocess | 
|  | 7 | 
|  | 8 DEBUG = False | 
|  | 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( args.script_path ) | 
|  | 26     _exec("%s %s %s" % (command_prefix, java_class, args)) | 
|  | 27 | 
|  | 28 | 
|  | 29 def _dbtoolkit_jar_path( script_path ): | 
|  | 30     jar_path = join(script_path, "dbtoolkit-4.2", "dbtoolkit-4.2.jar") | 
|  | 31     return jar_path | 
|  | 32 | 
|  | 33 def _exec(command): | 
|  | 34     proc = subprocess.Popen(args=command, shell=True) | 
|  | 35     return_code = proc.wait() | 
|  | 36     if return_code != 0: | 
|  | 37         print "Error executing command [%s], return code is %d" % (command, return_code) | 
|  | 38         sys.exit(return_code) | 
|  | 39 | 
|  | 40 | 
|  | 41 def _parse_args(): | 
|  | 42     parser = OptionParser() | 
|  | 43     parser.add_option("-i", "--input") | 
|  | 44     parser.add_option("-o", "--output") | 
|  | 45     parser.add_option("-s", "--script_path") | 
|  | 46     return parser.parse_args() | 
|  | 47 | 
|  | 48 | 
|  | 49 if __name__ == "__main__": | 
|  | 50     main() |