annotate garli_wrapper.py @ 1:9ce35d2d9937

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