Mercurial > repos > miller-lab > genome_diversity
comparison phylogenetic_tree.py @ 24:248b06e86022
Added gd_genotype datatype. Modified tools to support new datatype.
author | Richard Burhans <burhans@bx.psu.edu> |
---|---|
date | Tue, 28 May 2013 16:24:19 -0400 |
parents | 2c498d40ecde |
children | 8997f2ca8c7a |
comparison
equal
deleted
inserted
replaced
23:66a183c44dd5 | 24:248b06e86022 |
---|---|
17 if e.errno <> errno.EEXIST: | 17 if e.errno <> errno.EEXIST: |
18 raise | 18 raise |
19 | 19 |
20 ################################################################################ | 20 ################################################################################ |
21 | 21 |
22 if len(sys.argv) < 11: | 22 # <command interpreter="python"> |
23 print >> sys.stderr, "Usage" | 23 # phylogenetic_tree.py "$input" "$output" "$output.files_path" |
24 # | |
25 # #if $input_type.choice == '0' | |
26 # "gd_snp" | |
27 # #if $input_type.data_source.choice == '0' | |
28 # "sequence_coverage" | |
29 # "$input_type.data_source.minimum_coverage" | |
30 # "$input_type.data_source.minimum_quality" | |
31 # #else if $input_type.data_source.choice == '1' | |
32 # "estimated_genotype" | |
33 # #else if $input_type.choice == '1' | |
34 # "gd_genotype" | |
35 # #end if | |
36 # | |
37 # #if $individuals.choice == '0' | |
38 # "all_individuals" | |
39 # #else if $individuals.choice == '1' | |
40 # "$individuals.p1_input" | |
41 # #end if | |
42 # | |
43 # #if ((str($input.metadata.scaffold) == str($input.metadata.ref)) and (str($input.metadata.pos) == str($input.metadata.rPos))) or (str($include_reference) == '0') | |
44 # "none" | |
45 # #else | |
46 # "$input.metadata.dbkey" | |
47 # #end if | |
48 # | |
49 # #set $draw_tree_options = ''.join(str(x) for x in [$branch_style, $scale_style, $length_style, $layout_style]) | |
50 # #if $draw_tree_options == '' | |
51 # "" | |
52 # #else | |
53 # "-$draw_tree_options" | |
54 # #end if | |
55 # | |
56 # #for $individual_name, $individual_col in zip($input.dataset.metadata.individual_names, $input.dataset.metadata.individual_columns) | |
57 # #set $arg = '%s:%s' % ($individual_col, $individual_name) | |
58 # "$arg" | |
59 # #end for | |
60 # </command> | |
61 | |
62 ################################################################################ | |
63 | |
64 # if len(sys.argv) < 11: | |
65 # print >> sys.stderr, "Usage" | |
66 # sys.exit(1) | |
67 # | |
68 # input, p1_input, output, extra_files_path, minimum_coverage, minimum_quality, dbkey, data_source, draw_tree_options = sys.argv[1:10] | |
69 # | |
70 # individual_metadata = sys.argv[10:] | |
71 # | |
72 # # note: TEST THIS | |
73 # if dbkey in ['', '?', 'None']: | |
74 # dbkey = 'none' | |
75 # | |
76 # p_total = Population() | |
77 # p_total.from_tag_list(individual_metadata) | |
78 | |
79 if len(sys.argv) < 5: | |
80 print >> sys.stderr, 'Usage' | |
24 sys.exit(1) | 81 sys.exit(1) |
25 | 82 |
26 input, p1_input, output, extra_files_path, minimum_coverage, minimum_quality, dbkey, data_source, draw_tree_options = sys.argv[1:10] | 83 input, output, extra_files_path, input_type = sys.argv[1:5] |
27 | 84 args = sys.argv[5:] |
28 individual_metadata = sys.argv[10:] | 85 |
86 data_source = '1' | |
87 minimum_coverage = '0' | |
88 minimum_quality = '0' | |
89 | |
90 if input_type == 'gd_snp': | |
91 data_source_arg = args.pop(0) | |
92 if data_source_arg == 'sequence_coverage': | |
93 data_source = '0' | |
94 minimum_coverage = args.pop(0) | |
95 minimum_quality = args.pop(0) | |
96 elif data_source_arg == 'estimated_genotype': | |
97 pass | |
98 else: | |
99 print >> sys.stderr, 'Unsupported data_source:', data_source_arg | |
100 sys.exit(1) | |
101 elif input_type == 'gd_genotype': | |
102 pass | |
103 else: | |
104 print >> sys.stderr, 'Unsupported input_type:', input_type | |
105 sys.exit(1) | |
106 | |
107 p1_input, dbkey, draw_tree_options = args[:3] | |
29 | 108 |
30 # note: TEST THIS | 109 # note: TEST THIS |
31 if dbkey in ['', '?', 'None']: | 110 if dbkey in ['', '?', 'None']: |
32 dbkey = 'none' | 111 dbkey = 'none' |
33 | 112 |
113 individual_metadata = args[3:] | |
114 | |
34 p_total = Population() | 115 p_total = Population() |
35 p_total.from_tag_list(individual_metadata) | 116 p_total.from_tag_list(individual_metadata) |
36 | |
37 | 117 |
38 ################################################################################ | 118 ################################################################################ |
39 | 119 |
40 mkdir_p(extra_files_path) | 120 mkdir_p(extra_files_path) |
41 | 121 |
86 print >> sys.stderr, 'There is an individual in the population that is not in the SNP table' | 166 print >> sys.stderr, 'There is an individual in the population that is not in the SNP table' |
87 sys.exit(1) | 167 sys.exit(1) |
88 tags = p1.tag_list() | 168 tags = p1.tag_list() |
89 | 169 |
90 for tag in tags: | 170 for tag in tags: |
171 if input_type == 'gd_genotype': | |
172 column, name = tag.split(':') | |
173 tag = '{0}:{1}'.format(int(column) - 2, name) | |
91 args.append(tag) | 174 args.append(tag) |
92 | 175 |
93 fh = open(phylip_outfile, 'w') | 176 fh = open(phylip_outfile, 'w') |
94 run_program(None, args, fh) | 177 run_program(None, args, fh) |
95 | 178 |