diff aggregate_gd_indivs.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 91e835060ad2
children
line wrap: on
line diff
--- a/aggregate_gd_indivs.py	Mon Jun 03 12:29:29 2013 -0400
+++ b/aggregate_gd_indivs.py	Mon Jul 15 10:47:35 2013 -0400
@@ -1,43 +1,38 @@
 #!/usr/bin/env python
 
+import gd_util
 import sys
-import subprocess
 from Population import Population
 
 ################################################################################
 
-if len(sys.argv) < 6:
-    print >> sys.stderr, "Usage"
-    sys.exit(1)
+if len(sys.argv) != 6:
+    gd_util.dir('Usage')
 
-input, p1_input, output, input_type  = sys.argv[1:5]
-individual_metadata = sys.argv[5:]
+input, p1_input, output, input_type, ind_arg  = sys.argv[1:]
 
 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 the population that is not in the SNP table'
-    sys.exit(1)
+    gd_util.die('There is an individual in the population that is not in the SNP table')
 
 ################################################################################
 
 prog = 'aggregate'
 
-args = []
-args.append(prog)
+args = [ prog ]
 args.append(input)
 
 if input_type == 'gd_snp':
-    args.append('1')
+    args.append(1)
 elif input_type == 'gd_genotype':
-    args.append('0')
+    args.append(0)
 else:
-    print >> sys.stderr, "unknown input type:", input_type
-    sys.exit(1)
+    die('unknown input type: {0}'.format(input_type))
 
 columns = p1.column_list()
 
@@ -46,12 +41,8 @@
         column = str(int(column) - 2)
     args.append(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)