diff average_fst.py @ 27:8997f2ca8c7a

Update to Miller Lab devshed revision bae0d3306d3b
author Richard Burhans <burhans@bx.psu.edu>
date Mon, 15 Jul 2013 10:47:35 -0400
parents 248b06e86022
children
line wrap: on
line diff
--- a/average_fst.py	Mon Jun 03 12:29:29 2013 -0400
+++ b/average_fst.py	Mon Jul 15 10:47:35 2013 -0400
@@ -1,17 +1,15 @@
 #!/usr/bin/env python
 
+import gd_util
 import sys
-import subprocess
 from Population import Population
 
 ################################################################################
 
-if len(sys.argv) < 12:
-    print >> sys.stderr, "Usage"
-    sys.exit(1)
+if len(sys.argv) != 12:
+    gd_util.die('Usage')
 
-input, p1_input, p2_input, input_type, data_source, min_total_count, discard_fixed, output, shuffles, p0_input = sys.argv[1:11]
-individual_metadata = sys.argv[11:]
+input, p1_input, p2_input, input_type, data_source, min_total_count, discard_fixed, output, shuffles, p0_input, ind_arg = sys.argv[1:]
 
 try:
     shuffle_count = int(shuffles)
@@ -19,34 +17,30 @@
     shuffle_count = 0
 
 p_total = Population()
-p_total.from_tag_list(individual_metadata)
+p_total.from_wrapped_dict(ind_arg)
 
 p1 = Population()
 p1.from_population_file(p1_input)
 if not p_total.is_superset(p1):
-    print >> sys.stderr, 'There is an individual in population 1 that is not in the SNP table'
-    sys.exit(1)
+    gd_util.die('There is an individual in population 1 that is not in the SNP table')
 
 p2 = Population()
 p2.from_population_file(p2_input)
 if not p_total.is_superset(p2):
-    print >> sys.stderr, 'There is an individual in population 2 that is not in the SNP table'
-    sys.exit(1)
+    gd_util.die('There is an individual in population 2 that is not in the SNP table')
 
 p0 = None
 if shuffle_count > 0:
     p0 = Population()
     p0.from_population_file(p0_input)
     if not p_total.is_superset(p0):
-        print >> sys.stderr, 'There is an individual in population 0 that is not in the SNP table'
-        sys.exit(1)
+        gd_util.die('There is an individual in population 0 that is not in the SNP table')
 
 ################################################################################
 
 prog = 'Fst_ave'
 
-args = []
-args.append(prog)
+args = [ prog ]
 args.append(input)
 args.append(data_source)
 args.append(min_total_count)
@@ -72,12 +66,8 @@
             column = int(column) - 2
         args.append('{0}:0'.format(column))
 
-fh = open(output, 'w')
-
-#print "args:", ' '.join(args)
-p = subprocess.Popen(args, bufsize=-1, stdin=None, stdout=fh, stderr=sys.stderr)
-rc = p.wait()
-fh.close()
+with open(output, 'w') as fh:
+    gd_util.run_program(prog, args, stdout=fh)
 
 sys.exit(0)