annotate modify_snp_table.py @ 12:4b6590dd7250

Uploaded
author miller-lab
date Wed, 12 Sep 2012 17:10:26 -0400
parents 2c498d40ecde
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
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
3 import sys
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
4 import subprocess
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
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
9 if len(sys.argv) < 9:
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
10 print >> sys.stderr, "Usage"
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
11 sys.exit(1)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
12
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
13 input, p1_input, output, lo, hi, lo_ind, lo_ind_qual = sys.argv[1:8]
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
14 individual_metadata = sys.argv[8:]
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
15
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
16 p_total = Population()
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
17 p_total.from_tag_list(individual_metadata)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
18
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
19 p1 = Population()
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
20 p1.from_population_file(p1_input)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
21
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
22 if not p_total.is_superset(p1):
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
23 print >> sys.stderr, 'There is an individual in the population that is not in the SNP table'
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
24 sys.exit(1)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
25
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
26 ################################################################################
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
27
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
28 prog = 'pop'
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
29
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
30 args = []
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
31 args.append(prog)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
32 args.append(input)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
33 args.append(lo)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
34 args.append(hi)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
35 args.append(lo_ind)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
36 args.append(lo_ind_qual)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
37
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
38 columns = p1.column_list()
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
39
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
40 for column in sorted(columns):
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
41 args.append(column)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
42
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
43 fh = open(output, 'w')
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
44
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
45 #print "args:", ' '.join(args)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
46 p = subprocess.Popen(args, bufsize=-1, stdin=None, stdout=fh, stderr=sys.stderr)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
47 rc = p.wait()
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
48 fh.close()
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
49
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
50 sys.exit(0)
2c498d40ecde Uploaded
miller-lab
parents:
diff changeset
51