annotate aggregate_gd_indivs.py @ 26:91e835060ad2

Updates to Admixture, Aggregate Individuals, and Restore Attributes to support gd_genotype
author Richard Burhans <burhans@bx.psu.edu>
date Mon, 03 Jun 2013 12:29:29 -0400
parents 95a05c1ef5d5
children 8997f2ca8c7a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
1 #!/usr/bin/env python
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
2
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
3 import sys
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
4 import subprocess
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
5 from Population import Population
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
6
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
7 ################################################################################
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
8
26
91e835060ad2 Updates to Admixture, Aggregate Individuals, and Restore Attributes to support gd_genotype
Richard Burhans <burhans@bx.psu.edu>
parents: 22
diff changeset
9 if len(sys.argv) < 6:
22
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
10 print >> sys.stderr, "Usage"
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
11 sys.exit(1)
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
12
26
91e835060ad2 Updates to Admixture, Aggregate Individuals, and Restore Attributes to support gd_genotype
Richard Burhans <burhans@bx.psu.edu>
parents: 22
diff changeset
13 input, p1_input, output, input_type = sys.argv[1:5]
91e835060ad2 Updates to Admixture, Aggregate Individuals, and Restore Attributes to support gd_genotype
Richard Burhans <burhans@bx.psu.edu>
parents: 22
diff changeset
14 individual_metadata = sys.argv[5:]
22
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
15
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
16 p_total = Population()
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
17 p_total.from_tag_list(individual_metadata)
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
18
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
19 p1 = Population()
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
20 p1.from_population_file(p1_input)
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
21
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
22 if not p_total.is_superset(p1):
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
23 print >> sys.stderr, 'There is an individual in the population that is not in the SNP table'
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
24 sys.exit(1)
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
25
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
26 ################################################################################
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
27
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
28 prog = 'aggregate'
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
29
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
30 args = []
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
31 args.append(prog)
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
32 args.append(input)
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
33
26
91e835060ad2 Updates to Admixture, Aggregate Individuals, and Restore Attributes to support gd_genotype
Richard Burhans <burhans@bx.psu.edu>
parents: 22
diff changeset
34 if input_type == 'gd_snp':
91e835060ad2 Updates to Admixture, Aggregate Individuals, and Restore Attributes to support gd_genotype
Richard Burhans <burhans@bx.psu.edu>
parents: 22
diff changeset
35 args.append('1')
91e835060ad2 Updates to Admixture, Aggregate Individuals, and Restore Attributes to support gd_genotype
Richard Burhans <burhans@bx.psu.edu>
parents: 22
diff changeset
36 elif input_type == 'gd_genotype':
91e835060ad2 Updates to Admixture, Aggregate Individuals, and Restore Attributes to support gd_genotype
Richard Burhans <burhans@bx.psu.edu>
parents: 22
diff changeset
37 args.append('0')
91e835060ad2 Updates to Admixture, Aggregate Individuals, and Restore Attributes to support gd_genotype
Richard Burhans <burhans@bx.psu.edu>
parents: 22
diff changeset
38 else:
91e835060ad2 Updates to Admixture, Aggregate Individuals, and Restore Attributes to support gd_genotype
Richard Burhans <burhans@bx.psu.edu>
parents: 22
diff changeset
39 print >> sys.stderr, "unknown input type:", input_type
91e835060ad2 Updates to Admixture, Aggregate Individuals, and Restore Attributes to support gd_genotype
Richard Burhans <burhans@bx.psu.edu>
parents: 22
diff changeset
40 sys.exit(1)
91e835060ad2 Updates to Admixture, Aggregate Individuals, and Restore Attributes to support gd_genotype
Richard Burhans <burhans@bx.psu.edu>
parents: 22
diff changeset
41
22
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
42 columns = p1.column_list()
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
43
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
44 for column in sorted(columns):
26
91e835060ad2 Updates to Admixture, Aggregate Individuals, and Restore Attributes to support gd_genotype
Richard Burhans <burhans@bx.psu.edu>
parents: 22
diff changeset
45 if input_type == 'gd_genotype':
91e835060ad2 Updates to Admixture, Aggregate Individuals, and Restore Attributes to support gd_genotype
Richard Burhans <burhans@bx.psu.edu>
parents: 22
diff changeset
46 column = str(int(column) - 2)
22
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
47 args.append(column)
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
48
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
49 fh = open(output, 'w')
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
50
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
51 #print "args:", ' '.join(args)
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
52 p = subprocess.Popen(args, bufsize=-1, stdin=None, stdout=fh, stderr=sys.stderr)
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
53 rc = p.wait()
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
54 fh.close()
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
55
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
56 sys.exit(0)
95a05c1ef5d5 update to devshed revision aaece207bd01
Richard Burhans <burhans@bx.psu.edu>
parents:
diff changeset
57