comparison diversity_pi.py @ 24:248b06e86022

Added gd_genotype datatype. Modified tools to support new datatype.
author Richard Burhans <burhans@bx.psu.edu>
date Tue, 28 May 2013 16:24:19 -0400
parents
children 8997f2ca8c7a
comparison
equal deleted inserted replaced
23:66a183c44dd5 24:248b06e86022
1 #!/usr/bin/env python
2
3 import sys
4 import subprocess
5 from Population import Population
6
7 def run_program(prog, args, stdout_file=None, space_to_tab=False):
8 #print "args: ", ' '.join(args)
9 p = subprocess.Popen(args, bufsize=-1, executable=prog, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
10 (stdoutdata, stderrdata) = p.communicate()
11 rc = p.returncode
12
13 if stdout_file is not None:
14 with open(stdout_file, 'w') as ofh:
15 lines = stdoutdata.split('\n')
16 for line in lines:
17 line = line.strip()
18 if line:
19 if space_to_tab:
20 line = line.replace(' ', '\t')
21 print >> ofh, line
22
23 if rc != 0:
24 print >> sys.stderr, "FAILED: rc={0}: {1}".format(rc, ' '.join(args))
25 print >> sys.stderr, stderrdata
26 sys.exit(1)
27
28 ################################################################################
29
30 if len(sys.argv) < 7:
31 print >> sys.stderr, "Usage"
32 sys.exit(1)
33
34 snp_input, coverage_input, indiv_input, min_coverage, output = sys.argv[1:6]
35 individual_metadata = sys.argv[6:]
36
37 p_total = Population()
38 p_total.from_tag_list(individual_metadata)
39
40 p1 = Population()
41 p1.from_population_file(indiv_input)
42 if not p_total.is_superset(p1):
43 print >> sys.stderr, 'There is an individual in the population individuals that is not in the SNP table'
44 sys.exit(1)
45
46 ################################################################################
47
48 prog = 'mt_pi'
49
50 args = [ prog ]
51
52 args.append(snp_input)
53 args.append(coverage_input)
54 args.append(min_coverage)
55
56 for tag in p1.tag_list():
57 args.append(tag)
58
59 run_program(prog, args, stdout_file=output)
60 sys.exit(0)