diff options
-rw-r--r-- | sys/libbio/phylo.c | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/sys/libbio/phylo.c b/sys/libbio/phylo.c index c1ace7a..d623712 100644 --- a/sys/libbio/phylo.c +++ b/sys/libbio/phylo.c @@ -30,6 +30,29 @@ phylo·addchild(bio·Node* parent, bio·Node* child) } error +phylo·rmchild(bio·Node* parent, bio·Node* child) +{ + bio·Node *it, *prev; + enum { + error·nil, + error·notfound, + }; + + prev = nil; + for (it = parent->child[0]; it != nil && it != child; it = it->sibling) { + prev = it; + } + if (it == nil) return error·notfound; + + + + return error·nil; +} + +// ----------------------------------------------------------------------- +// subtree statistics + +error phylo·countnodes(bio·Node *node, int *n) { error err; @@ -67,4 +90,26 @@ phylo·countleafs(bio·Node *node, int *n) } // ----------------------------------------------------------------------- -// tree statistics +// tree editing + +error +phylo·ladderize(bio·Node *root) +{ + int i; + error err; + bio·Node *child; + double dists[50]; + + if (!root->nchild) return 0; + Assert(root->nchild < arrlen(dists)); + + for (i = 0, child = root->child[0]; child != nil; child = child->sibling, i++) { + if (err = phylo·ladderize(child), err) { + errorf("ladderize: failure at '%s'", child->name); + return 1; + } + dists[i] = child->dist; + } + + return 0; +} |