aboutsummaryrefslogtreecommitdiff
path: root/include/libbio.h
blob: 3db742d0128133da2fddf464cfb2480de125a6e5 (plain)
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
#pragma once

// -----------------------------------------------------------------------
// Phylogenetics

typedef struct bio·Node
{
    string name;
    string comment;
    double dist;
    double support;
    int    nchild;
    int    ndescendent;
    struct bio·Node *parent;
    struct bio·Node *child[2];
    struct bio·Node *sibling;
} bio·Node;

error phylo·addchild(bio·Node *parent, bio·Node* child);
bool  phylo·isleaf(bio·Node *node);

typedef struct bio·Tree
{
    bio·Node *root;
} bio·Tree;

/* newick i/o */
bio·Tree bio·readnewick(io·Peeker stream, void*, mem·Allocator heap, void*);
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 = 1000,   // number of hashes
};

error aln·sketch(byte *seq, int l, uint64 *phi[aln·N], int *locs[aln·N]);
error aln·sort(int len, int l, uint64 *vals);