#pragma once // ----------------------------------------------------------------------- // Phylogenetics typedef struct bio·Node { string name, comment; double dist, support; int nnode, nchild; struct bio·Node *parent, *sibling, *child; void *data; } bio·Node; typedef struct bio·Tree { bio·Node *root; int nleaf; mem·Allocator mem; void *heap; } bio·Tree; /* clade manipulation */ error phylo·addchild(bio·Node* parent, bio·Node* child); error phylo·rmchild(bio·Node* parent, bio·Node* child); /* clade statistics */ error phylo·countnodes(bio·Node *node, int *n); error phylo·countleafs(bio·Node *node, int *n); /* topological sorting */ error phylo·ladderize(bio·Node *root); double phylo·diameter(bio·Tree tree, int *len, bio·Node **path); /* generic computation on tree */ void *phylo·postorder(bio·Node *clade, void *(*op)(bio·Node*, void*), void *ctx); void *phylo·preorder(bio·Node *clade, void *(*op)(bio·Node*, void*), void *ctx); /* simple helpers */ void phylo·getleafs(bio·Tree tree, bio·Node **leafs); /* newick i/o */ error bio·readnewick(io·Peeker io, void* rdr, bio·Tree* tree); error bio·writenewick(bio·Tree tree, io·Putter out, void*); // ----------------------------------------------------------------------- // Sequences /* i/o */ typedef struct bio·SeqReader bio·SeqReader; typedef struct bio·Seq { vlong len; char *name; char *s; char *q; } bio·Seq; bio·SeqReader *bio·openseq(io·Reader io, void *rdr, mem·Allocator mem, void *heap); error bio·closeseq(bio·SeqReader *rdr); error bio·readfasta(bio·SeqReader *rdr, bio·Seq *seq); error bio·readfastq(bio·SeqReader *rdr, bio·Seq *seq); error bio·writefasta(io·Writer io, void *wtr, bio·Seq seq); error bio·writefastq(io·Writer io, void *wtr, bio·Seq seq);