1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#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 */
int phylo·addchild(bio·Node* parent, bio·Node* child);
int phylo·rmchild(bio·Node* parent, bio·Node* child);
/* clade statistics */
int phylo·countnodes(bio·Node *node, int *n);
int phylo·countleafs(bio·Node *node, int *n);
/* topological sorting */
int 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 */
int bio·readnewick(io·Peeker io, void* rdr, bio·Tree* tree);
int 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);
int bio·closeseq(bio·SeqReader *rdr);
int bio·readfasta(bio·SeqReader *rdr, bio·Seq *seq);
int bio·readfastq(bio·SeqReader *rdr, bio·Seq *seq);
int bio·writefasta(io·Writer io, void *wtr, bio·Seq seq);
int bio·writefastq(io·Writer io, void *wtr, bio·Seq seq);
|