void getStartingTree(tree *tr, analdef *adef) { tr->likelihood = unlikely; if(adef->restart) { INFILE = myfopen(tree_file, "rb"); if(!adef->grouping) { switch(adef->mode) { case ANCESTRAL_STATES: assert(!tr->saveMemory); tr->leftRootNode = (nodeptr)NULL; tr->rightRootNode = (nodeptr)NULL; treeReadLen(INFILE, tr, FALSE, FALSE, FALSE, adef, TRUE, FALSE); assert(tr->leftRootNode && tr->rightRootNode); break; case CLASSIFY_MP: treeReadLen(INFILE, tr, TRUE, FALSE, TRUE, adef, FALSE, FALSE); break; case OPTIMIZE_BR_LEN_SCALER: treeReadLen(INFILE, tr, TRUE, FALSE, FALSE, adef, TRUE, FALSE); break; case CLASSIFY_ML: if(adef->useBinaryModelFile) { if(tr->saveMemory) treeReadLen(INFILE, tr, TRUE, FALSE, TRUE, adef, FALSE, FALSE); else treeReadLen(INFILE, tr, TRUE, FALSE, FALSE, adef, FALSE, FALSE); } else { if(tr->saveMemory) treeReadLen(INFILE, tr, FALSE, FALSE, TRUE, adef, FALSE, FALSE); else treeReadLen(INFILE, tr, FALSE, FALSE, FALSE, adef, FALSE, FALSE); } break; default: if(tr->saveMemory) treeReadLen(INFILE, tr, FALSE, FALSE, TRUE, adef, FALSE, FALSE); else treeReadLen(INFILE, tr, FALSE, FALSE, FALSE, adef, FALSE, FALSE); break; } } else { assert(adef->mode != ANCESTRAL_STATES); partCount = 0; if (! treeReadLenMULT(INFILE, tr, adef)) exit(-1); } if(adef->mode == PARSIMONY_ADDITION) return; if(adef->mode != CLASSIFY_MP) { if(adef->mode == OPTIMIZE_BR_LEN_SCALER) { assert(tr->numBranches == tr->NumberOfModels); scaleBranches(tr, TRUE); evaluateGenericInitrav(tr, tr->start); } else { evaluateGenericInitrav(tr, tr->start); treeEvaluate(tr, 1); } } fclose(INFILE); } else { assert(adef->mode != PARSIMONY_ADDITION && adef->mode != MORPH_CALIBRATOR && adef->mode != ANCESTRAL_STATES && adef->mode != OPTIMIZE_BR_LEN_SCALER); if(adef->randomStartingTree) makeRandomTree(tr, adef); else makeParsimonyTree(tr, adef); if(adef->startingTreeOnly) { printStartingTree(tr, adef, TRUE); exit(0); } else printStartingTree(tr, adef, FALSE); evaluateGenericInitrav(tr, tr->start); treeEvaluate(tr, 1); } tr->start = tr->nodep[1]; }
int main(int argc, char *argv[]) { GraphType graphType; edgefn ef; opts.pfx = ""; opts.name = ""; opts.cnt = 1; graphType = init(argc, argv, &opts); if (opts.directed) { fprintf(opts.outfile, "digraph %s{\n", opts.name); ef = dirfn; } else { fprintf(opts.outfile, "graph %s{\n", opts.name); ef = undirfn; } switch (graphType) { case grid: makeSquareGrid(opts.graphSize1, opts.graphSize2, opts.foldVal, opts.isPartial, ef); break; case circle: makeCircle(opts.graphSize1, ef); break; case path: makePath(opts.graphSize1, ef); break; case tree: if (opts.graphSize2 == 2) makeBinaryTree(opts.graphSize1, ef); else makeTree(opts.graphSize1, opts.graphSize2, ef); break; case trimesh: makeTriMesh(opts.graphSize1, ef); break; case ball: makeBall(opts.graphSize1, opts.graphSize2, ef); break; case torus: if ((opts.parm1 == 0) && (opts.parm2 == 0)) makeTorus(opts.graphSize1, opts.graphSize2, ef); else makeTwistedTorus(opts.graphSize1, opts.graphSize2, opts.parm1, opts.parm2, ef); break; case cylinder: makeCylinder(opts.graphSize1, opts.graphSize2, ef); break; case mobius: makeMobius(opts.graphSize1, opts.graphSize2, ef); break; case sierpinski: makeSierpinski(opts.graphSize1, ef); break; case complete: makeComplete(opts.graphSize1, ef); break; case randomg: makeRandom (opts.graphSize1, opts.graphSize2, ef); break; case randomt: { int i; treegen_t* tg = makeTreeGen (opts.graphSize1); for (i = 1; i <= opts.cnt; i++) { makeRandomTree (tg, ef); if (i != opts.cnt) closeOpen (); } freeTreeGen (tg); } makeRandom (opts.graphSize1, opts.graphSize2, ef); break; case completeb: makeCompleteB(opts.graphSize1, opts.graphSize2, ef); break; case hypercube: makeHypercube(opts.graphSize1, ef); break; case star: makeStar(opts.graphSize1, ef); break; case wheel: makeWheel(opts.graphSize1, ef); break; default: /* can't happen */ break; } fprintf(opts.outfile, "}\n"); exit(0); }
void getStartingTree(tree *tr, analdef *adef) { tr->likelihood = unlikely; if(adef->restart) { INFILE = myfopen(tree_file, "rb"); if(!adef->grouping) { if(tr->saveMemory) treeReadLen(INFILE, tr, FALSE, FALSE, TRUE, adef, FALSE); else treeReadLen(INFILE, tr, FALSE, FALSE, FALSE, adef, FALSE); } else { partCount = 0; if (! treeReadLenMULT(INFILE, tr, adef)) exit(-1); } if(adef->mode == PARSIMONY_ADDITION) return; { /* double t = gettime(); int i; for(i = 0; i < 50; i++) */ evaluateGenericInitrav(tr, tr->start); /* printf("%1.40f \n", tr->likelihood); printf("%f\n", gettime() - t); */ treeEvaluate(tr, 1); /* printf("%1.40f \n", tr->likelihood); printf("%f\n", gettime() - t); exit(1); */ } fclose(INFILE); } else { assert(adef->mode != PARSIMONY_ADDITION && adef->mode != MORPH_CALIBRATOR && adef->mode != MORPH_CALIBRATOR_PARSIMONY); if(adef->randomStartingTree) makeRandomTree(tr, adef); else makeParsimonyTree(tr, adef); if(adef->startingTreeOnly) { printStartingTree(tr, adef, TRUE); exit(0); } else printStartingTree(tr, adef, FALSE); setupPointerMesh(tr); evaluateGenericInitrav(tr, tr->start); treeEvaluate(tr, 1); } tr->start = tr->nodep[1]; }
int main(int argc, char * argv[]) { tree * tr; if (argc != 2) { fprintf (stderr, "syntax: %s [binary-alignment-file]\n", argv[0]); return (1); } tr = (tree *)malloc(sizeof(tree)); /* read the binary input, setup tree, initialize model with alignment */ read_msa(tr,argv[1]); tr->randomNumberSeed = 665; makeRandomTree(tr); printf("Number of taxa: %d\n", tr->mxtips); printf("Number of partitions: %d\n", tr->NumberOfModels); /* compute the LH of the full tree */ printf ("Virtual root: %d\n", tr->start->number); evaluateGeneric(tr, tr->start, TRUE); printf("Likelihood: %f\n", tr->likelihood); /* 8 rounds of branch length optimization */ smoothTree(tr, 1); evaluateGeneric(tr, tr->start, TRUE); printf("Likelihood after branch length optimization: %.20f\n", tr->likelihood); /* Now we show how to find a particular LH vector for a node */ int i; int node_number = tr->mxtips + 1; nodeptr p = tr->nodep[node_number]; printf("Pointing to node %d\n", p->number); /* Fix as VR */ newviewGeneric(tr, p, FALSE); newviewGeneric(tr, p->back, FALSE); evaluateGeneric(tr, p, FALSE); printf("Likelihood : %.f\n", tr->likelihood); printf("Make a copy of LH vector for node %d\n", p->number); likelihood_vector *vector = copy_likelihood_vectors(tr, p); for(i=0; i<vector->num_partitions; i++) printf("Partition %d requires %d bytes\n", i, (int)vector->partition_sizes[i]); /* Check we have the same vector in both tree and copied one */ assert(same_vector(tr, p, vector)); /* Now force the p to get a new value (generally branch lengths are NOT updated like this) */ /* This is just an example to show usage (for fast NNI eval), manually updating vectors is not recommended! */ printf("bl : %.40f\n", p->next->z[0]); p->next->z[0] = p->next->back->z[0] = zmin; printf("bl : %.40f\n", p->next->z[0]); newviewGeneric(tr, p, FALSE); assert(!same_vector(tr, p, vector)); evaluateGeneric(tr, p, FALSE); printf("Likelihood : %f\n", tr->likelihood); restore_vector(tr, p, vector); assert(same_vector(tr, p, vector)); evaluateGeneric(tr, p, FALSE); printf("Likelihood after manually restoring the vector : %f\n", tr->likelihood); free_likelihood_vector(vector); /* Pick an inner branch */ printf("numBranches %d \n", tr->numBranches); //tr->numBranches = 1; p = tr->nodep[tr->mxtips + 1]; int partition_id = 0; /* single partition */ double bl = get_branch_length(tr, p, partition_id); printf("z value: %f , bl value %f\n", p->z[partition_id], bl); /* set the bl to 2.5 */ double new_bl = 2.5; set_branch_length(tr, p, partition_id, new_bl); printf("Changed BL to %f\n", new_bl); printf("new z value: %f , new bl value %f\n", p->z[partition_id], get_branch_length(tr, p, partition_id)); /* set back to original */ printf("Changed to previous BL\n"); set_branch_length(tr, p, partition_id, bl); printf("new z value: %f , new bl value %f\n", p->z[partition_id], get_branch_length(tr, p, partition_id)); return (0); }