1
|
1 #!/usr/bin/env python
|
|
2
|
|
3 """
|
|
4 Runs Garli-2.0 on a sequence file.
|
|
5 For use with Garli version 2.0
|
|
6
|
|
7 usage: garli_wrapper.py config_file best_tree all_trees run_log screen_log out_conf
|
|
8 """
|
|
9 import os, shutil, subprocess, sys
|
|
10
|
|
11 def stop_err(msg):
|
|
12 sys.stderr.write("%s\n" % msg)
|
|
13 sys.exit()
|
|
14
|
|
15 def __main__():
|
|
16 usage = "usage: %prog input conf btree balltree runlog scrlog outconf"
|
|
17 conf = sys.argv[1]
|
|
18 balltree = 'garli.best.all.tre'
|
|
19 btree = 'garli.best.tre'
|
|
20 runlog = 'garli.log00.log'
|
|
21 scrlog = 'garli.screen.log'
|
|
22 cmd = []
|
|
23 cmd.append('Garli-2.0')
|
|
24 cmd.append(os.path.basename(conf))
|
|
25 try:
|
|
26 proc = subprocess.Popen(args=cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
27 except Exception, err:
|
|
28 sys.stderr.write("Error invoking command: \n%s\n\n%s\n" % (cmd, err))
|
|
29 sys.exit(1)
|
|
30 stdout, stderr = proc.communicate()
|
|
31 return_code = proc.returncode
|
|
32 if return_code:
|
|
33 sys.stdout.write(stdout)
|
|
34 sys.stderr.write(stderr)
|
|
35 sys.stderr.write("Return error code %i from command:\n" % return_code)
|
|
36 sys.stderr.write("%s\n" % cmd)
|
|
37 else:
|
|
38 sys.stdout.write(stdout)
|
|
39 sys.stdout.write(stderr)
|
|
40 try:
|
|
41 shutil.copyfile(os.path.basename(conf), 'garli.conf')
|
|
42 if not os.path.exists(balltree):
|
|
43 bat = open(balltree,'w')
|
|
44 bat.write('Only a single tree was found, so this file does not have any output')
|
|
45 bat.close()
|
|
46 except Exception, err:
|
|
47 sys.stderr.write("Error copying output files: \n%s\n" % err)
|
|
48 if __name__=="__main__": __main__()
|