#include "common.h"#include "linefile.h"#include "dystring.h"#include "phyloTree.h"Include dependency graph for phyloTree.c:

Go to the source code of this file.
Functions | |
| phyloTree * | phyloReadTree (struct lineFile *lf) |
| phyloTree * | phyloOpenTree (char *fileName) |
| static struct phyloName * | parseIdent (char **ptrPtr) |
| static struct phyloTree * | newEdge (struct phyloTree *parent, struct phyloTree *child) |
| phyloTree * | phyloAddEdge (struct phyloTree *parent, struct phyloTree *child) |
| static struct phyloTree * | parseSubTree (char **ptrPtr) |
| phyloTree * | phyloParseString (char *string) |
| static void | tabOut (FILE *f) |
| static void | pTree (struct phyloTree *tree, FILE *f, boolean noDups) |
| void | phyloPrintTreeNoDups (struct phyloTree *tree, FILE *f) |
| void | phyloPrintTree (struct phyloTree *tree, FILE *f) |
| void | phyloDebugTree (struct phyloTree *tree, FILE *f) |
| phyloTree * | phyloFindName (struct phyloTree *tree, char *name) |
| void | phyloClearTreeMarks (struct phyloTree *tree) |
| phyloTree * | phyloFindMarkUpTree (struct phyloTree *tree) |
| void | phyloMarkUpTree (struct phyloTree *tree) |
| char * | phyloFindPath (struct phyloTree *tree, char *ref, char *cross) |
| static void | nodeNames (struct phyloTree *tree, struct dyString *ds) |
| char * | phyloNodeNames (struct phyloTree *tree) |
| static void | reParent (struct phyloTree *tree) |
| phyloTree * | phyloReRoot (struct phyloTree *tree) |
| void | phyloDeleteEdge (struct phyloTree *tree, struct phyloTree *edge) |
| int | phyloCountLeaves (struct phyloTree *tree) |
Variables | |
| static int | recurseCount = 0 |
| static struct phyloTree* newEdge | ( | struct phyloTree * | parent, | |
| struct phyloTree * | child | |||
| ) | [static, read] |
Definition at line 69 of file phyloTree.c.
References phyloTree::allocedEdges, phyloTree::edges, needMoreMem(), phyloTree::numEdges, and phyloTree::parent.
Referenced by bfGraphFromRangeGraph(), parseSubTree(), phyloAddEdge(), and reParent().
00070 { 00071 parent->numEdges++; 00072 00073 if (parent->numEdges > parent->allocedEdges) 00074 { 00075 int oldSize = parent->allocedEdges * sizeof (struct phyloTree *); 00076 int newSize; 00077 00078 parent->allocedEdges += 5; 00079 newSize = parent->allocedEdges * sizeof (struct phyloTree *); 00080 parent->edges = needMoreMem(parent->edges, oldSize, newSize); 00081 } 00082 00083 child->parent = parent; 00084 return parent->edges[parent->numEdges -1 ] = child; 00085 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 326 of file phyloTree.c.
References ds, dyStringAppendC(), dyStringAppendN(), phyloTree::edges, phyloTree::ident, phyloName::name, and phyloTree::numEdges.
Referenced by phyloNodeNames().
00328 { 00329 int ii; 00330 00331 if (tree->ident->name) 00332 { 00333 dyStringAppendN(ds, tree->ident->name, strlen(tree->ident->name)); 00334 dyStringAppendC(ds, ' '); 00335 } 00336 00337 for (ii=0; ii < tree->numEdges; ii++) 00338 nodeNames(tree->edges[ii],ds); 00339 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static struct phyloName* parseIdent | ( | char ** | ptrPtr | ) | [static, read] |
Definition at line 30 of file phyloTree.c.
References AllocVar, cloneString(), phyloName::length, and phyloName::name.
Referenced by parseSubTree().
00032 { 00033 struct phyloName *pName; 00034 char *start = *ptrPtr; 00035 char *ptr = *ptrPtr; 00036 00037 AllocVar(pName); 00038 /* legal id's are alphanumeric */ 00039 while(isalpha(*ptr) || isdigit(*ptr) || (*ptr == '/') 00040 || (*ptr == '\'') 00041 || (*ptr == '.') || (*ptr == '_')) 00042 ptr++; 00043 00044 /* did we read something? */ 00045 if(ptr > start) 00046 { 00047 char val; 00048 00049 val = *ptr; 00050 *ptr = 0; 00051 pName->name = cloneString(start); 00052 *ptr = val; 00053 } 00054 00055 /* is there some branch length info */ 00056 if (*ptr == ':') 00057 { 00058 ptr++; 00059 sscanf(ptr, "%lg", &pName->length); 00060 while ((*ptr != '[') && (*ptr != ')') && (*ptr != ',') && (*ptr != ';')) 00061 ptr++; 00062 } 00063 00064 *ptrPtr = ptr; 00065 00066 return pName; 00067 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static struct phyloTree* parseSubTree | ( | char ** | ptrPtr | ) | [static, read] |
Definition at line 93 of file phyloTree.c.
References AllocVar, errAbort(), phyloTree::ident, phyloTree::isDup, newEdge(), phyloTree::parent, parseIdent(), startsWith(), and TRUE.
Referenced by phyloParseString().
00095 { 00096 struct phyloTree *node = NULL; 00097 char *ptr = *ptrPtr; 00098 00099 /* trees are terminated by one of these three chars */ 00100 if ((*ptr == ';') || (*ptr == ',') || (*ptr == ')') ) 00101 return NULL; 00102 00103 AllocVar(node); 00104 if (*ptr == '(') 00105 { 00106 struct phyloTree *edge; 00107 00108 ptr++; 00109 00110 do 00111 { 00112 edge = newEdge(node,parseSubTree(&ptr)); 00113 edge->parent = node; 00114 } while (*ptr++ == ','); 00115 --ptr; 00116 if (*ptr++ != ')') 00117 errAbort("unbalanced parenthesis at (%s)",ptr-1); 00118 node->ident = parseIdent(&ptr); 00119 } 00120 else 00121 if ((*ptr == ':') || (isalpha(*ptr))|| (isdigit(*ptr)) 00122 || (*ptr == '\'') || (*ptr == '.')) 00123 node->ident = parseIdent(&ptr); 00124 else 00125 errAbort("illegal char '%c' in phyloString",*ptr); 00126 00127 if (*ptr == '[') 00128 { 00129 if (startsWith("[&&NHX:D=Y]",ptr)) 00130 node->isDup = TRUE; 00131 00132 while(*ptr != ']') 00133 ptr++; 00134 00135 ptr++; 00136 00137 } 00138 00139 *ptrPtr = ptr; 00140 00141 00142 return node; 00143 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 87 of file phyloTree.c.
References newEdge(), and phyloTree::parent.
Here is the call graph for this function:

| void phyloClearTreeMarks | ( | struct phyloTree * | tree | ) |
Definition at line 253 of file phyloTree.c.
References phyloTree::edges, phyloTree::mark, phyloTree::numEdges, and phyloClearTreeMarks().
Referenced by phyloClearTreeMarks(), and phyloFindPath().
00255 { 00256 int ii; 00257 00258 tree->mark = 0; 00259 00260 for (ii=0; ii < tree->numEdges; ii++) 00261 phyloClearTreeMarks(tree->edges[ii]); 00262 }
Here is the call graph for this function:

Here is the caller graph for this function:

| int phyloCountLeaves | ( | struct phyloTree * | tree | ) |
Definition at line 394 of file phyloTree.c.
References phyloTree::edges, phyloTree::numEdges, and phyloCountLeaves().
Referenced by phyloCountLeaves().
00395 { 00396 int ii, count = 0; 00397 00398 if (tree->numEdges == 0) 00399 return 1; 00400 00401 for (ii=0; ii < tree->numEdges; ii++) 00402 count += phyloCountLeaves(tree->edges[ii]); 00403 00404 return count; 00405 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void phyloDebugTree | ( | struct phyloTree * | tree, | |
| FILE * | f | |||
| ) |
Definition at line 218 of file phyloTree.c.
References phyloTree::edges, phyloTree::ident, phyloName::length, phyloName::name, phyloTree::numEdges, phyloDebugTree(), recurseCount, and tabOut().
Referenced by phyloDebugTree().
00220 { 00221 if (tree) 00222 { 00223 int ii; 00224 fprintf(f,"%s:%g numEdges %d\n",tree->ident->name, tree->ident->length, tree->numEdges); 00225 recurseCount++; 00226 for (ii= 0; ii < tree->numEdges; ii++) 00227 { 00228 tabOut(f); 00229 phyloDebugTree(tree->edges[ii], f); 00230 } 00231 recurseCount--; 00232 } 00233 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 377 of file phyloTree.c.
References phyloTree::edges, and phyloTree::numEdges.
Referenced by reParent().
00379 { 00380 int ii; 00381 00382 for (ii=0; ii < tree->numEdges; ii++) 00383 if (tree->edges[ii] == edge) 00384 { 00385 memcpy(&tree->edges[ii], &tree->edges[ii+1], sizeof(tree) * (tree->numEdges - ii - 1)); 00386 tree->numEdges--; 00387 //phyloFreeTree(edge); 00388 return; 00389 } 00390 00391 errAbort("tried to delete non-existant edge"); 00392 }
Here is the caller graph for this function:

Definition at line 264 of file phyloTree.c.
References phyloTree::mark, and phyloTree::parent.
Referenced by phyloFindPath().
00266 { 00267 do 00268 { 00269 if (tree->mark) 00270 return tree; 00271 tree = tree->parent; 00272 } while (tree); 00273 00274 return NULL; 00275 }
Here is the caller graph for this function:

Definition at line 235 of file phyloTree.c.
References phyloTree::edges, phyloTree::ident, phyloName::name, phyloTree::numEdges, phyloFindName(), and sameString.
Referenced by phyloFindName(), and phyloFindPath().
00237 { 00238 struct phyloTree *subTree = NULL; 00239 int ii; 00240 00241 if (tree->ident->name && sameString(tree->ident->name, name)) 00242 return tree; 00243 00244 for (ii=0; ii < tree->numEdges; ii++) 00245 { 00246 if ((subTree = phyloFindName( tree->edges[ii], name)) != NULL) 00247 break; 00248 } 00249 00250 return subTree; 00251 }
Here is the call graph for this function:

Here is the caller graph for this function:

| char* phyloFindPath | ( | struct phyloTree * | tree, | |
| char * | ref, | |||
| char * | cross | |||
| ) |
Definition at line 285 of file phyloTree.c.
References ds, dyStringAppendC(), dyStringAppendN(), phyloTree::ident, phyloTree::mark, phyloName::name, newDyString(), phyloTree::parent, phyloClearTreeMarks(), phyloFindMarkUpTree(), phyloFindName(), and phyloMarkUpTree().
00288 { 00289 struct phyloTree *treeRef, *treeCross, *parent; 00290 struct dyString *ds = newDyString(0); 00291 00292 if ((treeRef = phyloFindName(tree,ref)) == NULL) 00293 return NULL; 00294 00295 if ((treeCross = phyloFindName(tree,cross)) == NULL) 00296 return NULL; 00297 00298 phyloClearTreeMarks(tree); 00299 phyloMarkUpTree(treeCross); 00300 if ((parent = phyloFindMarkUpTree(treeRef)) == NULL) 00301 return NULL; 00302 00303 /* walk up the tree till we hit the common parent */ 00304 while(treeRef != parent) 00305 { 00306 treeRef = treeRef->parent; 00307 if (ds->stringSize) 00308 dyStringAppendC(ds, ' '); 00309 if (treeRef->ident->name) 00310 dyStringAppendN(ds, treeRef->ident->name, strlen(treeRef->ident->name)); 00311 } 00312 00313 /* now walk down the tree till we come to the target species */ 00314 while (parent != treeCross) 00315 { 00316 parent = parent->mark; 00317 dyStringAppendC(ds, ' '); 00318 if (parent->ident->name) 00319 dyStringAppendN(ds, parent->ident->name, strlen(parent->ident->name)); 00320 } 00321 00322 return ds->string; 00323 }
Here is the call graph for this function:

| void phyloMarkUpTree | ( | struct phyloTree * | tree | ) |
Definition at line 277 of file phyloTree.c.
References phyloTree::mark, and phyloTree::parent.
Referenced by phyloFindPath().
00279 { 00280 tree->mark = tree; 00281 for(;tree->parent; tree = tree->parent) 00282 tree->parent->mark = tree; 00283 }
Here is the caller graph for this function:

| char* phyloNodeNames | ( | struct phyloTree * | tree | ) |
Definition at line 341 of file phyloTree.c.
References ds, newDyString(), and nodeNames().
00343 { 00344 struct dyString *ds = newDyString(0); 00345 00346 nodeNames(tree, ds); 00347 00348 ds->string[ds->stringSize-1]=0; 00349 00350 return ds->string; 00351 }
Here is the call graph for this function:

| struct phyloTree* phyloOpenTree | ( | char * | fileName | ) | [read] |
Definition at line 19 of file phyloTree.c.
References lineFileClose(), lineFileOpen(), phyloReadTree(), and TRUE.
00020 { 00021 struct lineFile *lf = lineFileOpen(fileName, TRUE); 00022 struct phyloTree *tree = phyloReadTree(lf); 00023 00024 lineFileClose(&lf); 00025 00026 return tree; 00027 }
Here is the call graph for this function:

| struct phyloTree* phyloParseString | ( | char * | string | ) | [read] |
Definition at line 145 of file phyloTree.c.
References eraseWhiteSpace(), errAbort(), and parseSubTree().
Referenced by phyloReadTree().
00147 { 00148 struct phyloTree *tree = NULL; 00149 char *ptr = string; 00150 00151 eraseWhiteSpace(string); 00152 00153 tree = parseSubTree(&ptr); 00154 00155 if (*ptr != ';') 00156 errAbort("trees must terminated by ';'"); 00157 00158 return tree; 00159 }
Here is the call graph for this function:

Here is the caller graph for this function:

| void phyloPrintTree | ( | struct phyloTree * | tree, | |
| FILE * | f | |||
| ) |
| void phyloPrintTreeNoDups | ( | struct phyloTree * | tree, | |
| FILE * | f | |||
| ) |
Definition at line 6 of file phyloTree.c.
References lineFileNext(), and phyloParseString().
Referenced by phyloOpenTree().
00008 { 00009 struct phyloTree *tree = NULL; 00010 char *ptr; 00011 int len; 00012 00013 if (lineFileNext(lf, &ptr, &len) && (len > 0)) 00014 tree = phyloParseString(ptr); 00015 00016 return tree; 00017 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 368 of file phyloTree.c.
References phyloTree::ident, phyloName::length, and reParent().
Here is the call graph for this function:

| static void pTree | ( | struct phyloTree * | tree, | |
| FILE * | f, | |||
| boolean | noDups | |||
| ) | [static] |
Definition at line 173 of file phyloTree.c.
References phyloTree::edges, phyloTree::ident, phyloTree::isDup, phyloName::length, phyloName::name, and phyloTree::numEdges.
Referenced by phyloPrintTree(), phyloPrintTreeNoDups(), and rbTreeFree().
00175 { 00176 if (tree) 00177 { 00178 int ii; 00179 if (noDups && (tree->numEdges == 1)) 00180 pTree(tree->edges[0], f, noDups); 00181 else 00182 { 00183 if (tree->numEdges) 00184 { 00185 fprintf(f,"("); 00186 for (ii= 0; ii < tree->numEdges; ii++) 00187 { 00188 pTree(tree->edges[ii], f, noDups); 00189 if (ii + 1 < tree->numEdges) 00190 fprintf(f,","); 00191 } 00192 fprintf(f,")"); 00193 } 00194 if (tree->ident->name) 00195 fprintf(f,"%s",tree->ident->name); 00196 //if (tree->ident->length != 0.0) 00197 fprintf(f,":%0.04g", tree->ident->length); 00198 if (tree->isDup) 00199 fprintf(f,"[&&NHX:D=Y]"); 00200 } 00201 } 00202 }
Here is the caller graph for this function:

| static void reParent | ( | struct phyloTree * | tree | ) | [static] |
Definition at line 354 of file phyloTree.c.
References phyloTree::ident, phyloName::length, newEdge(), phyloTree::parent, and phyloDeleteEdge().
Referenced by phyloReRoot().
00355 { 00356 if (tree->parent) 00357 { 00358 struct phyloTree *edge, *saveParent = tree->parent; 00359 00360 reParent(saveParent); 00361 phyloDeleteEdge(saveParent, tree); 00362 edge = newEdge(tree, saveParent); 00363 edge->parent = tree; 00364 edge->ident->length = tree->ident->length; 00365 } 00366 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void tabOut | ( | FILE * | f | ) | [static] |
Definition at line 165 of file phyloTree.c.
References recurseCount.
Referenced by phyloDebugTree().
00166 { 00167 int i; 00168 00169 for(i=0; i < recurseCount; i++) 00170 fputc(' ',f); 00171 }
Here is the caller graph for this function:

int recurseCount = 0 [static] |
1.5.2