4 /* version 3.6. (c) Copyright 1993-2004 by the University of Washington.
5 Written by Joseph Felsenstein, Hisashi Horino,
6 Akiko Fuseki, Dan Fineman, Sean Lamont, and Andrew Keeffe.
8 to copy and use this program provided no fee is charged for it and
9 provided that this copyright notice is not removed. */
12 /* The following extern's refer to things declared in cons.c */
14 extern int tree_pairing;
16 extern Char outfilename[FNMLNGTH], intreename[FNMLNGTH], intree2name[FNMLNGTH], outtreename[FNMLNGTH];
19 extern long numopts, outgrno, col;
20 extern long maxgrp; /* max. no. of groups in all trees found */
22 extern boolean trout, firsttree, noroot, outgropt, didreroot, prntsets,
23 progress, treeprint, goteof, strict, mr, mre, ml;
24 extern pointarray nodep; /* pointers to all nodes in tree */
25 extern group_type **grouping, **grping2, **group2;/* to store groups found */
26 extern long **order, **order2, lasti;
27 extern group_type *fullset;
30 extern double trweight, ntrees, mlfrac;
33 /* function prototypes */
34 void getoptions(void);
35 void count_siblings(node **p);
37 /* function prototypes */
43 /* interactively set options */
44 long loopcount, loopcount2;
48 /* Initial settings */
56 /* This is needed so functions in cons.c work */
57 tree_pairing = NO_PAIRING ;
59 fprintf(outfile, "\nConsensus tree");
60 fprintf(outfile, " program, version %s\n\n", VERSION);
78 printf("\nConsensus tree");
79 printf(" program, version %s\n\n", VERSION);
80 printf("Settings for this run:\n");
81 printf(" C Consensus type (MRe, strict, MR, Ml):");
85 printf(" Majority rule\n");
87 printf(" Majority rule (extended)\n");
90 else printf(" Adams\n");
92 printf(" O Outgroup root:");
94 printf(" Yes, at species number%3ld\n", outgrno);
96 printf(" No, use as outgroup species%3ld\n", outgrno);
98 printf(" R Trees to be treated as Rooted:");
103 printf(" T Terminal type (IBM PC, ANSI, none):");
108 if (!(ibmpc || ansi))
110 printf(" 1 Print out the sets of species:");
115 printf(" 2 Print indications of progress of run: %s\n",
116 (progress ? "Yes" : "No"));
117 printf(" 3 Print out tree:");
122 printf(" 4 Write out trees onto tree file:");
128 printf("\nAre these settings correct? (type Y or the letter for one to change)\n");
130 phyFillScreenColor();
132 scanf("%c%*[^\n]", &ch);
137 if ((noroot && (ch == 'O')) || strchr("CRT1234",ch) != NULL) {
163 outgropt = !outgropt;
168 printf("Type number of the outgroup:\n");
170 phyFillScreenColor();
172 scanf("%ld%*[^\n]", &outgrno);
174 done1 = (outgrno >= 1);
176 printf("ERROR: Bad outgroup number: %ld\n", outgrno);
177 printf(" Must be greater than zero\n");
179 countup(&loopcount2, 10);
180 } while (done1 != true);
189 initterminal(&ibmpc, &ansi);
193 prntsets = !prntsets;
197 progress = !progress;
201 treeprint = !treeprint;
210 printf("Not a possible option!\n");
212 countup(&loopcount, 100);
216 printf("\nFraction (l) of times a branch must appear\n");
217 scanf("%lf%*[^\n]", &mlfrac);
219 } while ((mlfrac < 0.5) || (mlfrac > 1.0));
224 void count_siblings(node **p)
230 /* This is a leaf, */
233 tmp_node = (*p)->next;
236 for (i = 0 ; i < 1000; i++) {
237 if (tmp_node == (*p)) {
238 /* When we've gone through all the siblings, */
240 } else if (tmp_node) {
241 tmp_node = tmp_node->next;
243 /* Should this be executed? */
247 } /* count_siblings */
250 void treeout(node *p)
252 /* write out file with representation of final tree */
261 /* If we're at a node which is a leaf, figure out how long the
262 name is and print it out. */
263 for (i = 1; i <= MAXNCH; i++) {
264 if (p->nayme[i - 1] != '\0')
267 for (i = 0; i < n; i++) {
275 /* If we're at a furcation, print out the proper formatting, loop
276 through all the children, calling the procedure recursively. */
281 /* This should terminate when we've gone through all the
301 x = (double)p->deltav;
304 /* When we're all done with this tree, */
305 fprintf(outtree, ";\n");
309 /* Figure out how many characters the branch length requires: */
313 fprintf(outtree, ":%5.1f", x);
315 } else if (x >= 10.0) {
316 fprintf(outtree, ":%4.1f", x);
318 } else if (x >= 0.99) {
319 fprintf(outtree, ":%3.1f", x);
322 fprintf(outtree, ":%4.2f", x);
330 int main(int argc, Char *argv[])
332 /* Local variables added by Dan F. */
333 pattern_elm ***pattern_array;
334 double *timesseen_changes = NULL;
340 argc = 1; /* macsetup("Consense", ""); */
341 argv[0] = "Consense";
344 openfile(&intree, INTREE, "input tree file", "r", argv[0], intreename);
345 openfile(&outfile, OUTFILE, "output file", "w", argv[0], outfilename);
347 /* Initialize option-based variables, then ask for changes regarding
352 maxgrp = 32767; /* initial size of set hash table */
356 openfile(&outtree, OUTTREE, "output tree file", "w", argv[0], outtreename);
358 fprintf(outfile, "Species in order: \n\n");
360 trees_in = countsemic(&intree);
362 /* Read the tree file and put together grouping, order, and timesseen */
363 read_groups (&pattern_array, timesseen_changes, trees_in, trees_in, intree);
364 /* Compute the consensus tree. */
366 nodep = (pointarray)Malloc(2*(1+spp)*sizeof(node *));
367 for (i = 0; i < spp; i++) {
368 nodep[i] = (node *)Malloc(sizeof(node));
369 for (j = 0; j < MAXNCH; j++)
370 nodep[i]->nayme[j] = '\0';
371 strncpy(nodep[i]->nayme, nayme[i], MAXNCH);
373 for (i = spp; i < 2*(1+spp); i++)
375 consensus(pattern_array, trees_in);
380 printf("Consensus tree written to file \"%s\"\n\n", outtreename);
383 printf("Output written to file \"%s\"\n\n", outfilename);
384 for (i = 0; i < spp; i++)
386 for (i = spp; i < 2*(1 + spp); i++) {
387 if (nodep[i] != NULL) {
393 } while (p != nodep[i]);
403 fixmacfile(outfilename);
404 fixmacfile(outtreename);
409 phyRestoreConsoleAttributes();