void buildtree() { long i, j, nextnode; node *p; changed = false; newtree = false; switch (how) { case arb: arbitree(); break; case use: /* Open in binary: ftell() is broken for UNIX line-endings under WIN32 */ openfile(&intree,INTREE,"input tree file", "rb",progname,intreename); names = (boolean *)Malloc(spp*sizeof(boolean)); firsttree = true; /**/ nodep = NULL; /**/ nextnode = 0; /**/ haslengths = 0; /**/ zeros = (long *)Malloc(chars*sizeof(long)); /**/ for (i = 0; i < chars; i++) /**/ zeros[i] = 0; /**/ treeread(intree, &root, treenode, &goteof, &firsttree, nodep, &nextnode, &haslengths, &grbg, initdolmovenode,false,nonodes); for (i = spp; i < (nonodes); i++) { p = treenode[i]; for (j = 1; j <= 3; j++) { p->stateone = (bitptr)Malloc(words*sizeof(long)); p->statezero = (bitptr)Malloc(words*sizeof(long)); p = p->next; } } /* debug: see comment at initdolmovenode() */ /*treeread(which, ch, &root, treenode, names);*/ for (i = 0; i < (spp); i++) in_tree[i] = names[i]; free(names); FClose(intree); break; case spec: yourtree(); break; } outgrno = root->next->back->index; if (in_tree[outgrno - 1]) reroot(treenode[outgrno - 1]); } /* buildtree */
void setup_environment(Char *argv[], boolean *canbeplotted) { boolean firsttree; char* treestr; /* Set up all kinds of fun stuff */ #ifdef MAC OSErr retcode; FInfo fndrinfo; macsetup("Drawgram","Preview"); #endif #ifdef TURBOC if ((registerbgidriver(EGAVGA_driver) <0) || (registerbgidriver(Herc_driver) <0) || (registerbgidriver(CGA_driver) <0)){ printf("Graphics error: %s ",grapherrormsg(graphresult())); exit(-1);} #endif printf("DRAWGRAM from PHYLIP version %s\n",VERSION); printf("Reading tree ... \n"); firsttree = true; treestr = ajStrGetuniquePtr(&phylotrees[0]->Tree); allocate_nodep(&nodep, treestr, &spp); treeread (&treestr, &root, treenode, &goteof, &firsttree, nodep, &nextnode, &haslengths, &grbg, initdrawgramnode,true,-1); root->oldlen = 0.0; printf("Tree has been read.\n"); printf("Loading the font .... \n"); loadfont(font,argv[0]); printf("Font loaded.\n"); previewing = false; ansi = ANSICRT; ibmpc = IBMCRT; firstscreens = true; initialparms(); (*canbeplotted) = false; } /* setup_environment */
void maketree() { /* constructs a binary tree from the pointers in treenode. adds each node at location which yields highest "likelihood" then rearranges the tree for greatest "likelihood" */ long i, j, nextnode; double gotlike; node *item, *nufork, *dummy, *p; char *treestr; fullset = (1L << (bits + 1)) - (1L << 1); if (!usertree) { for (i = 1; i <= (spp); i++) enterorder[i - 1] = i; if (jumble) randumize(seed, enterorder); root = treenode[enterorder[0] - 1]; add(treenode[enterorder[0] - 1], treenode[enterorder[1] - 1], treenode[spp], &root, treenode); if (progress) { printf("Adding species:\n"); writename(0, 2, enterorder); #ifdef WIN32 phyFillScreenColor(); #endif } lastrearr = false; for (i = 3; i <= (spp); i++) { bestyet = -350.0 * spp * chars; item = treenode[enterorder[i - 1] - 1]; nufork = treenode[spp + i - 2]; addpreorder(root, item, nufork); add(there, item, nufork, &root, treenode); like = bestyet; rearrange(&root); if (progress) { writename(i - 1, 1, enterorder); #ifdef WIN32 phyFillScreenColor(); #endif } lastrearr = (i == spp); if (lastrearr) { if (progress) { printf("\nDoing global rearrangements\n"); printf(" !"); for (j = 1; j <= (nonodes); j++) if ( j % (( nonodes / 72 ) + 1 ) == 0 ) putchar('-'); printf("!\n"); #ifdef WIN32 phyFillScreenColor(); #endif } bestlike = bestyet; if (jumb == 1) { bstlike2 = bestlike; nextree = 1; } do { if (progress) printf(" "); gotlike = bestlike; for (j = 0; j < (nonodes); j++) { bestyet = - 350.0 * spp * chars; item = treenode[j]; if (item != root) { nufork = treenode[j]->back; re_move(&item, &nufork, &root, treenode); there = root; addpreorder(root, item, nufork); add(there, item, nufork, &root, treenode); } if (progress) { if ( j % (( nonodes / 72 ) + 1 ) == 0 ) putchar('.'); fflush(stdout); } } if (progress) { putchar('\n'); #ifdef WIN32 phyFillScreenColor(); #endif } } while (bestlike > gotlike); } } if (progress) putchar('\n'); for (i = spp - 1; i >= 1; i--) re_move(&treenode[i], &dummy, &root, treenode); if (jumb == njumble) { if (treeprint) { putc('\n', outfile); if (nextree == 2) fprintf(outfile, "One most parsimonious tree found:\n"); else fprintf(outfile, "%6ld trees in all found\n", nextree - 1); } if (nextree > maxtrees + 1) { if (treeprint) fprintf(outfile, "here are the first%4ld of them\n", (long)maxtrees); nextree = maxtrees + 1; } if (treeprint) putc('\n', outfile); for (i = 0; i <= (nextree - 2); i++) { root = treenode[0]; add(treenode[0], treenode[1], treenode[spp], &root, treenode); for (j = 3; j <= spp; j++) { add(treenode[bestrees[i].btree[j - 1] - 1], treenode[j - 1], treenode[spp + j - 2], &root, treenode);} evaluate(root); printree(1.0, treeprint, root); describe(); for (j = 1; j < (spp); j++) re_move(&treenode[j], &dummy, &root, treenode); } } } else { if (numtrees > 2) { emboss_initseed(inseed, &inseed0, seed); printf("\n"); } if (treeprint) { fprintf(outfile, "User-defined tree"); if (numtrees > 1) putc('s', outfile); fprintf(outfile, ":\n"); } names = (boolean *)Malloc(spp*sizeof(boolean)); which = 1; firsttree = true; /**/ nodep = NULL; /**/ nextnode = 0; /**/ haslengths = 0; /**/ phirst = 0; /**/ zeros = (long *)Malloc(chars*sizeof(long)); /**/ for (i = 0; i < chars; i++) /**/ zeros[i] = 0; /**/ while (which <= numtrees) { treestr = ajStrGetuniquePtr(&phylotrees[which-1]->Tree); treeread(&treestr, &root, treenode, &goteof, &firsttree, nodep, &nextnode, &haslengths, &grbg, initdollopnode,false,nonodes); for (i = spp; i < (nonodes); i++) { p = treenode[i]; for (j = 1; j <= 3; j++) { p->stateone = (bitptr)Malloc(words*sizeof(long)); p->statezero = (bitptr)Malloc(words*sizeof(long)); p = p->next; } } /* debug: see comment at initdollopnode() */ if (treeprint) fprintf(outfile, "\n\n"); evaluate(root); printree(1.0, treeprint, root); describe(); which++; } FClose(intree); fprintf(outfile, "\n\n"); if (numtrees > 1 && chars > 1) standev(numtrees, minwhich, minsteps, nsteps, fsteps, seed); free(names); } if (jumb == njumble) { if (progress) { printf("Output written to file \"%s\"\n\n", outfilename); if (trout) printf("Trees also written onto file \"%s\"\n\n", outtreename); } if (ancseq) freegarbage(&garbage); } } /* maketree */