comparison draw_variants.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 8997f2ca8c7a
children ea52b23f1141
comparison
equal deleted inserted replaced
30:4188853b940b 31:a631c2f6d913
4 import sys 4 import sys
5 from Population import Population 5 from Population import Population
6 6
7 ################################################################################ 7 ################################################################################
8 8
9 if len(sys.argv) != 10: 9 def load_pop(file, wrapped_dict):
10 gd_util.die('Usage') 10 if file == '/dev/null':
11 pop = None
12 else:
13 pop = Population()
14 pop.from_wrapped_dict(wrapped_dict)
15 return pop
11 16
12 snp_input, indel_input, coverage_input, annotation_input, indiv_input, ref_name, min_coverage, output, ind_arg = sys.argv[1:] 17 def append_tags(the_list, p, p_type, val):
13 18 if p is None:
14 p_total = Population() 19 return
15 p_total.from_wrapped_dict(ind_arg) 20 for tag in p.tag_list():
16 21 column, name = tag.split(':')
17 p1 = Population() 22 if p_type == 'gd_genotype':
18 p1.from_population_file(indiv_input) 23 column = int(column) - 2
19 if not p_total.is_superset(p1): 24 the_list.append('{0}:{1}:{2}'.format(val, column, name))
20 gd_util.die('There is an individual in the population individuals that is not in the SNP table')
21 25
22 ################################################################################ 26 ################################################################################
23 27
24 prog = 'mk_Ji' 28 if len(sys.argv) != 11:
29 gd_util.die('Usage')
30
31
32 snp_file, snp_ext, snp_arg, indiv_input, annotation_input, cov_file, cov_ext, cov_arg, min_coverage, output = sys.argv[1:]
33
34 p_snp = load_pop(snp_file, snp_arg)
35 p_cov = load_pop(cov_file, cov_arg)
36
37 if indiv_input == '/dev/null':
38 if p_snp is not None:
39 p_ind = p_snp
40 elif p_cov is not None:
41 p_ind = p_cov
42 else:
43 p_ind = None
44 order_p_ind = True
45 else:
46 p_ind = Population()
47 p_ind.from_population_file(indiv_input)
48 order_p_ind = False
49
50 ## p ind must be from either p_snp or p_cov
51 if p_snp is not None and p_cov is not None:
52 if not (p_snp.is_superset(p_ind) or p_cov.is_superset(p_ind)):
53 gd_util.die('There is an individual in the population individuals that is not in the SNP/Genotype or Coverage table')
54 elif p_snp is not None:
55 if not p_snp.is_superset(p_ind):
56 gd_util.die('There is an individual in the population individuals that is not in the SNP/Genotype table')
57 elif p_cov is not None:
58 if not p_cov.is_superset(p_ind):
59 gd_util.die('There is an individual in the population individuals that is not in the Coverage table')
60
61
62 ################################################################################
63
64 prog = 'mito_draw'
25 65
26 args = [ prog ] 66 args = [ prog ]
27 args.append(snp_input) 67 args.append(snp_file)
28 args.append(indel_input) 68 args.append(cov_file)
29 args.append(coverage_input)
30 args.append(annotation_input) 69 args.append(annotation_input)
31 args.append(min_coverage) 70 args.append(min_coverage)
32 args.append(ref_name)
33 71
34 for tag in p1.tag_list(): 72 if order_p_ind:
35 args.append(tag) 73 for column in sorted(p_ind.column_list()):
74 individual = p_ind.individual_with_column(column)
75 name = individual.name.split()[0]
76 args.append('{0}:{1}:{2}'.format(0, column, name))
77 else:
78 append_tags(args, p_ind, 'gd_indivs', 0)
36 79
37 with open('mk_Ji.out', 'w') as fh: 80 append_tags(args, p_snp, snp_ext, 1)
81 append_tags(args, p_cov, cov_ext, 2)
82
83 with open('Ji.spec', 'w') as fh:
38 gd_util.run_program(prog, args, stdout=fh) 84 gd_util.run_program(prog, args, stdout=fh)
39 85
40 ################################################################################ 86 ################################################################################
41 87
42 prog = 'varplot' 88 prog = 'varplot'
46 args.append(3) 92 args.append(3)
47 args.append('-s') 93 args.append('-s')
48 args.append(0.3) 94 args.append(0.3)
49 args.append('-g') 95 args.append('-g')
50 args.append(0.2) 96 args.append(0.2)
51 args.append('mk_Ji.out') 97 args.append('Ji.spec')
52 98
53 with open(output, 'w') as fh: 99 with open('Ji.svg', 'w') as fh:
54 gd_util.run_program(prog, args, stdout=fh) 100 gd_util.run_program(prog, args, stdout=fh)
55 101
102 ################################################################################
103
104 prog = 'convert'
105
106 args = [ prog ]
107 args.append('-density')
108 args.append(100)
109 args.append('Ji.svg')
110 args.append('tiff:{0}'.format(output))
111
112 gd_util.run_program(prog, args)
56 sys.exit(0) 113 sys.exit(0)