diff options
-rw-r--r-- | include/libbio.h | 9 | ||||
-rw-r--r-- | include/libn.h | 42 | ||||
-rw-r--r-- | sys/libbio/io/newick.c | 6 |
3 files changed, 55 insertions, 2 deletions
diff --git a/include/libbio.h b/include/libbio.h index 58540d4..9f54015 100644 --- a/include/libbio.h +++ b/include/libbio.h @@ -24,8 +24,17 @@ typedef struct bio·Tree bio·Node *root; } bio·Tree; +/* newick i/o */ bio·Tree bio·readnewick(Stream *file, mem·Allocator heap); error bio·writenewick(bio·Tree tree, Stream *out); // ----------------------------------------------------------------------- // Sequences + +typedef struct bio·FastaReader bio·FastaReader; + +/* fasta/q i/o */ +bio·Seq *bio·newfastareader(Stream *file, mem·Allocator heap); +bio·Seq *bio·readfasta(bio·FastaParser *p); +error bio·writefasta(bio·Seq *seq, Stream *out); + diff --git a/include/libn.h b/include/libn.h index c8d510f..67d131d 100644 --- a/include/libn.h +++ b/include/libn.h @@ -107,6 +107,48 @@ vlong io·write(Stream *s, int sz, int n, void *buf); int io·flush(Stream *s); int io·seek(Stream *s, long off, enum SeekPos origin); +/* Generic I/O interfaces */ + +typedef struct io·Reader +{ + int (*read)(int n, void *buf); +}; + +typedef struct io·Peeker +{ + byte (*get)(void); + error (*unget)(byte); +}; + +typedef struct io·FullReader +{ + io·Reader; + io·Peeker; +} io·FullReader; + +typedef struct io·Writer +{ + int (*write)(int n, void *buf); +} io·Writer; + +typedef struct io·Putter +{ + error (*put)(byte); + int (*putstr)(string); +} io·Putter; + +typedef struct io·FullWriter +{ + io·Writer; + io·Putter; +} io·FullWriter; + +typedef struct io·ReadWriter +{ + io·Reader; + io·Writer; +} io·ReadWriter; + // ----------------------------------------------------------------------------- // Buffered I/O diff --git a/sys/libbio/io/newick.c b/sys/libbio/io/newick.c index f3aeb8a..0004fac 100644 --- a/sys/libbio/io/newick.c +++ b/sys/libbio/io/newick.c @@ -336,6 +336,8 @@ bio·readnewick(Stream *file, mem·Allocator heap) error dump(bio·Node *node, Stream *out) { + byte b[24]; + if (!node) { return 1; } @@ -357,8 +359,8 @@ dump(bio·Node *node, Stream *out) if (node->parent) { io·putbyte(out, ':'); - // TODO(nnoll): Format float - io·putbyte(out, '0'); + snprintf(b, arrlen(b), "%f", node->dist); + io·putstring(out, b); } return 0; |