comparison offspring_heterozygosity_pedigree.py @ 31:a631c2f6d913

Update to Miller Lab devshed revision 3c4110ffacc3
author Richard Burhans <burhans@bx.psu.edu>
date Fri, 20 Sep 2013 13:25:27 -0400
parents
children
comparison
equal deleted inserted replaced
30:4188853b940b 31:a631c2f6d913
1 #!/usr/bin/env python
2
3 import sys
4 import gd_util
5
6 from Population import Population
7
8 def load_and_check_pop(file, total_pop, name):
9 p = Population()
10 p.from_population_file(file)
11 if not total_pop.is_superset(p):
12 gd_util.die('There is an individual in the {0} that is not in the SNP table'.format(name))
13 return p
14
15 def append_breeders_from_file(the_list, filename, kind):
16 with open(filename) as fh:
17 for line in fh:
18 elems = line.split()
19 breeder = elems[0].rstrip('\r\n')
20 the_list.append('{0}:{1}'.format(kind, breeder))
21
22 ################################################################################
23
24 if len(sys.argv) != 9:
25 gd_util.die('Usage')
26
27 input, input_type, pedigree, ind_arg, founders, b1_input, b2_input, output = sys.argv[1:]
28
29 p_total = Population()
30 p_total.from_wrapped_dict(ind_arg)
31
32 f1 = load_and_check_pop(founders, p_total, 'founders')
33
34 ################################################################################
35
36 prog = 'offspring_heterozygosity2'
37
38 args = [ prog ]
39 args.append(input) # a Galaxy SNP table
40 args.append(pedigree) # a pedigree, where the SNP table is for the founders
41
42 for tag in f1.tag_list():
43 column, name = tag.split(':')
44 if type == 'gd_genotype':
45 column = int(column) - 2
46 tag = 'founder:{0}:{1}'.format(column, name)
47 args.append(tag)
48
49 append_breeders_from_file(args, b1_input, 0)
50 append_breeders_from_file(args, b2_input, 1)
51
52 with open(output, 'w') as fh:
53 gd_util.run_program(prog, args, stdout=fh)
54
55 ################################################################################
56
57 sys.exit(0)
58