Mercurial > repos > miller-lab > genome_diversity
annotate average_fst.py @ 21:d6b961721037
Miller Lab Devshed version 4c04e35b18f6
author | Richard Burhans <burhans@bx.psu.edu> |
---|---|
date | Mon, 05 Nov 2012 12:44:17 -0500 |
parents | f04f40a36cc8 |
children | 248b06e86022 |
rev | line source |
---|---|
0 | 1 #!/usr/bin/env python |
2 | |
3 import sys | |
4 import subprocess | |
5 from Population import Population | |
6 | |
7 ################################################################################ | |
8 | |
18
f04f40a36cc8
Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents:
0
diff
changeset
|
9 if len(sys.argv) < 11: |
0 | 10 print >> sys.stderr, "Usage" |
11 sys.exit(1) | |
12 | |
18
f04f40a36cc8
Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents:
0
diff
changeset
|
13 input, p1_input, p2_input, data_source, min_total_count, discard_fixed, output, shuffles, p0_input = sys.argv[1:10] |
f04f40a36cc8
Latest changes from Belinda and Cathy. Webb's updates to the Fst tools.
Richard Burhans <burhans@bx.psu.edu>
parents:
0
diff
changeset
|
14 individual_metadata = sys.argv[10:] |
0 | 15 |
16 try: | |
17 shuffle_count = int(shuffles) | |
18 except: | |
19 shuffle_count = 0 | |
20 | |
21 p_total = Population() | |
22 p_total.from_tag_list(individual_metadata) | |
23 | |
24 p1 = Population() | |
25 p1.from_population_file(p1_input) | |
26 if not p_total.is_superset(p1): | |
27 print >> sys.stderr, 'There is an individual in population 1 that is not in the SNP table' | |
28 sys.exit(1) | |
29 | |
30 p2 = Population() | |
31 p2.from_population_file(p2_input) | |
32 if not p_total.is_superset(p2): | |
33 print >> sys.stderr, 'There is an individual in population 2 that is not in the SNP table' | |
34 sys.exit(1) | |
35 | |
36 p0 = None | |
37 if shuffle_count > 0: | |
38 p0 = Population() | |
39 p0.from_population_file(p0_input) | |
40 if not p_total.is_superset(p0): | |
41 print >> sys.stderr, 'There is an individual in population 0 that is not in the SNP table' | |
42 sys.exit(1) | |
43 | |
44 ################################################################################ | |
45 | |
46 prog = 'Fst_ave' | |
47 | |
48 args = [] | |
49 args.append(prog) | |
50 args.append(input) | |
51 args.append(data_source) | |
52 args.append(min_total_count) | |
53 args.append(discard_fixed) | |
54 args.append(shuffles) | |
55 | |
56 columns = p1.column_list() | |
57 for column in columns: | |
58 args.append('{0}:1'.format(column)) | |
59 | |
60 columns = p2.column_list() | |
61 for column in columns: | |
62 args.append('{0}:2'.format(column)) | |
63 | |
64 if p0 is not None: | |
65 columns = p0.column_list() | |
66 for column in columns: | |
67 args.append('{0}:0'.format(column)) | |
68 | |
69 fh = open(output, 'w') | |
70 | |
71 #print "args:", ' '.join(args) | |
72 p = subprocess.Popen(args, bufsize=-1, stdin=None, stdout=fh, stderr=sys.stderr) | |
73 rc = p.wait() | |
74 fh.close() | |
75 | |
76 sys.exit(0) | |
77 |