static boolean addElementLenMULT (FILE *fp, tree *tr, nodeptr p, int partitionCounter) { nodeptr q, r, s; int n, ch, fres, rn; double randomResolution; int old; tr->constraintVector[p->number] = partitionCounter; if ((ch = treeGetCh(fp)) == '(') { partCount++; old = partCount; n = (tr->nextnode)++; if (n > 2*(tr->mxtips) - 2) { if (tr->rooted || n > 2*(tr->mxtips) - 1) { printf("ERROR: Too many internal nodes. Is tree rooted?\n"); printf(" Deepest splitting should be a trifurcation.\n"); return FALSE; } else { tr->rooted = TRUE; } } q = tr->nodep[n]; tr->constraintVector[q->number] = partCount; if (! addElementLenMULT(fp, tr, q->next, old)) return FALSE; if (! treeNeedCh(fp, ',', "in")) return FALSE; if (! addElementLenMULT(fp, tr, q->next->next, old)) return FALSE; hookupDefault(p, q, tr->numBranches); while((ch = treeGetCh(fp)) == ',') { n = (tr->nextnode)++; if (n > 2*(tr->mxtips) - 2) { if (tr->rooted || n > 2*(tr->mxtips) - 1) { printf("ERROR: Too many internal nodes. Is tree rooted?\n"); printf(" Deepest splitting should be a trifurcation.\n"); return FALSE; } else { tr->rooted = TRUE; } } r = tr->nodep[n]; tr->constraintVector[r->number] = partCount; rn = randomInt(10000); if(rn == 0) randomResolution = 0; else randomResolution = ((double)rn)/10000.0; if(randomResolution < 0.5) { s = q->next->back; r->back = q->next; q->next->back = r; r->next->back = s; s->back = r->next; addElementLenMULT(fp, tr, r->next->next, old); } else { s = q->next->next->back; r->back = q->next->next; q->next->next->back = r; r->next->back = s; s->back = r->next; addElementLenMULT(fp, tr, r->next->next, old); } } if(ch != ')') { printf("Missing /) in treeReadLenMULT\n"); exit(-1); } (void) treeFlushLabel(fp); } else { ungetc(ch, fp); if ((n = treeFindTipName(fp, tr)) <= 0) return FALSE; q = tr->nodep[n]; tr->constraintVector[q->number] = partitionCounter; if (tr->start->number > n) tr->start = q; (tr->ntips)++; hookupDefault(p, q, tr->numBranches); } fres = treeFlushLen(fp); if(!fres) return FALSE; return TRUE; }
int treeReadLen (FILE *fp, tree *tr, boolean readBranches, boolean readNodeLabels, boolean topologyOnly, analdef *adef, boolean completeTree) { nodeptr p; int i, ch, lcount = 0; for (i = 1; i <= tr->mxtips; i++) { tr->nodep[i]->back = (node *) NULL; if(topologyOnly) tr->nodep[i]->support = -1; } for(i = tr->mxtips + 1; i < 2 * tr->mxtips; i++) { tr->nodep[i]->back = (nodeptr)NULL; tr->nodep[i]->next->back = (nodeptr)NULL; tr->nodep[i]->next->next->back = (nodeptr)NULL; tr->nodep[i]->number = i; tr->nodep[i]->next->number = i; tr->nodep[i]->next->next->number = i; if(topologyOnly) { tr->nodep[i]->support = -2; tr->nodep[i]->next->support = -2; tr->nodep[i]->next->next->support = -2; } } if(topologyOnly) tr->start = tr->nodep[tr->mxtips]; else tr->start = tr->nodep[1]; tr->ntips = 0; tr->nextnode = tr->mxtips + 1; for(i = 0; i < tr->numBranches; i++) tr->partitionSmoothed[i] = FALSE; tr->rooted = FALSE; p = tr->nodep[(tr->nextnode)++]; while((ch = treeGetCh(fp)) != '('); if(!topologyOnly) assert(readBranches == FALSE && readNodeLabels == FALSE); if (! addElementLen(fp, tr, p, readBranches, readNodeLabels, &lcount)) assert(0); if (! treeNeedCh(fp, ',', "in")) assert(0); if (! addElementLen(fp, tr, p->next, readBranches, readNodeLabels, &lcount)) assert(0); if (! tr->rooted) { if ((ch = treeGetCh(fp)) == ',') { if (! addElementLen(fp, tr, p->next->next, readBranches, readNodeLabels, &lcount)) assert(0); } else { /* A rooted format */ tr->rooted = TRUE; if (ch != EOF) (void) ungetc(ch, fp); } } else { p->next->next->back = (nodeptr) NULL; } if (! treeNeedCh(fp, ')', "in")) assert(0); if(topologyOnly) assert(!(tr->rooted && readNodeLabels)); (void) treeFlushLabel(fp); if (! treeFlushLen(fp)) assert(0); if (! treeNeedCh(fp, ';', "at end of")) assert(0); if (tr->rooted) { assert(!readNodeLabels); p->next->next->back = (nodeptr) NULL; tr->start = uprootTree(tr, p->next->next, FALSE, FALSE); if (! tr->start) { printf("FATAL ERROR UPROOTING TREE\n"); assert(0); } } else tr->start = findAnyTip(p, tr->rdta->numsp); if(!topologyOnly) { setupPointerMesh(tr); assert(tr->ntips <= tr->mxtips); if(tr->ntips < tr->mxtips) { if(completeTree) { printBothOpen("Hello this is your friendly RAxML tree parsing routine\n"); printBothOpen("The RAxML option you are uisng requires to read in only complete trees\n"); printBothOpen("with %d taxa, there is at least one tree with %d taxa though ... exiting\n", tr->mxtips, tr->ntips); exit(-1); } else { if(adef->computeDistance) { printBothOpen("Error: pairwise distance computation only allows for complete, i.e., containing all taxa\n"); printBothOpen("bifurcating starting trees\n"); exit(-1); } if(adef->mode == CLASSIFY_ML) { printBothOpen("RAxML classifier Algo: You provided a reference tree with %d taxa; alignmnet has %d taxa\n", tr->ntips, tr->mxtips); printBothOpen("%d query taxa will be classifed under ML\n", tr->mxtips - tr->ntips); classifyML(tr, adef); } else { printBothOpen("You provided an incomplete starting tree %d alignmnet has %d taxa\n", tr->ntips, tr->mxtips); makeParsimonyTreeIncomplete(tr, adef); } } } else { if(adef->mode == PARSIMONY_ADDITION) { printBothOpen("Error you want to add sequences to a trees via MP stepwise addition, but \n"); printBothOpen("you have provided an input tree that already contains all taxa\n"); exit(-1); } if(adef->mode == CLASSIFY_ML) { printBothOpen("Error you want to classify query sequences into a tree via ML, but \n"); printBothOpen("you have provided an input tree that already contains all taxa\n"); exit(-1); } } onlyInitrav(tr, tr->start); } return lcount; }
static boolean addElementLen (FILE *fp, tree *tr, nodeptr p, boolean readBranchLengths, boolean readNodeLabels, int *lcount) { nodeptr q; int n, ch, fres; if ((ch = treeGetCh(fp)) == '(') { n = (tr->nextnode)++; if (n > 2*(tr->mxtips) - 2) { if (tr->rooted || n > 2*(tr->mxtips) - 1) { printf("ERROR: Too many internal nodes. Is tree rooted?\n"); printf(" Deepest splitting should be a trifurcation.\n"); return FALSE; } else { assert(!readNodeLabels); tr->rooted = TRUE; } } q = tr->nodep[n]; if (! addElementLen(fp, tr, q->next, readBranchLengths, readNodeLabels, lcount)) return FALSE; if (! treeNeedCh(fp, ',', "in")) return FALSE; if (! addElementLen(fp, tr, q->next->next, readBranchLengths, readNodeLabels, lcount)) return FALSE; if (! treeNeedCh(fp, ')', "in")) return FALSE; if(readNodeLabels) { char label[64]; int support; if(treeGetLabel (fp, label, 10)) { int val = sscanf(label, "%d", &support); assert(val == 1); /*printf("LABEL %s Number %d\n", label, support);*/ /*p->support = q->support = support;*/ /*printf("%d %d %d %d\n", p->support, q->support, p->number, q->number);*/ assert(p->number > tr->mxtips && q->number > tr->mxtips); *lcount = *lcount + 1; } } else (void) treeFlushLabel(fp); } else { ungetc(ch, fp); if ((n = treeFindTipName(fp, tr)) <= 0) return FALSE; q = tr->nodep[n]; if (tr->start->number > n) tr->start = q; (tr->ntips)++; } if(readBranchLengths) { double branch; if (! treeNeedCh(fp, ':', "in")) return FALSE; if (! treeProcessLength(fp, &branch)) return FALSE; /*printf("Branch %8.20f %d\n", branch, tr->numBranches);*/ hookup(p, q, &branch, tr->numBranches); } else { fres = treeFlushLen(fp); if(!fres) return FALSE; hookupDefault(p, q, tr->numBranches); } return TRUE; }
int treeReadLen (FILE *fp, tree *tr, boolean readBranches, boolean readNodeLabels, boolean topologyOnly) { nodeptr p; int i, ch, lcount = 0; for (i = 1; i <= tr->mxtips; i++) { tr->nodep[i]->back = (node *) NULL; /*if(topologyOnly) tr->nodep[i]->support = -1;*/ } for(i = tr->mxtips + 1; i < 2 * tr->mxtips; i++) { tr->nodep[i]->back = (nodeptr)NULL; tr->nodep[i]->next->back = (nodeptr)NULL; tr->nodep[i]->next->next->back = (nodeptr)NULL; tr->nodep[i]->number = i; tr->nodep[i]->next->number = i; tr->nodep[i]->next->next->number = i; /*if(topologyOnly) { tr->nodep[i]->support = -2; tr->nodep[i]->next->support = -2; tr->nodep[i]->next->next->support = -2; }*/ } if(topologyOnly) tr->start = tr->nodep[tr->mxtips]; else tr->start = tr->nodep[1]; tr->ntips = 0; tr->nextnode = tr->mxtips + 1; for(i = 0; i < tr->numBranches; i++) tr->partitionSmoothed[i] = FALSE; tr->rooted = FALSE; p = tr->nodep[(tr->nextnode)++]; while((ch = treeGetCh(fp)) != '('); if(!topologyOnly) assert(readBranches == FALSE && readNodeLabels == FALSE); if (! addElementLen(fp, tr, p, readBranches, readNodeLabels, &lcount)) assert(0); if (! treeNeedCh(fp, ',', "in")) assert(0); if (! addElementLen(fp, tr, p->next, readBranches, readNodeLabels, &lcount)) assert(0); if (! tr->rooted) { if ((ch = treeGetCh(fp)) == ',') { if (! addElementLen(fp, tr, p->next->next, readBranches, readNodeLabels, &lcount)) assert(0); } else { /* A rooted format */ tr->rooted = TRUE; if (ch != EOF) (void) ungetc(ch, fp); } } else { p->next->next->back = (nodeptr) NULL; } if (! treeNeedCh(fp, ')', "in")) assert(0); if(topologyOnly) assert(!(tr->rooted && readNodeLabels)); (void) treeFlushLabel(fp); if (! treeFlushLen(fp)) assert(0); if (! treeNeedCh(fp, ';', "at end of")) assert(0); if (tr->rooted) { assert(!readNodeLabels); p->next->next->back = (nodeptr) NULL; tr->start = uprootTree(tr, p->next->next, FALSE); if (! tr->start) { printf("FATAL ERROR UPROOTING TREE\n"); assert(0); } } else tr->start = findAnyTip(p, tr->mxtips); assert(tr->ntips == tr->mxtips); return lcount; }
boolean treeReadLenMULT (FILE *fp, tree *tr, int *partCount) { nodeptr p, r, s; int i, ch, n, rn; int partitionCounter = 0; double randomResolution; srand(tr->randomSeed); for(i = 0; i < 2 * tr->mxtips; i++) tr->constraintVector[i] = -1; for (i = 1; i <= tr->mxtips; i++) tr->nodep[i]->back = (node *) NULL; for(i = tr->mxtips + 1; i < 2 * tr->mxtips; i++) { tr->nodep[i]->back = (nodeptr)NULL; tr->nodep[i]->next->back = (nodeptr)NULL; tr->nodep[i]->next->next->back = (nodeptr)NULL; tr->nodep[i]->number = i; tr->nodep[i]->next->number = i; tr->nodep[i]->next->next->number = i; } tr->start = tr->nodep[tr->mxtips]; tr->ntips = 0; tr->nextnode = tr->mxtips + 1; for(i = 0; i < tr->numBranches; i++) tr->partitionSmoothed[i] = FALSE; tr->rooted = FALSE; p = tr->nodep[(tr->nextnode)++]; while((ch = treeGetCh(fp)) != '('); if (! addElementLenMULT(fp, tr, p, partitionCounter, partCount)) return FALSE; if (! treeNeedCh(fp, ',', "in")) return FALSE; if (! addElementLenMULT(fp, tr, p->next, partitionCounter, partCount)) return FALSE; if (! tr->rooted) { if ((ch = treeGetCh(fp)) == ',') { if (! addElementLenMULT(fp, tr, p->next->next, partitionCounter, partCount)) return FALSE; while((ch = treeGetCh(fp)) == ',') { n = (tr->nextnode)++; assert(n <= 2*(tr->mxtips) - 2); r = tr->nodep[n]; tr->constraintVector[r->number] = partitionCounter; rn = randomInt(10000); if(rn == 0) randomResolution = 0; else randomResolution = ((double)rn)/10000.0; if(randomResolution < 0.5) { s = p->next->next->back; r->back = p->next->next; p->next->next->back = r; r->next->back = s; s->back = r->next; addElementLenMULT(fp, tr, r->next->next, partitionCounter, partCount); } else { s = p->next->back; r->back = p->next; p->next->back = r; r->next->back = s; s->back = r->next; addElementLenMULT(fp, tr, r->next->next, partitionCounter, partCount); } } if(ch != ')') { printf("Missing /) in treeReadLenMULT\n"); exit(-1); } else ungetc(ch, fp); } else { tr->rooted = TRUE; if (ch != EOF) (void) ungetc(ch, fp); } } else { p->next->next->back = (nodeptr) NULL; } if (! treeNeedCh(fp, ')', "in")) return FALSE; (void) treeFlushLabel(fp); if (! treeFlushLen(fp)) return FALSE; if (! treeNeedCh(fp, ';', "at end of")) return FALSE; if (tr->rooted) { p->next->next->back = (nodeptr) NULL; tr->start = uprootTree(tr, p->next->next, FALSE); if (! tr->start) return FALSE; } else { tr->start = findAnyTip(p, tr->mxtips); } assert(tr->ntips == tr->mxtips); return TRUE; }