Tree *buildTreeFromPhylo_( int node, int *lowerNodes, int *upperNodes, double *edgeLengths, int nedges, char **tipLabels, int ntips ) { Tree *t,*b,**bb; int i,j,n; t=NewTree(); bb=&t->branches; n=0; for(i=0;i<nedges;i++) { if(lowerNodes[i]!=node) continue; j=upperNodes[i]; if(j==0) {error=ERROR; goto err;} if(j>0) { if(j>ntips) {error=ERROR; goto err;} b=NewTree(); strcpy(b->label,tipLabels[j-1]); } else { if(-j>nedges) {error=ERROR; goto err;} b= buildTreeFromPhylo_(j,lowerNodes,upperNodes,edgeLengths,nedges,tipLabels,ntips); } b->length=edgeLengths[i]; *bb=b; bb=&b->next; n++; } if(n<2) {error=ERROR; goto err;} err: *bb=NULL; return(t); }
void CBitPatternTreeMethod::findRemoveInvalidColumns(const std::vector< CStepMatrixColumn * > & nullColumns) { if (mNewColumns.empty()) { return; } // Convert the new columns into a bit pattern tree CBitPatternTree NewTree(mNewColumns); // Determine the columns which became invalid. std::vector< CStepMatrixColumn * > InvalidColumns; std::vector< CStepMatrixColumn * >::const_iterator it = nullColumns.begin(); std::vector< CStepMatrixColumn * >::const_iterator end = nullColumns.end(); for (; it != end; ++it) { if (!NewTree.isExtremeRay((*it)->getZeroSet())) { InvalidColumns.push_back(*it); } } mpStepMatrix->removeInvalidColumns(InvalidColumns); mNewColumns.clear(); }
Decision::Decision(Player P, char *DatabaseAddr) { m_SeeTree = true; m_T = NewTree(); m_Node = m_T; m_player = P; if(ReadDatabase(m_T,DatabaseAddr)==false) { printf("\no arquivo não existe\n"); } }
static void SimpleTree( conflict_node *conf ) /***********************************************/ { reg_tree *tree; name *temp; tree = NewTree(); temp = conf->name; tree->temp = temp; tree->size = temp->n.size; tree->offset = temp->v.offset; tree->idx = conf->possible; BuildPossible( tree ); conf->tree = tree; }
void NewFractals(void) { NewTree(); }
static reg_tree *BuildTree( name *alias, name *master, type_length offset, type_length size, conflict_node *conf ) /************************************************************************/ { reg_tree *tree; name *temp; bool have_lo; bool have_hi; type_length losize; type_length hisize; type_length midpoint; tree = NewTree(); tree->offset = offset; tree->size = size; if( alias != NULL ) { tree->temp = alias; tree->has_name = true; alias->t.temp_flags |= VISITED; temp = alias->t.alias; while( temp != alias ) { if( temp->v.offset == offset && temp->n.size == size ) { tree->alt = temp; /* signed vs. unsigned*/ temp->t.temp_flags |= VISITED; break; } temp = temp->t.alias; } } if( tree->alt == NULL ) { if( tree->temp != NULL ) { tree->idx = GetPossibleForTemp( conf, tree->temp ); } } else { tree->idx = RegIntersect( GetPossibleForTemp( conf, tree->temp ), GetPossibleForTemp( conf, tree->alt ) ); } if( size == 6 ) { /* this is harmlessly specific to 80386 big pointers */ losize = 4; hisize = 2; } else { losize = size / 2; hisize = size / 2; } midpoint = offset + losize; if( losize != 0 ) { have_lo = false; have_hi = false; temp = master->t.alias; while( temp != master ) { if( !have_lo && temp->v.offset == offset && temp->n.size == losize ) { tree->lo = BuildTree( temp, master, offset, losize, conf ); have_lo = true; } else if( !have_hi && temp->v.offset == midpoint && temp->n.size == hisize ) { tree->hi = BuildTree( temp, master, midpoint, hisize, conf ); have_hi = true; } temp = temp->t.alias; } if( !have_lo ) { tree->lo = BuildTree( NULL, master, offset, losize, conf ); } if( !have_hi ) { tree->hi = BuildTree( NULL, master, midpoint, hisize, conf ); } if( tree->hi->has_name ) { tree->has_name = true; } if( tree->lo->has_name ) { tree->has_name = true; } } return( tree ); }
int main(int argc, char **argv) { int i, j, k, treeNo, sumLength; char ch; TTree **treeSet; FILE *text_fv; clock_t totalStart; double totalSecs, scale, sum; char *ancestor; totalStart = clock(); ReadParams(argc, argv); if (rateHetero == CodonRates && invariableSites) { fprintf(stderr, "Invariable sites model cannot be used with codon rate heterogeneity.\n"); exit(4); } if (writeAncestors && fileFormat == NEXUSFormat) { fprintf(stderr, "Warning - When writing ancestral sequences, relaxed PHYLIP format is used.\n"); } if (writeAncestors && maxPartitions > 1) { fprintf(stderr, "Writing ancestral sequences can only be used for a single partition.\n"); exit(4); } if (!userSeed) randomSeed = CreateSeed(); SetSeed(randomSeed); if (!quiet) PrintTitle(); numTrees = OpenTreeFile(); /* if (!treeFile) { */ ReadFileParams(); /*} */ if ((ancestorSeq>0 && !hasAlignment) || ancestorSeq>numSequences) { fprintf(stderr, "Bad ancestral sequence number: %d (%d sequences loaded)\n", ancestorSeq, numSequences); exit(4); } if (textFile) { if ( (text_fv=fopen(textFileName, "rt"))==NULL ) { fprintf(stderr, "Error opening text file for insertion into output: '%s'\n", textFileName); exit(4); } } ancestor=NULL; if (hasAlignment) { AllocateMemory(); ReadFile(); if (numSites<0) numSites=numAlignmentSites; if (ancestorSeq>0) { if (numSites!=numAlignmentSites) { fprintf(stderr, "Ancestral sequence is of a different length to the simulated sequences (%d)\n", numAlignmentSites); exit(4); } ancestor=sequences[ancestorSeq-1]; } } else if (numSites<0) numSites=1000; SetModel(model); numTaxa=-1; scale=1.0; treeSet = (TTree **)malloc(sizeof(TTree **) * maxPartitions); if (treeSet==NULL) { fprintf(stderr, "Out of memory\n"); exit(5); } partitionLengths = (int *)malloc(sizeof(int) * maxPartitions); if (partitionLengths==NULL) { fprintf(stderr, "Out of memory\n"); exit(5); } partitionRates = (double *)malloc(sizeof(double) * maxPartitions); if (partitionRates==NULL) { fprintf(stderr, "Out of memory\n"); exit(5); } for (i = 0; i < maxPartitions; i++) { if ((treeSet[i]=NewTree())==NULL) { fprintf(stderr, "Out of memory\n"); exit(5); } } CreateRates(); treeNo=0; do { partitionLengths[0] = -1; ReadTree(tree_fv, treeSet[0], treeNo+1, 0, NULL, &partitionLengths[0], &partitionRates[0]); if (treeNo==0) { numTaxa=treeSet[0]->numTips; if (!quiet) fprintf(stderr, "Random number generator seed: %ld\n\n", randomSeed); if (fileFormat == NEXUSFormat) { fprintf(stdout, "#NEXUS\n"); fprintf(stdout, "[\nGenerated by %s %s\n\n", PROGRAM_NAME, VERSION_NUMBER); PrintVerbose(stdout); fprintf(stdout, "]\n\n"); } } else if (treeSet[0]->numTips != numTaxa) { fprintf(stderr, "All trees must have the same number of tips.\n"); exit(4); } if (maxPartitions == 1) { if (partitionLengths[0] != -1) { fprintf(stderr, "\nWARNING: The treefile contained partion lengths but only one partition\n"); fprintf(stderr, "was specified.\n"); } partitionLengths[0] = numSites; } sumLength = partitionLengths[0]; i = 1; while (sumLength < numSites && i <= maxPartitions) { if (!IsTreeAvail(tree_fv)) { fprintf(stderr, "\nA set of trees number %d had less partition length (%d) than\n", treeNo + 1, sumLength); fprintf(stderr, "was required to make a sequence of length %d.\n", numSites); exit(4); } ReadTree(tree_fv, treeSet[i], treeNo+1, treeSet[0]->numTips, treeSet[0]->names, &partitionLengths[i], &partitionRates[i]); if (treeSet[i]->numTips != numTaxa) { fprintf(stderr, "All trees must have the same number of tips.\n"); exit(4); } sumLength += partitionLengths[i]; i++; } if (i > maxPartitions) { fprintf(stderr, "\nA set of trees number %d had more partitions (%d) than\n", treeNo + 1, i); fprintf(stderr, "was specified in the user options (%d).\n", maxPartitions); } numPartitions = i; if (sumLength != numSites) { fprintf(stderr, "The sum of the partition lengths in the treefile does not equal\n"); fprintf(stderr, "the specified number of sites.\n"); exit(4); } for (i = 0; i < numPartitions; i++) CreateSequences(treeSet[i], partitionLengths[i]); if (numPartitions > 1) { sum = 0.0; for (i = 0; i < numPartitions; i++) sum += partitionRates[i] * partitionLengths[i]; for (i = 0; i < numPartitions; i++) partitionRates[i] *= numSites / sum; } if (treeNo==0 && verbose && !quiet) { PrintVerbose(stderr); InitProgressBar(numTrees*numDatasets); DrawProgressBar(); } for (i=0; i<numDatasets; i++) { SetCategories(); k = 0; for (j = 0; j < numPartitions; j++) { scale = partitionRates[j]; if (scaleTrees) { if (!treeSet[j]->rooted) { fprintf(stderr, "To scale tree length, they must be rooted and ultrametric.\n"); exit(4); } scale *= treeScale/treeSet[j]->totalLength; } else if (scaleBranches) scale *= branchScale; EvolveSequences(treeSet[j], k, partitionLengths[j], scale, ancestor); k += partitionLengths[j]; } if (writeAncestors) WriteAncestralSequences(stdout, treeSet[0]); else WriteSequences(stdout, (numTrees > 1 ? treeNo+1 : -1), (numDatasets > 1 ? i+1 : -1), treeSet, partitionLengths); if (writeRates) { WriteRates(stderr); } if (textFile) { while (!feof(text_fv)) { ch = fgetc(text_fv); if (!feof(text_fv)) fputc(ch, stdout); } fputc('\n', stdout); rewind(text_fv); } if (verbose && !quiet) ProgressBar(); } for (i = 0; i < numPartitions; i++) DisposeTree(treeSet[i]); treeNo++; } while (IsTreeAvail(tree_fv)); /* for (i = 0; i < maxPartitions; i++) FreeTree(treeSet[i]); */ if (treeFile) fclose(tree_fv); if (textFile) fclose(text_fv); totalSecs = (double)(clock() - totalStart) / CLOCKS_PER_SEC; if (!quiet) { fprintf(stderr, "Time taken: %G seconds\n", totalSecs); if (verboseMemory) fprintf(stderr, "Total memory used: %ld\n", totalMem); } return 0; }