1 | /* |
---|
2 | |
---|
3 | PHYML : a program that computes maximum likelihood phyLOGenies from |
---|
4 | DNA or AA homoLOGous sequences |
---|
5 | |
---|
6 | Copyright (C) Stephane Guindon. Oct 2003 onward |
---|
7 | |
---|
8 | All parts of the source except where indicated are distributed under |
---|
9 | the GNU public licence. See http://www.opensource.org for details. |
---|
10 | |
---|
11 | */ |
---|
12 | |
---|
13 | #include "draw.h" |
---|
14 | |
---|
15 | |
---|
16 | void DR_Draw_Tree(char *file_name, t_tree *tree) |
---|
17 | { |
---|
18 | FILE *ps_tree; |
---|
19 | |
---|
20 | ps_tree = (FILE *)fopen(file_name,"w"); |
---|
21 | DR_Print_Postscript_Header(1,ps_tree); |
---|
22 | tree->ps_tree = DR_Make_Tdraw_Struct(tree); |
---|
23 | DR_Init_Tdraw_Struct(tree->ps_tree); |
---|
24 | DR_Get_Tree_Box_Width(tree->ps_tree,tree); |
---|
25 | Dist_To_Root(tree->n_root,tree); |
---|
26 | tree->ps_tree->max_dist_to_root = DR_Get_Max_Dist_To_Root(tree); |
---|
27 | DR_Get_X_Coord(NO,tree->ps_tree,tree); |
---|
28 | DR_Get_Y_Coord(NO,tree->ps_tree,tree); |
---|
29 | DR_Print_Tree_Postscript(1,NO,ps_tree,tree); |
---|
30 | DR_Print_Postscript_EOF(ps_tree); |
---|
31 | fclose(ps_tree); |
---|
32 | } |
---|
33 | |
---|
34 | ////////////////////////////////////////////////////////////// |
---|
35 | ////////////////////////////////////////////////////////////// |
---|
36 | |
---|
37 | |
---|
38 | void DR_Get_Tree_Coord(t_tree *tree) |
---|
39 | { |
---|
40 | DR_Init_Tdraw_Struct(tree->ps_tree); |
---|
41 | DR_Get_Tree_Box_Width(tree->ps_tree,tree); |
---|
42 | if(!tree->n_root) |
---|
43 | { |
---|
44 | PhyML_Printf("\n. Adding root before rendering the tree."); |
---|
45 | Add_Root(tree->a_edges[0],tree); |
---|
46 | } |
---|
47 | Dist_To_Root(tree->n_root,tree); |
---|
48 | tree->ps_tree->max_dist_to_root = DR_Get_Max_Dist_To_Root(tree); |
---|
49 | DR_Get_X_Coord(NO,tree->ps_tree,tree); |
---|
50 | DR_Get_Y_Coord(NO,tree->ps_tree,tree); |
---|
51 | } |
---|
52 | |
---|
53 | ////////////////////////////////////////////////////////////// |
---|
54 | ////////////////////////////////////////////////////////////// |
---|
55 | |
---|
56 | |
---|
57 | void DR_Print_Postscript_Header(int n_pages, FILE *fp) |
---|
58 | { |
---|
59 | if(!fp) |
---|
60 | { |
---|
61 | PhyML_Printf("\n. Failed to open the postscript file."); |
---|
62 | PhyML_Printf("\n. Did you forget the '--ps' option ?."); |
---|
63 | Warn_And_Exit("\n"); |
---|
64 | } |
---|
65 | |
---|
66 | PhyML_Fprintf(fp,"%%!PS-Adobe-3.0\n"); |
---|
67 | PhyML_Fprintf(fp,"%%%%BoundingBox: 40 40 560 820\n"); |
---|
68 | PhyML_Fprintf(fp,"%%%%DocumentFonts: Times-Roman Times-Roman\n"); |
---|
69 | PhyML_Fprintf(fp,"%%%%Creator: Stephane Guindon\n"); |
---|
70 | PhyML_Fprintf(fp,"%%%%Title: tree\n"); |
---|
71 | PhyML_Fprintf(fp,"%%%%BeginFeature: *PageSize\n"); |
---|
72 | PhyML_Fprintf(fp,"a4\n"); |
---|
73 | PhyML_Fprintf(fp,"%%%%EndFeature\n"); |
---|
74 | PhyML_Fprintf(fp,"%%%%EndComments\n"); |
---|
75 | PhyML_Fprintf(fp,"%%%%Pages: %d\n",n_pages); |
---|
76 | |
---|
77 | PhyML_Fprintf(fp,"/lt {lineto} bind def\n"); |
---|
78 | PhyML_Fprintf(fp,"/mt {moveto} bind def\n"); |
---|
79 | PhyML_Fprintf(fp,"/sc {setrgbcolor} bind def\n"); |
---|
80 | PhyML_Fprintf(fp,"/ct {curveto} bind def\n"); |
---|
81 | PhyML_Fprintf(fp,"/np {newpath} bind def\n"); |
---|
82 | PhyML_Fprintf(fp,"/cp {closepath} bind def\n"); |
---|
83 | PhyML_Fprintf(fp,"/gs {gsave} bind def\n"); |
---|
84 | PhyML_Fprintf(fp,"/gr {grestore} bind def\n"); |
---|
85 | |
---|
86 | PhyML_Fprintf(fp,"/Times-Roman findfont\n"); |
---|
87 | PhyML_Fprintf(fp,"14 scalefont\n"); |
---|
88 | PhyML_Fprintf(fp,"setfont\n"); |
---|
89 | |
---|
90 | PhyML_Fprintf(fp,"/clipbox\n"); |
---|
91 | PhyML_Fprintf(fp,"{\n"); |
---|
92 | PhyML_Fprintf(fp,"newpath\n"); |
---|
93 | PhyML_Fprintf(fp,"40 40 mt\n"); |
---|
94 | PhyML_Fprintf(fp,"560 40 lt\n"); |
---|
95 | PhyML_Fprintf(fp,"560 820 lt\n"); |
---|
96 | PhyML_Fprintf(fp,"40 820 lt\n"); |
---|
97 | PhyML_Fprintf(fp,"40 40 lt\n"); |
---|
98 | PhyML_Fprintf(fp,"closepath\n"); |
---|
99 | PhyML_Fprintf(fp,"clip\n"); |
---|
100 | PhyML_Fprintf(fp,"} bind def\n"); |
---|
101 | |
---|
102 | } |
---|
103 | |
---|
104 | ////////////////////////////////////////////////////////////// |
---|
105 | ////////////////////////////////////////////////////////////// |
---|
106 | |
---|
107 | |
---|
108 | void DR_Print_Postscript_EOF(FILE *fp) |
---|
109 | { |
---|
110 | PhyML_Fprintf(fp,"%%%%Trailer\n"); |
---|
111 | PhyML_Fprintf(fp,"%%%%EOF\n"); |
---|
112 | } |
---|
113 | |
---|
114 | ////////////////////////////////////////////////////////////// |
---|
115 | ////////////////////////////////////////////////////////////// |
---|
116 | |
---|
117 | |
---|
118 | void DR_Print_Tree_Postscript(int page_num, int render_name, FILE *fp, t_tree *tree) |
---|
119 | { |
---|
120 | tdraw *draw; |
---|
121 | t_node *n_root; |
---|
122 | |
---|
123 | draw = tree->ps_tree; |
---|
124 | /* DR_Get_Tree_Coord(tree); */ |
---|
125 | n_root = tree->n_root; |
---|
126 | |
---|
127 | /* PhyML_Fprintf(fp,"%%%%Page: %d %d\n",page_num,page_num); */ |
---|
128 | PhyML_Fprintf(fp,"0.001 setlinewidth\n"); |
---|
129 | /* PhyML_Fprintf(fp,"0.5 0.5 0.4 sc\n"); */ |
---|
130 | PhyML_Fprintf(fp,"0 0 0 sc\n"); |
---|
131 | /* PhyML_Fprintf(fp,"clipbox\n"); */ |
---|
132 | /* PhyML_Fprintf(fp,"stroke\n"); */ |
---|
133 | PhyML_Fprintf(fp,"0 0 translate\n"); |
---|
134 | PhyML_Fprintf(fp,"newpath\n"); |
---|
135 | |
---|
136 | |
---|
137 | draw->ycoord[n_root->num] = (draw->ycoord[n_root->v[2]->num] + draw->ycoord[n_root->v[1]->num])/2.; |
---|
138 | draw->xcoord[n_root->num] = 0.0; |
---|
139 | DR_Print_Tree_Postscript_Pre(n_root,n_root->v[2],render_name,fp,draw,tree); |
---|
140 | DR_Print_Tree_Postscript_Pre(n_root,n_root->v[1],render_name,fp,draw,tree); |
---|
141 | |
---|
142 | |
---|
143 | PhyML_Fprintf(fp,"closepath\n"); |
---|
144 | PhyML_Fprintf(fp,"0 0 translate\n"); |
---|
145 | PhyML_Fprintf(fp,"stroke\n"); |
---|
146 | PhyML_Fprintf(fp,"showpage\n"); |
---|
147 | } |
---|
148 | |
---|
149 | ////////////////////////////////////////////////////////////// |
---|
150 | ////////////////////////////////////////////////////////////// |
---|
151 | |
---|
152 | |
---|
153 | void DR_Print_Tree_Postscript_Pre(t_node *a, t_node *d, int render_name, FILE *fp, tdraw *w, t_tree *tree) |
---|
154 | { |
---|
155 | int i; |
---|
156 | phydbl R, G, B; |
---|
157 | |
---|
158 | R = G = B = 0.0; |
---|
159 | |
---|
160 | PhyML_Fprintf(fp,"gs\n"); |
---|
161 | |
---|
162 | PhyML_Fprintf(fp,"%.1f %.1f mt\n",w->xcoord[a->num],w->ycoord[a->num]); |
---|
163 | |
---|
164 | /* PhyML_Fprintf(fp,"%.1f %.1f lt\n",w->xcoord[a->num],w->ycoord[d->num]); */ |
---|
165 | /* PhyML_Fprintf(fp,"%.1f %.1f lt\n",w->xcoord[d->num],w->ycoord[d->num]); */ |
---|
166 | |
---|
167 | phydbl min,max,step,val; |
---|
168 | |
---|
169 | min = 0.0; |
---|
170 | max = 4.; |
---|
171 | |
---|
172 | step = (max-min)/13.; |
---|
173 | |
---|
174 | /* val = tree->rates->mean_r[d->num] / (phydbl)(tree->mcmc->run/tree->mcmc->sample_interval+1.); */ |
---|
175 | /* val = tree->rates->mean_r[d->num]; */ |
---|
176 | /* val = tree->rates->has_survived[d->num]; */ |
---|
177 | /* if(val > 0.5) {R=1.; G=.0; B=0.;} */ |
---|
178 | val = 0.; |
---|
179 | |
---|
180 | if(val <= min+1.*step) |
---|
181 | {R=.0; G=1.; B=1.;} |
---|
182 | else if(val > min+1.*step && val <= min+2.*step) |
---|
183 | {R=.0; G=1.; B=.8;} |
---|
184 | else if(val > min+2.*step && val <= min+3.*step) |
---|
185 | {R=.0; G=1.; B=.5;} |
---|
186 | else if(val > min+3.*step && val <= min+4.*step) |
---|
187 | {R=.0; G=1.; B=.3;} |
---|
188 | else if(val > min+4.*step && val <= min+5.*step) |
---|
189 | {R=.0; G=1.; B=.0;} |
---|
190 | else if(val > min+5.*step && val <= min+6.*step) |
---|
191 | {R=.25; G=1.; B=0.;} |
---|
192 | else if(val > min+6.*step && val <= min+7.*step) |
---|
193 | {R=.5; G=1.; B=0.;} |
---|
194 | else if(val > min+7.*step && val <= min+8.*step) |
---|
195 | {R=.75; G=1.; B=.0;} |
---|
196 | else if(val > min+8.*step && val <= min+9.*step) |
---|
197 | {R=1.; G=1.; B=.0;} |
---|
198 | else if(val > min+9.*step && val <= min+10.*step) |
---|
199 | {R=1.; G=.75; B=.0;} |
---|
200 | else if(val > min+10.*step && val <= min+11.*step) |
---|
201 | {R=1.; G=.5; B=.0;} |
---|
202 | else if(val > min+11.*step && val <= min+12.*step) |
---|
203 | {R=1.; G=.25; B=.0;} |
---|
204 | else if(val > min+12.*step) |
---|
205 | {R=1.; G=.0; B=0.;} |
---|
206 | |
---|
207 | |
---|
208 | R = 0.; G = 0.; B = 0.; |
---|
209 | |
---|
210 | PhyML_Fprintf(fp,"%.1f %.1f lt\n",w->xcoord[a->num],w->ycoord[d->num]); |
---|
211 | PhyML_Fprintf(fp,"%.1f %.1f lt\n",w->xcoord[d->num],w->ycoord[d->num]); |
---|
212 | |
---|
213 | /* PhyML_Fprintf(fp,"%.1f %.1f %.1f %.1f %.1f %.1f ct\n", */ |
---|
214 | /* w->xcoord[a->num], */ |
---|
215 | /* w->ycoord[d->num], */ |
---|
216 | /* w->xcoord[d->num], */ |
---|
217 | /* w->ycoord[d->num], */ |
---|
218 | /* w->xcoord[d->num], */ |
---|
219 | /* w->ycoord[d->num]); */ |
---|
220 | |
---|
221 | |
---|
222 | if(tree->rates->has_survived[d->num] == YES) |
---|
223 | { |
---|
224 | PhyML_Fprintf(fp," /Helvetica findfont 16 scalefont\n"); |
---|
225 | PhyML_Fprintf(fp,"setfont\n"); |
---|
226 | PhyML_Fprintf(fp,"%.1f %.1f mt\n",w->xcoord[d->num]-5,w->ycoord[d->num]); |
---|
227 | PhyML_Fprintf(fp,"0 0 0 sc\n"); |
---|
228 | PhyML_Fprintf(fp,"(*) show \n"); |
---|
229 | } |
---|
230 | |
---|
231 | PhyML_Fprintf(fp,"%f %f %f sc\n",R,G,B); |
---|
232 | |
---|
233 | if(d->tax) |
---|
234 | { |
---|
235 | PhyML_Fprintf(fp,"stroke\n"); |
---|
236 | PhyML_Fprintf(fp,"0 setgray\n"); |
---|
237 | PhyML_Fprintf(fp,"0.1 setlinewidth\n"); |
---|
238 | PhyML_Fprintf(fp,"np %.1f %.1f 1 0 360 arc cp\n",w->xcoord[d->num],w->ycoord[d->num]); |
---|
239 | PhyML_Fprintf(fp,"%.1f %.1f %.1f sc fill\n",R,G,B); |
---|
240 | /* PhyML_Fprintf(fp,"%f setgray fill\n",greylevel); */ |
---|
241 | PhyML_Fprintf(fp,"0 0 0 sc\n"); |
---|
242 | |
---|
243 | |
---|
244 | PhyML_Fprintf(fp," /Helvetica findfont 10 scalefont\n"); |
---|
245 | PhyML_Fprintf(fp,"setfont\n"); |
---|
246 | PhyML_Fprintf(fp,"%.1f %.1f mt\n",w->xcoord[d->num]+2,w->ycoord[d->num]-6); |
---|
247 | /* PhyML_Fprintf(fp,"(%d) show \n",d->num); */ |
---|
248 | PhyML_Fprintf(fp,"(%s) show \n",d->name); |
---|
249 | PhyML_Fprintf(fp," /Helvetica findfont 14 scalefont\n"); |
---|
250 | PhyML_Fprintf(fp,"setfont\n"); |
---|
251 | |
---|
252 | |
---|
253 | PhyML_Fprintf(fp,"%.1f %.1f mt\n",w->xcoord[d->num] - (w->xcoord[d->num] - w->xcoord[a->num])/2.,w->ycoord[d->num]); |
---|
254 | PhyML_Fprintf(fp," /Helvetica findfont 10 scalefont\n"); |
---|
255 | PhyML_Fprintf(fp,"setfont\n"); |
---|
256 | PhyML_Fprintf(fp,"([%4.4f,%4.4f]) show \n", |
---|
257 | tree->geo->ldscape[tree->geo->loc[d->num]*tree->geo->n_dim+0], |
---|
258 | tree->geo->ldscape[tree->geo->loc[d->num]*tree->geo->n_dim+1]); |
---|
259 | |
---|
260 | |
---|
261 | |
---|
262 | /* PhyML_Fprintf(fp,"%.1f %.1f mt\n",w->xcoord[d->num]+5,w->ycoord[d->num]); */ |
---|
263 | /* PhyML_Fprintf(fp,"(%.10s) show \n",d->name); */ |
---|
264 | |
---|
265 | |
---|
266 | /* if(render_name) */ |
---|
267 | /* { */ |
---|
268 | /* if(tree->io->long_tax_names) */ |
---|
269 | /* PhyML_Fprintf(fp,"(%s) show \n",tree->io->long_tax_names[d->num]); */ |
---|
270 | /* else */ |
---|
271 | /* PhyML_Fprintf(fp,"(%s) show \n",d->name); */ |
---|
272 | /* } */ |
---|
273 | |
---|
274 | PhyML_Fprintf(fp,"stroke\n"); |
---|
275 | PhyML_Fprintf(fp,"gr\n"); |
---|
276 | PhyML_Fprintf(fp,"0 0 0 sc\n"); |
---|
277 | return; |
---|
278 | } |
---|
279 | else |
---|
280 | { |
---|
281 | PhyML_Fprintf(fp,"stroke\n"); |
---|
282 | PhyML_Fprintf(fp,"0 setgray\n"); |
---|
283 | PhyML_Fprintf(fp,"0.1 setlinewidth\n"); |
---|
284 | PhyML_Fprintf(fp,"np %.1f %.1f 1 0 360 arc cp\n",w->xcoord[d->num],w->ycoord[d->num]); |
---|
285 | PhyML_Fprintf(fp,"%.1f %.1f %.1f sc fill\n",R,G,B); |
---|
286 | /* PhyML_Fprintf(fp,"%f setgray fill\n",greylevel); */ |
---|
287 | PhyML_Fprintf(fp,"0 0 0 sc\n"); |
---|
288 | |
---|
289 | PhyML_Fprintf(fp," /Helvetica findfont 10 scalefont\n"); |
---|
290 | PhyML_Fprintf(fp,"setfont\n"); |
---|
291 | PhyML_Fprintf(fp,"%.1f %.1f mt\n",w->xcoord[d->num]+2,w->ycoord[d->num]); |
---|
292 | /* PhyML_Fprintf(fp,"(%d) show \n",d->num); */ |
---|
293 | PhyML_Fprintf(fp,"%.1f %.1f mt\n",w->xcoord[d->num],w->ycoord[d->num]); |
---|
294 | PhyML_Fprintf(fp," /Helvetica findfont 14 scalefont\n"); |
---|
295 | PhyML_Fprintf(fp,"setfont\n"); |
---|
296 | |
---|
297 | |
---|
298 | PhyML_Fprintf(fp,"%.1f %.1f mt\n",w->xcoord[d->num] - (w->xcoord[d->num] - w->xcoord[a->num])/2.,w->ycoord[d->num]); |
---|
299 | PhyML_Fprintf(fp," /Helvetica findfont 10 scalefont\n"); |
---|
300 | PhyML_Fprintf(fp,"setfont\n"); |
---|
301 | PhyML_Fprintf(fp,"([%4.4f,%4.4f]) show \n", |
---|
302 | tree->geo->ldscape[tree->geo->loc[d->num]*tree->geo->n_dim+0], |
---|
303 | tree->geo->ldscape[tree->geo->loc[d->num]*tree->geo->n_dim+1]); |
---|
304 | |
---|
305 | |
---|
306 | |
---|
307 | PhyML_Fprintf(fp,"stroke\n"); |
---|
308 | PhyML_Fprintf(fp,"gr\n"); |
---|
309 | PhyML_Fprintf(fp,"0 0 0 sc\n"); |
---|
310 | For(i,3) |
---|
311 | if(d->v[i] != a && d->b[i] != tree->e_root) DR_Print_Tree_Postscript_Pre(d,d->v[i],render_name,fp,w,tree); |
---|
312 | } |
---|
313 | |
---|
314 | |
---|
315 | |
---|
316 | |
---|
317 | return; |
---|
318 | } |
---|
319 | |
---|
320 | ////////////////////////////////////////////////////////////// |
---|
321 | ////////////////////////////////////////////////////////////// |
---|
322 | |
---|
323 | |
---|
324 | void DR_Get_X_Coord_Pre(t_node *a, t_node *d, t_edge *b, tdraw *w, int fixed_tips, t_tree *tree) |
---|
325 | { |
---|
326 | int i; |
---|
327 | |
---|
328 | if(!(d->tax && fixed_tips == YES)) w->xcoord[d->num] = d->dist_to_root * (phydbl)w->tree_box_width/w->max_dist_to_root; |
---|
329 | |
---|
330 | if(d->tax) return; |
---|
331 | else |
---|
332 | { |
---|
333 | For(i,3) |
---|
334 | if((d->v[i] != a) && (d->b[i] != tree->e_root)) |
---|
335 | DR_Get_X_Coord_Pre(d,d->v[i],d->b[i],w,fixed_tips,tree); |
---|
336 | } |
---|
337 | } |
---|
338 | |
---|
339 | ////////////////////////////////////////////////////////////// |
---|
340 | ////////////////////////////////////////////////////////////// |
---|
341 | |
---|
342 | |
---|
343 | void DR_Get_X_Coord(int fixed_tips, tdraw *w, t_tree *tree) |
---|
344 | { |
---|
345 | if(!(tree->n_root->v[2]->tax && fixed_tips == YES)) w->xcoord[tree->n_root->v[2]->num] = tree->n_root->v[2]->dist_to_root * (phydbl)w->tree_box_width/w->max_dist_to_root; |
---|
346 | if(!(tree->n_root->v[1]->tax && fixed_tips == YES)) w->xcoord[tree->n_root->v[1]->num] = tree->n_root->v[1]->dist_to_root * (phydbl)w->tree_box_width/w->max_dist_to_root; |
---|
347 | DR_Get_X_Coord_Pre(tree->n_root,tree->n_root->v[2],NULL,w,fixed_tips,tree); |
---|
348 | DR_Get_X_Coord_Pre(tree->n_root,tree->n_root->v[1],NULL,w,fixed_tips,tree); |
---|
349 | w->xcoord[tree->n_root->num] = 0; |
---|
350 | } |
---|
351 | |
---|
352 | |
---|
353 | ////////////////////////////////////////////////////////////// |
---|
354 | ////////////////////////////////////////////////////////////// |
---|
355 | |
---|
356 | |
---|
357 | void DR_Get_Y_Coord(int fixed_tips, tdraw *w, t_tree *tree) |
---|
358 | { |
---|
359 | phydbl next_y_slot; |
---|
360 | next_y_slot = .0; |
---|
361 | DR_Get_Y_Coord_Post(tree->n_root,tree->n_root->v[2],NULL,&next_y_slot,fixed_tips,w,tree); |
---|
362 | DR_Get_Y_Coord_Post(tree->n_root,tree->n_root->v[1],NULL,&next_y_slot,fixed_tips,w,tree); |
---|
363 | w->ycoord[tree->n_root->num] = (int)((w->ycoord[tree->n_root->v[2]->num] + w->ycoord[tree->n_root->v[2]->num]) / 2.); |
---|
364 | } |
---|
365 | |
---|
366 | ////////////////////////////////////////////////////////////// |
---|
367 | ////////////////////////////////////////////////////////////// |
---|
368 | |
---|
369 | |
---|
370 | void DR_Get_Y_Coord_Post(t_node *a, t_node *d, t_edge *b, phydbl *next_y_slot, int fixed_tips, tdraw *w, t_tree *tree) |
---|
371 | { |
---|
372 | int i; |
---|
373 | |
---|
374 | if(d->tax) |
---|
375 | { |
---|
376 | if(!fixed_tips) |
---|
377 | { |
---|
378 | /* w->ycoord[d->num] = *next_y_slot + (int)(w->page_height / (2.*tree->n_otu)); */ |
---|
379 | w->ycoord[d->num] = *next_y_slot; |
---|
380 | (*next_y_slot) += ((phydbl)w->page_height / (phydbl)tree->n_otu); |
---|
381 | } |
---|
382 | } |
---|
383 | else |
---|
384 | { |
---|
385 | int d1, d2; |
---|
386 | |
---|
387 | d1 = d2 = -1; |
---|
388 | For(i,3) |
---|
389 | { |
---|
390 | if(d->v[i] != a && d->b[i] != tree->e_root) |
---|
391 | { |
---|
392 | DR_Get_Y_Coord_Post(d,d->v[i],d->b[i],next_y_slot,fixed_tips,w,tree); |
---|
393 | if(d1<0) d1 = i; |
---|
394 | else d2 = i; |
---|
395 | } |
---|
396 | } |
---|
397 | w->ycoord[d->num] = (w->ycoord[d->v[d1]->num] + w->ycoord[d->v[d2]->num])/2.; |
---|
398 | } |
---|
399 | } |
---|
400 | |
---|
401 | ////////////////////////////////////////////////////////////// |
---|
402 | ////////////////////////////////////////////////////////////// |
---|
403 | |
---|
404 | |
---|
405 | tdraw *DR_Make_Tdraw_Struct(t_tree *tree) |
---|
406 | { |
---|
407 | tdraw *w; |
---|
408 | |
---|
409 | w = (tdraw *)mCalloc(1,sizeof(tdraw)); |
---|
410 | w->xcoord = (phydbl *)mCalloc(2*tree->n_otu-1,sizeof(phydbl)); |
---|
411 | w->ycoord = (phydbl *)mCalloc(2*tree->n_otu-1,sizeof(phydbl)); |
---|
412 | w->xcoord_s = (phydbl *)mCalloc(2*tree->n_otu-1,sizeof(phydbl)); |
---|
413 | w->ycoord_s = (phydbl *)mCalloc(2*tree->n_otu-1,sizeof(phydbl)); |
---|
414 | w->cdf_mat = (int *)mCalloc((2*tree->n_otu-2)*(2*tree->n_otu-2),sizeof(int)); |
---|
415 | w->cdf_mat_x = (phydbl *)mCalloc(2*tree->n_otu-1,sizeof(phydbl)); |
---|
416 | w->cdf_mat_y = (phydbl *)mCalloc(2*tree->n_otu-1,sizeof(phydbl)); |
---|
417 | |
---|
418 | return w; |
---|
419 | } |
---|
420 | |
---|
421 | ////////////////////////////////////////////////////////////// |
---|
422 | ////////////////////////////////////////////////////////////// |
---|
423 | |
---|
424 | |
---|
425 | void DR_Init_Tdraw_Struct(tdraw *w) |
---|
426 | { |
---|
427 | w->page_width = 510; |
---|
428 | w->page_height = 760; |
---|
429 | } |
---|
430 | |
---|
431 | ////////////////////////////////////////////////////////////// |
---|
432 | ////////////////////////////////////////////////////////////// |
---|
433 | |
---|
434 | |
---|
435 | void DR_Get_Tree_Box_Width(tdraw *w, t_tree *tree) |
---|
436 | { |
---|
437 | int i; |
---|
438 | int max_name_len, curr_len; |
---|
439 | |
---|
440 | max_name_len = curr_len = 0; |
---|
441 | For(i,tree->n_otu) |
---|
442 | { |
---|
443 | curr_len = (int)strlen(tree->a_nodes[i]->name); |
---|
444 | if(curr_len > max_name_len) max_name_len = curr_len; |
---|
445 | } |
---|
446 | |
---|
447 | w->tree_box_width = w->page_width - max_name_len * 8.66667; |
---|
448 | } |
---|
449 | |
---|
450 | ////////////////////////////////////////////////////////////// |
---|
451 | ////////////////////////////////////////////////////////////// |
---|
452 | |
---|
453 | |
---|
454 | phydbl DR_Get_Max_Dist_To_Root(t_tree *tree) |
---|
455 | { |
---|
456 | phydbl mx; |
---|
457 | int i; |
---|
458 | |
---|
459 | mx = .0; |
---|
460 | For(i,tree->n_otu) |
---|
461 | { |
---|
462 | if(tree->a_nodes[i]->dist_to_root > mx) |
---|
463 | { |
---|
464 | mx = tree->a_nodes[i]->dist_to_root; |
---|
465 | } |
---|
466 | } |
---|
467 | |
---|
468 | return mx; |
---|
469 | } |
---|
470 | |
---|
471 | ////////////////////////////////////////////////////////////// |
---|
472 | ////////////////////////////////////////////////////////////// |
---|
473 | |
---|
474 | void DR_Get_Tree_Coord_Scaled(tdraw *w, t_tree *tree) |
---|
475 | { |
---|
476 | int i; |
---|
477 | int max_x,min_x; |
---|
478 | int max_y,min_y; |
---|
479 | |
---|
480 | max_x = -INT_MAX; |
---|
481 | min_x = INT_MAX; |
---|
482 | |
---|
483 | For(i,2*tree->n_otu-1) |
---|
484 | { |
---|
485 | if(w->xcoord[i] > max_x) max_x = w->xcoord[i]; |
---|
486 | if(w->xcoord[i] < min_x) min_x = w->xcoord[i]; |
---|
487 | } |
---|
488 | |
---|
489 | max_y = -INT_MAX; |
---|
490 | min_y = INT_MAX; |
---|
491 | |
---|
492 | For(i,2*tree->n_otu-1) |
---|
493 | { |
---|
494 | if(w->ycoord[i] > max_y) max_y = w->ycoord[i]; |
---|
495 | if(w->ycoord[i] < min_y) min_y = w->ycoord[i]; |
---|
496 | } |
---|
497 | |
---|
498 | |
---|
499 | For(i,2*tree->n_otu-1) |
---|
500 | { |
---|
501 | w->xcoord_s[i] = (phydbl)(w->xcoord[i] - min_x) / (max_x - min_x); |
---|
502 | w->ycoord_s[i] = (phydbl)(w->ycoord[i] - min_y) / (max_y - min_y); |
---|
503 | } |
---|
504 | } |
---|
505 | |
---|
506 | ////////////////////////////////////////////////////////////// |
---|
507 | ////////////////////////////////////////////////////////////// |
---|
508 | |
---|
509 | void DR_Get_Cdf_Mat(t_tree *tree) |
---|
510 | { |
---|
511 | int i,j,k; |
---|
512 | phydbl min_x,max_x,y; |
---|
513 | phydbl x_mat,y_mat; |
---|
514 | t_node *d, *a; |
---|
515 | phydbl eps; |
---|
516 | |
---|
517 | eps = 1.E-6; |
---|
518 | |
---|
519 | For(i,2*tree->n_otu-1) tree->ps_tree->cdf_mat_x[i] = tree->ps_tree->xcoord_s[i]; |
---|
520 | For(i,2*tree->n_otu-1) tree->ps_tree->cdf_mat_y[i] = tree->ps_tree->ycoord_s[i]; |
---|
521 | |
---|
522 | Qksort(tree->ps_tree->cdf_mat_x,NULL,0,2*tree->n_otu-2); |
---|
523 | Qksort(tree->ps_tree->cdf_mat_y,NULL,0,2*tree->n_otu-2); |
---|
524 | |
---|
525 | For(i,2*tree->n_otu-2) /* x coordinates */ |
---|
526 | { |
---|
527 | For(j,2*tree->n_otu-2) /* y coordinates */ |
---|
528 | { |
---|
529 | For(k,2*tree->n_otu-2) /* all nodes in the tree */ |
---|
530 | { |
---|
531 | d = tree->a_nodes[k]; |
---|
532 | a = tree->a_nodes[k]->anc; |
---|
533 | |
---|
534 | min_x = tree->ps_tree->xcoord_s[a->num]; |
---|
535 | max_x = tree->ps_tree->xcoord_s[d->num]; |
---|
536 | |
---|
537 | y = tree->ps_tree->ycoord_s[d->num]; |
---|
538 | |
---|
539 | x_mat = tree->ps_tree->cdf_mat_x[i]; |
---|
540 | y_mat = tree->ps_tree->cdf_mat_y[j]; |
---|
541 | |
---|
542 | /* printf("\n. x_mat=%.1f ymat=%.1f min=%.1f max=%.1f y=%.1f", */ |
---|
543 | /* x_mat,y_mat,min_x,max_x,y); */ |
---|
544 | |
---|
545 | if((min_x < x_mat + eps) && (max_x > x_mat) && (y > y_mat)) |
---|
546 | { |
---|
547 | tree->ps_tree->cdf_mat[j*(2*tree->n_otu-2)+i] += 1; |
---|
548 | /* PhyML_Printf("\n. Add 1 to [%.1f,%.1f]", */ |
---|
549 | /* tree->ps_tree->cdf_mat_x[i], */ |
---|
550 | /* tree->ps_tree->cdf_mat_y[j]); */ |
---|
551 | } |
---|
552 | } |
---|
553 | } |
---|
554 | } |
---|
555 | } |
---|
556 | |
---|
557 | ////////////////////////////////////////////////////////////// |
---|
558 | ////////////////////////////////////////////////////////////// |
---|
559 | |
---|
560 | ////////////////////////////////////////////////////////////// |
---|
561 | ////////////////////////////////////////////////////////////// |
---|
562 | |
---|
563 | ////////////////////////////////////////////////////////////// |
---|
564 | ////////////////////////////////////////////////////////////// |
---|
565 | |
---|
566 | ////////////////////////////////////////////////////////////// |
---|
567 | ////////////////////////////////////////////////////////////// |
---|
568 | |
---|
569 | ////////////////////////////////////////////////////////////// |
---|
570 | ////////////////////////////////////////////////////////////// |
---|
571 | |
---|
572 | ////////////////////////////////////////////////////////////// |
---|
573 | ////////////////////////////////////////////////////////////// |
---|
574 | |
---|
575 | ////////////////////////////////////////////////////////////// |
---|
576 | ////////////////////////////////////////////////////////////// |
---|
577 | |
---|
578 | ////////////////////////////////////////////////////////////// |
---|
579 | ////////////////////////////////////////////////////////////// |
---|
580 | |
---|
581 | ////////////////////////////////////////////////////////////// |
---|
582 | ////////////////////////////////////////////////////////////// |
---|
583 | |
---|
584 | ////////////////////////////////////////////////////////////// |
---|
585 | ////////////////////////////////////////////////////////////// |
---|
586 | |
---|