annotate average_fst.py @ 38:9d0b1fa77047

Changed simplejson to json
author Richard Burhans <burhans@bx.psu.edu>
date Fri, 28 Feb 2014 12:15:32 -0500
parents 8997f2ca8c7a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
1 #!/usr/bin/env python
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
2
27
8997f2ca8c7a Update to Miller Lab devshed revision bae0d3306d3b
Richard Burhans <burhans@bx.psu.edu>
parents: 24
diff changeset
3 import gd_util
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
4 import sys
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
5 from Population import Population
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
6
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
7 ################################################################################
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
8
27
8997f2ca8c7a Update to Miller Lab devshed revision bae0d3306d3b
Richard Burhans <burhans@bx.psu.edu>
parents: 24
diff changeset
9 if len(sys.argv) != 12:
8997f2ca8c7a Update to Miller Lab devshed revision bae0d3306d3b
Richard Burhans <burhans@bx.psu.edu>
parents: 24
diff changeset
10 gd_util.die('Usage')
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
11
27
8997f2ca8c7a Update to Miller Lab devshed revision bae0d3306d3b
Richard Burhans <burhans@bx.psu.edu>
parents: 24
diff changeset
12 input, p1_input, p2_input, input_type, data_source, min_total_count, discard_fixed, output, shuffles, p0_input, ind_arg = sys.argv[1:]
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
13
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
14 try:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
15 shuffle_count = int(shuffles)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
16 except:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
17 shuffle_count = 0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
18
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
19 p_total = Population()
27
8997f2ca8c7a Update to Miller Lab devshed revision bae0d3306d3b
Richard Burhans <burhans@bx.psu.edu>
parents: 24
diff changeset
20 p_total.from_wrapped_dict(ind_arg)
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
21
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
22 p1 = Population()
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
23 p1.from_population_file(p1_input)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
24 if not p_total.is_superset(p1):
27
8997f2ca8c7a Update to Miller Lab devshed revision bae0d3306d3b
Richard Burhans <burhans@bx.psu.edu>
parents: 24
diff changeset
25 gd_util.die('There is an individual in population 1 that is not in the SNP table')
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
26
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
27 p2 = Population()
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
28 p2.from_population_file(p2_input)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
29 if not p_total.is_superset(p2):
27
8997f2ca8c7a Update to Miller Lab devshed revision bae0d3306d3b
Richard Burhans <burhans@bx.psu.edu>
parents: 24
diff changeset
30 gd_util.die('There is an individual in population 2 that is not in the SNP table')
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
31
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
32 p0 = None
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
33 if shuffle_count > 0:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
34 p0 = Population()
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
35 p0.from_population_file(p0_input)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
36 if not p_total.is_superset(p0):
27
8997f2ca8c7a Update to Miller Lab devshed revision bae0d3306d3b
Richard Burhans <burhans@bx.psu.edu>
parents: 24
diff changeset
37 gd_util.die('There is an individual in population 0 that is not in the SNP table')
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
38
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
39 ################################################################################
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
40
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
41 prog = 'Fst_ave'
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
42
27
8997f2ca8c7a Update to Miller Lab devshed revision bae0d3306d3b
Richard Burhans <burhans@bx.psu.edu>
parents: 24
diff changeset
43 args = [ prog ]
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
44 args.append(input)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
45 args.append(data_source)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
46 args.append(min_total_count)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
47 args.append(discard_fixed)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
48 args.append(shuffles)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
49
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
50 columns = p1.column_list()
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
51 for column in columns:
24
248b06e86022 Added gd_genotype datatype. Modified tools to support new datatype.
Richard Burhans <burhans@bx.psu.edu>
parents: 18
diff changeset
52 if input_type == 'gd_genotype':
248b06e86022 Added gd_genotype datatype. Modified tools to support new datatype.
Richard Burhans <burhans@bx.psu.edu>
parents: 18
diff changeset
53 column = int(column) - 2
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
54 args.append('{0}:1'.format(column))
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
55
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
56 columns = p2.column_list()
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
57 for column in columns:
24
248b06e86022 Added gd_genotype datatype. Modified tools to support new datatype.
Richard Burhans <burhans@bx.psu.edu>
parents: 18
diff changeset
58 if input_type == 'gd_genotype':
248b06e86022 Added gd_genotype datatype. Modified tools to support new datatype.
Richard Burhans <burhans@bx.psu.edu>
parents: 18
diff changeset
59 column = int(column) - 2
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
60 args.append('{0}:2'.format(column))
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
61
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
62 if p0 is not None:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
63 columns = p0.column_list()
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
64 for column in columns:
24
248b06e86022 Added gd_genotype datatype. Modified tools to support new datatype.
Richard Burhans <burhans@bx.psu.edu>
parents: 18
diff changeset
65 if input_type == 'gd_genotype':
248b06e86022 Added gd_genotype datatype. Modified tools to support new datatype.
Richard Burhans <burhans@bx.psu.edu>
parents: 18
diff changeset
66 column = int(column) - 2
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
67 args.append('{0}:0'.format(column))
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
68
27
8997f2ca8c7a Update to Miller Lab devshed revision bae0d3306d3b
Richard Burhans <burhans@bx.psu.edu>
parents: 24
diff changeset
69 with open(output, 'w') as fh:
8997f2ca8c7a Update to Miller Lab devshed revision bae0d3306d3b
Richard Burhans <burhans@bx.psu.edu>
parents: 24
diff changeset
70 gd_util.run_program(prog, args, stdout=fh)
0
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
71
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
72 sys.exit(0)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
73