Mercurial > repos > miller-lab > genome_diversity
annotate average_fst.py @ 25:cba0d7a63b82
workaround for gd_genotype datatype
admix shift int -> float
| author | Richard Burhans <burhans@bx.psu.edu> |
|---|---|
| date | Wed, 29 May 2013 13:49:19 -0400 |
| parents | 248b06e86022 |
| children | 8997f2ca8c7a |
| rev | line source |
|---|---|
| 0 | 1 #!/usr/bin/env python |
| 2 | |
| 3 import sys | |
| 4 import subprocess | |
| 5 from Population import Population | |
| 6 | |
| 7 ################################################################################ | |
| 8 | |
|
24
248b06e86022
Added gd_genotype datatype. Modified tools to support new datatype.
Richard Burhans <burhans@bx.psu.edu>
parents:
18
diff
changeset
|
9 if len(sys.argv) < 12: |
| 0 | 10 print >> sys.stderr, "Usage" |
| 11 sys.exit(1) | |
| 12 | |
|
24
248b06e86022
Added gd_genotype datatype. Modified tools to support new datatype.
Richard Burhans <burhans@bx.psu.edu>
parents:
18
diff
changeset
|
13 input, p1_input, p2_input, input_type, data_source, min_total_count, discard_fixed, output, shuffles, p0_input = sys.argv[1:11] |
|
248b06e86022
Added gd_genotype datatype. Modified tools to support new datatype.
Richard Burhans <burhans@bx.psu.edu>
parents:
18
diff
changeset
|
14 individual_metadata = sys.argv[11:] |
| 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: | |
|
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 | 60 args.append('{0}:1'.format(column)) |
| 61 | |
| 62 columns = p2.column_list() | |
| 63 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
|
64 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
|
65 column = int(column) - 2 |
| 0 | 66 args.append('{0}:2'.format(column)) |
| 67 | |
| 68 if p0 is not None: | |
| 69 columns = p0.column_list() | |
| 70 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
|
71 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
|
72 column = int(column) - 2 |
| 0 | 73 args.append('{0}:0'.format(column)) |
| 74 | |
| 75 fh = open(output, 'w') | |
| 76 | |
| 77 #print "args:", ' '.join(args) | |
| 78 p = subprocess.Popen(args, bufsize=-1, stdin=None, stdout=fh, stderr=sys.stderr) | |
| 79 rc = p.wait() | |
| 80 fh.close() | |
| 81 | |
| 82 sys.exit(0) | |
| 83 |
