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

Last change on this file was 2, checked in by oldcode, 24 years ago

Initial revision

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1/*
2 * prtree.c   Adachi, J.   1995.02.05
3 * Copyright (C) 1992-1995 J. Adachi & M. Hasegawa, All rights reserved.
4 */
5
6#define PRINTLENGTH 1
7
8#include "protml.h"
9
10
11void
12putctopology(tr)
13Tree *tr;
14{
15        Node *cp, *rp;
16
17        cp = rp = tr->rootp;
18        putchar('(');
19        do {
20                cp = cp->isop->kinp;
21                if (cp->isop == NULL) { /* external node */
22                        fputs(Identif[cp->num], stdout);
23                        cp = cp->kinp;
24                } else { /* internal node */
25                        if (cp->descen)
26                                putchar('(');
27                        else
28                                putchar(')');
29                }
30                if (!cp->descen && !cp->isop->descen && cp != rp) /* not last subtree */
31                        putchar(',');
32        } while (cp != rp);
33        puts(");");
34
35} /* putctopology */
36
37
38void
39fputctopology(fp, tr)
40FILE *fp;
41Tree *tr;
42{
43        Node *cp, *rp;
44
45        cp = rp = tr->rootp;
46        putc('(', fp);
47        do {
48                cp = cp->isop->kinp;
49                if (cp->isop == NULL) { /* external node */
50                        fputs(Identif[cp->num], fp);
51                        cp = cp->kinp;
52                } else { /* internal node */
53                        if (cp->descen)
54                                putc('(', fp);
55                        else
56                                putc(')', fp);
57                }
58                if (!cp->descen && !cp->isop->descen && cp != rp) /* not last subtree */
59                        putc(',', fp);
60        } while (cp != rp);
61        fputs(");\n", fp);
62
63} /* fputctopology */
64
65
66void
67fputcphylogeny(fp, tr)
68FILE *fp;
69Tree *tr;
70{
71        Node *cp, *rp;
72        int n;
73
74        cp = rp = tr->rootp;
75        putc('(', fp);
76        n = 1;
77        do {
78                cp = cp->isop->kinp;
79                if (cp->isop == NULL) { /* external node */
80                        if (n > 60) { putc('\n', fp); n = 0; }
81                        fputs(Identif[cp->num], fp);
82                        n += strlen(Identif[cp->num]);
83                        fprintf(fp, ":%.3f", cp->length);
84                        n += 6;
85                        cp = cp->kinp;
86                } else { /* internal node */
87                        if (cp->descen) {
88                                if (n > 60) { putc('\n', fp); n = 0; }
89                                putc('(', fp);
90                                n++;
91                        } else {
92                                putc(')', fp);
93                                n++;
94                                if (n > 70) { putc('\n', fp); n = 0; }
95                                fprintf(fp, ":%.3f", cp->length);
96                                n += 6;
97                        }
98                }
99                if (!cp->descen && !cp->isop->descen && cp != rp) {
100                        putc(',', fp); /* not last subtree */
101                        n++;
102                }
103        } while (cp != rp);
104        fputs(");\n", fp);
105} /* fputcphylogeny */
106
107
108static void 
109prbranch(up, depth, m, maxm, umbrella, column)
110Node *up;
111int depth, m, maxm;
112ivector umbrella;
113ivector column;
114{
115        int i, nb, n, maxn, lim, nn;
116        Node *cp;
117        char bch;
118
119        if ((int)(up->length * Proportion) >= MAXOVER) {
120                column[depth] = MAXLENG;
121                bch = '+';
122        } else {
123                column[depth] = (int)(up->length * Proportion) + 3;
124                bch = '-';
125        }
126
127        if (up->isop == NULL) { /* external branch */
128                if (m == 1) umbrella[depth - 1] = TRUE;
129                for (i = 0; i < depth; i++) {
130                        if (umbrella[i])
131                                printf("%*c", column[i], ':');
132                        else
133                                printf("%*c", column[i], ' ');
134                }
135                if (m == maxm) umbrella[depth - 1] = FALSE;
136                for (i = 0, lim = column[depth] - 3; i < lim; i++)
137                        putchar(bch);
138                printf("-%d ", up->num + 1); /* offset */
139
140#if PRINTLENGTH
141                if (Info_optn) printf("%d ", (int)((up->length + 0.5) * 1.0));
142#endif
143                puts(Identif[up->num]);
144                return;
145        }
146
147        nb = up->num + 1; /* offset, internal branch */
148        nn = up->num - Maxspc;
149        for (cp = up->isop, maxn = 0; cp != up; cp = cp->isop, maxn++)
150                ;
151        for (cp = up->isop, n = 1; cp != up; cp = cp->isop, n++) {
152                prbranch(cp->kinp, depth + 1, n, maxn, umbrella, column);
153                if (m == 1 && n == maxn / 2) umbrella[depth - 1] = TRUE;
154                if (n != maxn) {
155                        for (i = 0; i < depth - 1; i++) {
156                                if (umbrella[i])
157                                        printf("%*c", column[i], ':');
158                                else
159                                        printf("%*c", column[i], ' ');
160                        }
161
162                        i = depth - 1;
163                        if (umbrella[i]) {
164                                if (Relia_optn && Relistat[nn] > 0)
165                                        printf("%*c", column[i], '*');
166                                else
167                                        printf("%*c", column[i], ':');
168                        } else {
169                                printf("%*c", column[i], ' ');
170                        }
171
172                        if (n == maxn / 2) { /* internal branch */
173                                if (Relia_optn  && Relistat[nn] > 0) {
174                                        for (i = 0, lim = column[depth] - 3; i < lim; i++)
175                                                putchar('*');
176                                        if (nb < 10)
177                                                printf("**%d", nb);
178                                        else if (nb < 100)
179                                                printf("*%2d", nb);
180                                        else
181                                                printf("%3d", nb);
182                                } else {
183                                        for (i = 0, lim = column[depth] - 3; i < lim; i++)
184                                                putchar(bch);
185                                        if (nb < 10)
186                                                printf("--%d", nb);
187                                        else if (nb < 100)
188                                                printf("-%2d", nb);
189                                        else
190                                                printf("%3d", nb);
191                                }
192#if PRINTLENGTH
193                                if (Info_optn) printf(" %d ", (int)((up->length + 0.5) * 1.0));
194#endif
195#if 1           
196                                if (Relia_optn) {
197                                        if (Relistat[nn] != -1) {
198                                                printf(" %.0f", Reliprob[nn][0] * 100.0);
199                                                if (Relistat[nn] > 0) {
200                                                        printf(" %.0f %d&%d", Reliprob[nn][1] * 100.0,
201                                                                Relinum[nn][0]+1, Relinum[nn][1]+1);
202                                                }
203                                        }
204                                }
205#endif
206                        } else {
207                                if (umbrella[depth])
208                                        printf("%*c", column[depth], ':');
209                                else
210                                        printf("%*c", column[depth], ' ');
211                        }
212                        putchar('\n');
213                }
214                if (m == maxm) umbrella[depth - 1] = FALSE;
215        }
216        return;
217} /*_ prbranch */
218
219
220void 
221prtopology(tr)
222Tree *tr;
223{
224        int n, maxn, depth;
225        ivector umbrella;
226        ivector column;
227        Node *cp, *rp;
228
229        umbrella = new_ivector(Numspc);
230        column = new_ivector(Numspc);
231
232        for (n = 0; n < Numspc; n++) {
233                umbrella[n] = FALSE;
234                column[n] = 3;
235        }
236        column[0] = 1;
237        rp = tr->rootp;
238        for (maxn = 1, cp = rp->isop; cp != rp; cp = cp->isop, maxn++)
239                ;
240        depth = 1;
241        n = 0;
242/*      putchar('\n'); */
243        cp = rp;
244        do {
245                cp = cp->isop;
246                n++;
247                prbranch(cp->kinp, depth, n, maxn, umbrella, column);
248                if (cp != rp) printf("%*c\n", column[0], ':');
249        } while (cp != rp);
250
251        free_ivector(umbrella);
252        free_ivector(column);
253} /*_ prtopology */
254
255
256void
257strctree(tr, ltree)
258Tree *tr;
259char *ltree;
260{
261        Node *cp, *rp;
262        char *idp;
263
264        cp = rp = tr->rootp;
265        *ltree++ = '(';
266        do {
267                cp = cp->isop->kinp;
268                if (cp->isop == NULL) { /* external node */
269                        for (idp = Identif[cp->num]; *idp != '\0'; *ltree++ = *idp++)
270                                ;
271                        cp = cp->kinp;
272                } else { /* internal node */
273                        if (cp->descen)
274                                *ltree++ = '(';
275                        else
276                                *ltree++ = ')';
277                }
278                if (!cp->descen && !cp->isop->descen && cp != rp) /* not last subtree */
279                        *ltree++ = ',';
280        } while (cp != rp);
281        *ltree++ = ')';
282        *ltree = '\0';
283} /* strctree */
Note: See TracBrowser for help on using the repository browser.