Mercurial > repos > miller-lab > genome_diversity
comparison diversity_pi.py @ 31:a631c2f6d913
Update to Miller Lab devshed revision 3c4110ffacc3
author | Richard Burhans <burhans@bx.psu.edu> |
---|---|
date | Fri, 20 Sep 2013 13:25:27 -0400 |
parents | 8997f2ca8c7a |
children |
comparison
equal
deleted
inserted
replaced
30:4188853b940b | 31:a631c2f6d913 |
---|---|
4 import sys | 4 import sys |
5 from Population import Population | 5 from Population import Population |
6 | 6 |
7 ################################################################################ | 7 ################################################################################ |
8 | 8 |
9 if len(sys.argv) != 7: | 9 def load_pop(file, wrapped_dict): |
10 gd_util.die('Usage') | 10 if file == '/dev/null': |
11 pop = None | |
12 else: | |
13 pop = Population() | |
14 pop.from_wrapped_dict(wrapped_dict) | |
15 return pop | |
11 | 16 |
12 snp_input, coverage_input, indiv_input, min_coverage, output, ind_arg = sys.argv[1:] | 17 def append_tags(the_list, p, p_type, val): |
13 | 18 if p is None: |
14 p_total = Population() | 19 return |
15 p_total.from_wrapped_dict(ind_arg) | 20 for tag in p.tag_list(): |
16 | 21 column, name = tag.split(':') |
17 p1 = Population() | 22 if p_type == 'gd_genotype': |
18 p1.from_population_file(indiv_input) | 23 column = int(column) - 2 |
19 if not p_total.is_superset(p1): | 24 the_list.append('{0}:{1}:{2}'.format(val, column, name)) |
20 gd_util.die('There is an individual in the population individuals that is not in the SNP table') | |
21 | 25 |
22 ################################################################################ | 26 ################################################################################ |
23 | 27 |
24 prog = 'mt_pi' | 28 if len(sys.argv) != 11: |
29 gd_util.die('Usage') | |
30 | |
31 snp_input, snp_ext, snp_arg, cov_input, cov_ext, cov_arg, indiv_input, min_coverage, req_thresh, output = sys.argv[1:] | |
32 | |
33 p_snp = load_pop(snp_input, snp_arg) | |
34 p_cov = load_pop(cov_input, cov_arg) | |
35 | |
36 p_ind = Population() | |
37 p_ind.from_population_file(indiv_input) | |
38 | |
39 if not p_snp.is_superset(p_ind): | |
40 gd_util.die('There is an individual in the population individuals that is not in the SNP/Genotype table') | |
41 | |
42 if p_cov is not None and (not p_cov.is_superset(p_ind)): | |
43 gd_util.die('There is an individual in the population individuals that is not in the Coverage table') | |
44 | |
45 ################################################################################ | |
46 | |
47 prog = 'mito_pi' | |
25 | 48 |
26 args = [ prog ] | 49 args = [ prog ] |
27 args.append(snp_input) | 50 args.append(snp_input) |
28 args.append(coverage_input) | 51 args.append(cov_input) |
29 args.append(min_coverage) | 52 args.append(min_coverage) |
53 args.append(req_thresh) | |
30 | 54 |
31 for tag in p1.tag_list(): | 55 append_tags(args, p_ind, 'gd_indivs', 0) |
32 args.append(tag) | 56 append_tags(args, p_snp, snp_ext, 1) |
57 append_tags(args, p_cov, cov_ext, 2) | |
33 | 58 |
34 with open(output, 'w') as fh: | 59 with open(output, 'w') as fh: |
35 gd_util.run_program(prog, args, stdout=fh) | 60 gd_util.run_program(prog, args, stdout=fh) |
36 | 61 |
37 sys.exit(0) | 62 sys.exit(0) |