1 | #include "include.hxx" |
---|
2 | |
---|
3 | extern void ph_view_matrix_cb(AW_window *); |
---|
4 | |
---|
5 | |
---|
6 | #define CHECK_NAN(x) if ( (!(x>=0.0)) && (!(x<0.0)) ) *(int *)0=0; |
---|
7 | |
---|
8 | |
---|
9 | static AP_smatrix *global_ratematrix = 0; |
---|
10 | |
---|
11 | |
---|
12 | void set_globel_r_m_value(AW_root *aw_root, long i, long j) { |
---|
13 | char buffer[256]; |
---|
14 | sprintf(buffer,"phyl/ratematrix/val_%li_%li",i,j); |
---|
15 | global_ratematrix->set(i,j,aw_root->awar(buffer)->read_float()); |
---|
16 | } |
---|
17 | |
---|
18 | void create_matrix_variables(AW_root *aw_root, AW_default def) |
---|
19 | { |
---|
20 | aw_root->awar_string( "tmp/dummy_string","0",def); |
---|
21 | |
---|
22 | |
---|
23 | aw_root->awar_string( "phyl/which_species","marked",def); |
---|
24 | aw_root->awar_string( "phyl/alignment","",def); |
---|
25 | |
---|
26 | aw_root->awar_string( "phyl/filter/alignment","none",def); |
---|
27 | aw_root->awar_string( "phyl/filter/name","none",def); |
---|
28 | aw_root->awar_string( "phyl/filter/filter","",def); |
---|
29 | |
---|
30 | aw_root->awar_string( "phyl/weights/name","none",def); |
---|
31 | aw_root->awar_string( "phyl/weights/alignment","none",def); |
---|
32 | |
---|
33 | aw_root->awar_string( "phyl/rates/name","none",def); |
---|
34 | aw_root->awar_string( "phyl/cancel/chars",".",def); |
---|
35 | aw_root->awar_string( "phyl/correction/transformation","none",def); |
---|
36 | |
---|
37 | aw_root->awar("phyl/filter/alignment")->map("phyl/alignment"); |
---|
38 | aw_root->awar("phyl/weights/alignment")->map("phyl/alignment"); |
---|
39 | |
---|
40 | aw_root->awar_string( "tmp/phyl/save_matrix/file_name", "infile", def); |
---|
41 | aw_root->awar_string( "tmp/phyl/save_matrix/directory", ".", def); |
---|
42 | aw_root->awar_string( "tmp/phyl/save_matrix/filter", "", def); |
---|
43 | |
---|
44 | aw_root->awar_string( "phyl/tree/tree_name","tree_temp",def); |
---|
45 | |
---|
46 | aw_root->awar_float( "phyl/alpha",1.0,def); |
---|
47 | |
---|
48 | global_ratematrix = new AP_smatrix(AP_MAX); |
---|
49 | |
---|
50 | long i,j; |
---|
51 | for (i=0; i <AP_MAX; i++){ |
---|
52 | for (j=0; j <AP_MAX; j++){ |
---|
53 | if (i!=j) global_ratematrix->set(i,j,1.0); |
---|
54 | } |
---|
55 | } |
---|
56 | for (i=AP_A; i <AP_MAX; i*=2){ |
---|
57 | for (j = AP_A; j < i; j*=2){ |
---|
58 | char buffer[256]; |
---|
59 | sprintf(buffer,"phyl/ratematrix/val_%li_%li",i,j); |
---|
60 | aw_root->awar_float(buffer, 1.0, def); |
---|
61 | aw_root->awar(buffer)->add_callback((AW_RCB)set_globel_r_m_value,(AW_CL)i,(AW_CL)j); |
---|
62 | } |
---|
63 | } |
---|
64 | } |
---|
65 | |
---|
66 | |
---|
67 | |
---|
68 | |
---|
69 | void ph_calculate_matrix_cb(AW_window *aww,AW_CL cb1,AW_CL cb2) |
---|
70 | { AWUSE(cb1); AWUSE(cb2); |
---|
71 | char *cancel,*transformation; |
---|
72 | |
---|
73 | if(!PHDATA::ROOT) |
---|
74 | { aw_message("data_base not opened !!"); |
---|
75 | return; |
---|
76 | } |
---|
77 | AW_root *aw_root = aww->get_root(); |
---|
78 | |
---|
79 | PH_TRANSFORMATION trans = PH_TRANSFORMATION_NONE; |
---|
80 | // transformation = aw_root->awar("phyl/correction/transformation")->read_string(); |
---|
81 | transformation=strdup(PH_TRANSFORMATION_JUKES_CANTOR_STRING); |
---|
82 | |
---|
83 | // double alpha = aw_root->awar("phyl/alpha")->read_float(); |
---|
84 | double alpha = 1.0; |
---|
85 | cancel = aw_root->awar("phyl/cancel/chars")->read_string(); |
---|
86 | printf("\ntransformation: %s",transformation); |
---|
87 | printf("\ncancel: %s\n",cancel); |
---|
88 | if (!strcmp(transformation,PH_TRANSFORMATION_JUKES_CANTOR_STRING)) |
---|
89 | trans = PH_TRANSFORMATION_JUKES_CANTOR; |
---|
90 | else if (!strcmp(transformation,PH_TRANSFORMATION_KIMURA_STRING)) |
---|
91 | trans = PH_TRANSFORMATION_KIMURA; |
---|
92 | else if (!strcmp(transformation,PH_TRANSFORMATION_TAJIMA_NEI_STRING)) |
---|
93 | trans = PH_TRANSFORMATION_TAJIMA_NEI; |
---|
94 | else if (!strcmp(transformation,PH_TRANSFORMATION_TAJIMA_NEI_PAIRWISE_STRING)) |
---|
95 | trans = PH_TRANSFORMATION_TAJIMA_NEI_PAIRWISE; |
---|
96 | else if (!strcmp(transformation,PH_TRANSFORMATION_BANDELT_STRING)) |
---|
97 | trans = PH_TRANSFORMATION_BANDELT; |
---|
98 | else if (!strcmp(transformation,PH_TRANSFORMATION_BANDELT_JC_STRING)) |
---|
99 | trans = PH_TRANSFORMATION_BANDELT_JC; |
---|
100 | else if (!strcmp(transformation,PH_TRANSFORMATION_BANDELT2_STRING)) |
---|
101 | trans = PH_TRANSFORMATION_BANDELT2; |
---|
102 | else if (!strcmp(transformation,PH_TRANSFORMATION_BANDELT2_JC_STRING)) |
---|
103 | trans = PH_TRANSFORMATION_BANDELT2_JC; |
---|
104 | |
---|
105 | GB_ERROR error = PHDATA::ROOT->calculate_matrix(".-",alpha,trans); |
---|
106 | |
---|
107 | if (error) aw_message(error); |
---|
108 | delete transformation; |
---|
109 | delete cancel; |
---|
110 | if(!error) ph_view_matrix_cb(aww); // call callback directly to see what you did |
---|
111 | } |
---|
112 | |
---|
113 | void ph_save_matrix_cb(AW_window *aww) |
---|
114 | { // save the matrix |
---|
115 | if (!PHDATA::ROOT) return; |
---|
116 | PHDATA::ROOT->print(); |
---|
117 | char *filename = aww->get_root()->awar("tmp/phyl/save_matrix/file_name")->read_string(); |
---|
118 | GB_ERROR error = PHDATA::ROOT->save(filename); |
---|
119 | delete filename; |
---|
120 | if (error) aw_message(error); |
---|
121 | aww->hide(); |
---|
122 | } |
---|
123 | |
---|
124 | AW_window *create_save_matrix_window(AW_root *aw_root, char *base_name) |
---|
125 | { |
---|
126 | AW_window_simple *aws = new AW_window_simple; |
---|
127 | aws->init( aw_root, "SAVE_MATRIX", "SAVE MATRIX TO DISC", 10, 10 ); |
---|
128 | aws->load_xfig("sel_box.fig"); |
---|
129 | |
---|
130 | aws->at("close");aws->callback((AW_CB0)AW_POPDOWN); |
---|
131 | aws->create_button("CLOSE","CLOSE","C"); |
---|
132 | |
---|
133 | aws->at("save");aws->callback(ph_save_matrix_cb); |
---|
134 | aws->create_button("SAVE","SAVE","S"); |
---|
135 | |
---|
136 | aws->callback( (AW_CB0)AW_POPDOWN); |
---|
137 | aws->at("cancel"); |
---|
138 | aws->create_button("CANCEL","CANCEL","C"); |
---|
139 | |
---|
140 | awt_create_selection_box((AW_window *)aws,base_name); |
---|
141 | |
---|
142 | return (AW_window *)aws; |
---|
143 | } |
---|
144 | |
---|
145 | |
---|
146 | AW_window *awt_create_select_cancel_window(AW_root *aw_root) |
---|
147 | { |
---|
148 | AW_window_simple *aws = new AW_window_simple; |
---|
149 | aws->init( aw_root, "CANCEL_SELECT", "CANCEL SELECT", 10, 10 ); |
---|
150 | aws->load_xfig("phylo/cancel.fig"); |
---|
151 | |
---|
152 | aws->at("close");aws->callback((AW_CB0)AW_POPDOWN); |
---|
153 | aws->create_button("CLOSE","CLOSE","C"); |
---|
154 | |
---|
155 | aws->at("cancel"); |
---|
156 | aws->create_input_field("phyl/cancel/chars",12); |
---|
157 | |
---|
158 | return (AW_window *)aws; |
---|
159 | } |
---|
160 | |
---|
161 | |
---|
162 | |
---|
163 | |
---|
164 | AW_window *create_matrix_window(AW_root *aw_root) |
---|
165 | { AW_window_simple *aws = new AW_window_simple; |
---|
166 | aws->init( aw_root, "DISTANCE_TABLE", "DistanceTable", 10, 10 ); |
---|
167 | aws->load_xfig("phylo/matrix.fig"); |
---|
168 | aws->button_length( 10 ); |
---|
169 | |
---|
170 | aws->at("close");aws->callback((AW_CB0)AW_POPDOWN); |
---|
171 | aws->create_button("CLOSE","CLOSE","C"); |
---|
172 | |
---|
173 | aws->at("point_opts"); |
---|
174 | aws->create_option_menu("phyl/matrix/point","'.' in column ","0"); // "0": no shortcut |
---|
175 | aws->insert_option("forget pair for distancematrix","0",0); |
---|
176 | aws->insert_option("use distancetable","0",1); |
---|
177 | aws->update_option_menu(); |
---|
178 | |
---|
179 | aws->at("minus_opts"); |
---|
180 | aws->create_option_menu("phyl/matrix/minus","'-' in column ","0"); |
---|
181 | aws->insert_option("forget pair for distancematrix","0",0); |
---|
182 | aws->insert_option("use distancetable","0",1); |
---|
183 | aws->update_option_menu(); |
---|
184 | |
---|
185 | aws->at("rest_opts"); |
---|
186 | aws->create_option_menu("phyl/matrix/rest","rest in column ","0"); |
---|
187 | aws->insert_option("forget pair for distancematrix","0",0); |
---|
188 | aws->insert_option("use distancetable","0",1); |
---|
189 | aws->update_option_menu(); |
---|
190 | |
---|
191 | aws->at("lower_opts"); |
---|
192 | aws->create_option_menu("phyl/matrix/lower","'acgtu' in column ","0"); |
---|
193 | aws->insert_option("forget pair for distancematrix","0",0); |
---|
194 | aws->insert_option("use distancetable","0",1); |
---|
195 | aws->update_option_menu(); |
---|
196 | |
---|
197 | return (AW_window *)aws; |
---|
198 | } |
---|