source: tags/arb_5.1/GDE/MOLPHY/pstree.c

Last change on this file was 1891, checked in by westram, 21 years ago
  • minor change
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.6 KB
Line 
1/*
2 * pstree.c   Adachi, J.   1996.01.13
3 * Copyright (C) 1995-1996 J. Adachi & M. Hasegawa. All rights reserved.
4 */
5
6#include "protml.h"
7
8#define OTUNUMBERING 0
9
10#if A4PAPER /* A4 size */
11#define PAPERHEIGHT 825 /* pt 840 */
12#define PAPERWIDTH  580 /* pt */
13#define TREEHEIGHT  700 /* pt */
14#define TREEWIDTH   450 /* pt */
15#else /* US letter size (no test) */
16#define PAPERHEIGHT 784 /* pt */
17#define PAPERWIDTH  596 /* pt */
18#define TREEHEIGHT  700 /* pt */
19#define TREEWIDTH   450 /* pt */
20#endif
21
22
23void
24psdicter(fp)
25FILE *fp;
26{
27        fputs("%\n/$MolphyDict 200 dict def \n", fp);
28        fputs("$MolphyDict begin\n", fp);
29        fputs("$MolphyDict /mtrx matrix put\n", fp);
30        fputs("/Fid /Helvetica-Bold def",fp);
31        fputs(" % You can change the font of species name.\n",fp);
32        fputs("/Fsc /Helvetica-BoldOblique def",fp);
33        fputs(" % You can change the font of scientific name.\n",fp);
34        fputs("/Fbp /Helvetica-Narrow def",fp);
35        fputs(" % You can change the font of bootstrap probabilities.\n",fp);
36        fputs("/FTR  /Times-Roman def\n", fp);
37        fputs("/FTB  /Times-Bold def\n", fp);
38        fputs("/FTI  /Times-Italic def\n", fp);
39        fputs("/FTBI /Times-BoldItalic def\n", fp);
40        fputs("/FH   /Helvetica def\n", fp);
41        fputs("/FHB  /Helvetica-Bold def\n", fp);
42        fputs("/FHO  /Helvetica-Oblique def\n", fp);
43        fputs("/FHBO /Helvetica-BoldOblique def\n", fp);
44        fputs("/FHN  /Helvetica-Narrow def\n", fp);
45        fputs("/FS   /Symbol def\n", fp);
46        fputs("/FBDI /Bookman-DemiItalic def\n", fp);
47        fputs("/FNCSI /NewCenturySchlbk-Italic def\n", fp);
48        fputs("/ff {findfont} bind def\n", fp);
49        fputs("/sf {scalefont setfont} bind def\n", fp);
50        fputs("/l  {lineto} bind def\n", fp);
51        fputs("/m  {moveto} bind def\n", fp);
52        fputs("/rl {rlineto} bind def\n", fp);
53        fputs("/rm {rmoveto} bind def\n", fp);
54        fputs("/s  {stroke} bind def\n", fp);
55        fputs("/n  {newpath} bind def\n", fp);
56        fputs("/c  {closepath} bind def\n", fp);
57        fputs("/cp {charpath} bind def\n", fp);
58        fputs("/sh {show} bind def\n", fp);
59        fputs("/gs {gsave} bind def\n", fp);
60        fputs("/gr {grestore} bind def\n", fp);
61        fputs("/sg {setgray} bind def\n", fp);
62        fputs("/gc {dup dup currentrgbcolor 4 -2 roll mul 4 -2 roll\n", fp);
63        fputs("\tmul 4 -2 roll mul setrgbcolor} bind def\n", fp);
64        fputs("/CS {dup stringwidth pop neg 2 div 0 rmoveto} def\n", fp);
65        fputs("/RS {dup stringwidth pop neg 0 rmoveto} def\n", fp);
66        fputs("/RDS {dup stringwidth exch neg exch neg rmoveto} def\n", fp);
67        fputs("/BB {stringwidth pop dup neg 0 rl exch 0 exch rl 0 rl c 1 sg fill s 0 sg} def\n", fp);
68        fputs("/RR {dup stringwidth pop neg 0 rmoveto show} def\n", fp);
69#if 0
70        fputs("/BP {false charpath gsave 0 setgray fill grestore stroke} def\n", fp);
71#else
72        fputs("/BP {show} def\n", fp);
73#endif
74#if 0
75        fputs("/col0  {0 0 0 setrgbcolor} bind def\n", fp);
76        fputs("/col1  {0 0 1 setrgbcolor} bind def\n", fp);
77        fputs("/col2  {0 1 0 setrgbcolor} bind def\n", fp);
78        fputs("/col3  {0 1 1 setrgbcolor} bind def\n", fp);
79        fputs("/col4  {1 0 0 setrgbcolor} bind def\n", fp);
80        fputs("/col5  {1 0 1 setrgbcolor} bind def\n", fp);
81        fputs("/col6  {1 1 0 setrgbcolor} bind def\n", fp);
82        fputs("/col7  {1 1 1 setrgbcolor} bind def\n", fp);
83        fputs("/col8  {.68 .85  .9 setrgbcolor} bind def\n", fp);
84        fputs("/col9  {  0 .39   0 setrgbcolor} bind def\n", fp);
85        fputs("/col10 {.65 .17 .17 setrgbcolor} bind def\n", fp);
86        fputs("/col11 {  1 .51   0 setrgbcolor} bind def\n", fp);
87        fputs("/col12 {.63 .13 .94 setrgbcolor} bind def\n", fp);
88        fputs("/col13 {  1 .75  .8 setrgbcolor} bind def\n", fp);
89        fputs("/col14 { .7 .13 .13 setrgbcolor} bind def\n", fp);
90        fputs("/col15 {  1 .84   0 setrgbcolor} bind def\n", fp);
91#endif
92        fputs("end % $MolphyDict\n", fp);
93        fputs("/$MolphyBegin {$MolphyDict begin /$MolphyEnteredState save def} def\n", fp);
94        fputs("/$MolphyEnd {$MolphyEnteredState restore end} def\n", fp);
95        fputs("%%EndProlog\n%\n", fp);
96} /* psdicter */
97
98
99void
100pstree(fp, tr)
101FILE *fp;
102Tree *tr;
103{
104        Node *cp, *rp, *kp, *bp, *ap;
105        char *name, date[32];
106        int len, ns, x, xmax, xs, xsmax, s, smax, y, yi, dy, depth, maxdepth;
107        int fonts, fontc, height, width, xorigin, yorigin, db, rel, rfonts, iscale;
108        double xscale, yscale, lscale, rfonth, fontw;
109        ivector yf, yl;
110
111        fputs("%!PS-Adobe-1.0 EPSF-1.0\n", fp);
112        fputs("%%Title: (MOLPHY's tree file)\n", fp);
113        fprintf(fp, "%%%%Creator: MOLPHY Version %s by Jun Adachi\n", VERSION);
114        strftime(date, 32, "%c", localtime(&Ct0));
115        fprintf(fp, "%%%%CreationDate: %s\n", date);
116        /* fputs("%%For: Jun Adachi\n", fp); */
117        fputs("%%Orientation: Portrait\n", fp);
118
119        xscale = yscale = 1.0;
120        ns = Numspc;
121        dy = (int)(TREEHEIGHT / (ns + 3));
122        if (dy > 20) {
123                dy = 20;
124                fonts = 12;
125                rfonts = 8;
126        } else if (dy > 12) {
127                fonts = 10;
128                rfonts = 8;
129        } else if (dy > 6) {
130                fonts = dy - 1;
131                rfonts = fonts - 1;
132        } else if (dy > 4) {
133                fonts = dy;
134                rfonts = fonts - 1;
135        } else {
136                dy = 4;
137                fonts = 5;
138                rfonts = fonts - 1;
139        }
140        fontc = (int)(fonts * 2.0 / 5.0);
141        fontw = fonts * 0.5;
142        rfonts = (int)(fonts*4/5);
143        rfonth = rfonts * 0.7;
144        db = 1 + (int)(fonts/5);
145        height = y = dy * (ns + 3);
146
147        x = xsmax = depth = maxdepth = 0;
148
149        cp = rp = tr->rootp;
150        do {
151                cp = cp->isop->kinp;
152                len = (int)(cp->length * 10.0 + 0.5);
153                if (len == 0) len = 1;
154                if (cp->descen) x += len;
155                if (cp->isop == NULL) { /* external node */
156                        name = ((Sciname[cp->num] && (Sciname[cp->num][0] != '\0'))
157                    ? Sciname[cp->num] : Identif[cp->num]); /* @@@OLIVER */
158                        s    = (int)(fontw * (strlen(name) + 1) + 10);
159                        if (Engname[cp->num] && Engname[cp->num][0] != '\0') { /* @@@OLIVER */
160                                s += (int)(fontw * (strlen(Engname[cp->num]) + 1));
161                        }
162                        xs = x + s;
163                        if (xs > xsmax) {
164                                xsmax = xs;
165                                xmax  = x;
166                                smax  = s;
167                        }
168                        cp = cp->kinp;
169                } else { /* internal node */
170                        if (cp->descen) {
171                                depth++;
172                                if (depth > maxdepth) maxdepth = depth;
173                        } else {
174                                depth--;
175                        }
176                }
177                if (!cp->descen) x -= len;
178        } while (cp != rp);
179
180        lscale = (double)(TREEWIDTH - smax) / (double)xmax;
181        width = TREEWIDTH;
182        xorigin = (PAPERWIDTH  - width ) / 2;
183        yorigin = (PAPERHEIGHT - height) / 2;
184
185        fprintf(fp, "%%%%BoundingBox: %d %d %d %d\n",
186                xorigin - 5, yorigin, xorigin + width, yorigin + height);
187        fputs("%%Pages: 1\n", fp);
188        fputs("%%EndComments\n", fp);
189
190        psdicter(fp);
191
192        fputs("$MolphyBegin\n", fp);
193
194        fprintf(fp, "FTR ff 6 sf");
195        fprintf(fp, " %d %d m", PAPERWIDTH - 10, PAPERHEIGHT - 10);
196        strftime(date, 32, "%x", localtime(&Ct0));
197#ifndef NJ
198        fprintf(fp, " (%s %s %s %s %d OTUs %d sites %s) RDS sh %% COMMENT\n",
199                Prog_name, VERSION, date, Modelname, Maxspc, Numsite, Comment);
200#else
201        fprintf(fp, " (%s %s %s %d OTUs %s) RDS sh %% COMMENT\n",
202                Prog_name, VERSION, date, Numspc, Comment);
203#endif
204        fprintf(fp, "%% 0.01 setlinewidth n %d %d m %d %d l %d %d l %d %d l c s\n",
205                xorigin-5, yorigin, xorigin+width, yorigin,
206                xorigin+width, yorigin+height, xorigin-5, yorigin+height);
207
208        fprintf(fp, "%d %d translate\n", xorigin, yorigin);
209        fprintf(fp, "%.3f %.3f scale\n", xscale, yscale);
210        fprintf(fp, "%d setlinecap %d setlinejoin\n", 2, 0);
211        fprintf(fp, "%.3f setlinewidth\n", Numspc > 20 ? (0.5) : (1.0));
212        /*
213        if (Sciname[0][0] == '\0')
214                fprintf(fp, "Fid ff %d sf\n", fonts);
215        else
216                fprintf(fp, "Fsc ff %d sf\n", fonts);
217        */
218        yf = new_ivector(maxdepth + 1);
219        yl = new_ivector(maxdepth + 1);
220        x = depth = 0;
221
222        cp = rp = tr->rootp;
223        do {
224                bp = cp;
225                kp = cp->isop;
226                cp = kp->kinp;
227                len = (int)(cp->length * 10.0 * lscale + 0.5);
228                if (len == 0) len = 1;
229                if (cp->descen) x += len;
230                if (cp->isop == NULL) { /* external node */
231                        y -= dy;
232                        fprintf(fp, "n %3d %3d m %3d %3d l s ", x - len, y, x, y);
233                        fprintf(fp, "  %3d %3d m", x + (int)fontw, y-fontc);
234                        fprintf(fp, " %% %3d\n", cp->num+1);
235                        if (Sciname[cp->num]== 0 || Sciname[cp->num][0] == '\0') { /* @@@OLIVER */
236                                fprintf(fp, " Fid ff %d sf (%s) sh", fonts, Identif[cp->num]);
237                        } else {
238                                fprintf(fp, " Fsc ff %d sf (%s) sh", fonts, Sciname[cp->num]);
239                        }
240                        if (Engname[cp->num] && Engname[cp->num][0] != '\0') { /* @@@OLIVER */
241                                fprintf(fp, " Fid ff %d sf ( %s) sh\n",fonts,Engname[cp->num]);
242                        } else {
243                                fprintf(fp, "\n");
244                        }
245#if OTUNUMBERING
246                        fprintf(fp, "\t(  %d) sh %% otunumbering\n", cp->num+1);
247#endif
248                        cp = cp->kinp;
249                        if (bp->descen)       yf[depth] = y;
250                        if (cp->isop->descen) yl[depth] = y;
251                        if (cp == rp->isop)   yf[depth] = y;
252                        if (cp == rp)         yl[depth] = y;
253                } else { /* internal node */
254                        if (cp->descen) {
255                                depth++;
256                        } else {
257                                yi = (yf[depth] + yl[depth]) / 2;
258                                depth--;
259                                if (cp == rp->isop) yf[depth] = yi;
260                                if (cp == rp)       yl[depth] = yi;
261                                if (cp->isop->descen) {
262                                        yl[depth] = yi;
263                                } else {
264                                        for (ap = cp; ap->isop != cp; ap = ap->isop) ;
265                                        if (ap->descen) yf[depth] = yi;
266                                }
267                                fprintf(fp, "n %3d %3d m %3d %3d l s ", x - len, yi, x, yi);
268                                fprintf(fp, "n %3d %3d m %3d %3d l s\t%% %3d\n",
269                                        x, yf[depth+1], x, yl[depth+1], cp->num+1);
270                        }
271                }
272                if (!cp->descen) x -= len;
273        } while (cp != rp);
274        fprintf(fp, "n %3d %3d m %3d %3d l s\t%% 0\n", x, yf[depth], x, yl[depth]);
275        y -= (dy * 1.0);
276
277        if (100*lscale < 400) {
278                iscale = 100;
279        } else {
280                iscale = 10;
281        }
282        fprintf(fp, "n %3d %3d m %3d %3d l %3d %3d l %3d %3d l s\n", x,y,
283                x,y-fontc, x+(int)(iscale*lscale),y-fontc, x+(int)(iscale*lscale),y);
284        fprintf(fp, "%%\nFH ff %d sf\n", fonts);
285        fprintf(fp, "%3d %3d m (%s substitutions/site) sh\n",
286                        x, y-fontc-fonts, (iscale == 100 ? "0.1" : "0.01"));
287
288#ifndef NJ
289if (Relia_optn) {
290        fprintf(fp, "%%\nFbp ff %d sf\n", rfonts); /* /FH */
291        y = height;
292        x = depth = 0;
293        cp = rp = tr->rootp;
294        do {
295                bp = cp;
296                kp = cp->isop;
297                cp = kp->kinp;
298                len = (int)(cp->length * 10.0 * lscale + 0.5);
299                if (len == 0) len = 1;
300                if (cp->descen) x += len;
301                if (cp->isop == NULL) { /* external node */
302                        y -= dy;
303                        cp = cp->kinp;
304                        if (bp->descen)       yf[depth] = y;
305                        if (cp->isop->descen) yl[depth] = y;
306                        if (cp == rp->isop)   yf[depth] = y;
307                        if (cp == rp)         yl[depth] = y;
308                } else { /* internal node */
309                        if (cp->descen) {
310                                depth++;
311                        } else {
312                                yi = (yf[depth] + yl[depth]) / 2;
313                                depth--;
314                                if (cp == rp->isop) yf[depth] = yi;
315                                if (cp == rp)       yl[depth] = yi;
316                                if (cp->isop->descen) {
317                                        yl[depth] = yi;
318                                } else {
319                                        for (ap = cp; ap->isop != cp; ap = ap->isop) ;
320                                        if (ap->descen) yf[depth] = yi;
321                                }
322                                if (Relistat[cp->num - Maxspc] >= 0) {
323                                        rel = (int)(Reliprob[cp->num - Maxspc][0]*100.0+0.5);
324                                        fprintf(fp, "%3d %3d m %.2f (%d) BB ",
325                                                x-db, yi+db, rfonth, rel);
326                                        fprintf(fp, "%3d %3d m (%d) RR\t%% %3d\n",
327                                                x-db, yi+db, rel, cp->num+1);
328                                        /* fprintf(fp, "  %3d %3d m gs ", x-db, yi+db);
329                                        fprintf(fp, "(%d) RS BP\n", rel); */
330                                }
331                        }
332                }
333                if (!cp->descen) x -= len;
334        } while (cp != rp);
335}
336#endif /* NJ */
337
338        free_ivector(yf);
339        free_ivector(yl);
340
341        fputs("%\nshowpage\n", fp);
342        fputs("$MolphyEnd\n", fp);
343        fputs("% %%EOF\n", fp);
344
345} /* pstree */
Note: See TracBrowser for help on using the repository browser.