#pragma once // ----------------------------------------------------------------------- // Phylogenetics typedef struct bio·Node { string name; string comment; double dist; double support; int nnode; int nchild; struct bio·Node *parent; struct bio·Node *sibling; struct bio·Node *child; } bio·Node; typedef struct bio·Tree { bio·Node *root; int nleaf; mem·Allocator heap; void *h; } 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 stream, void*, bio·Tree* tree); error bio·writenewick(bio·Tree tree, io·Putter out, void*); // ----------------------------------------------------------------------- // Sequences /* i/o */ typedef struct bio·FastaReader bio·FastaReader; typedef struct bio·FastqReader bio·FastqReader; typedef struct bio·Seq { int len; byte *name; byte *s; byte *q; } bio·Seq; bio·FastaReader *bio·openfasta(io·Reader stream, void *s, mem·Allocator heap, void *h); error bio·readfasta(bio·FastaReader *rdr, bio·Seq *seq); error bio·closefasta(bio·FastaReader *rdr); bio·FastqReader *bio·openfastq(io·Reader stream, void *s, mem·Allocator heap, void *h); error bio·readfastq(bio·FastqReader *rdr, bio·Seq *seq); error bio·closefastq(bio·FastqReader *rdr); /* alignment */ enum { aln·K = 20, // kmer size (k <= 32) aln·L = 3, // number of kmers / hash aln·N = 10, // number of hashes }; error aln·sketch(byte *seq, int l, uint64 *phi[aln·N], int *locs[aln·N]); error aln·sort(uintptr len, int l, uint64 *vals);