From 98375c9c5e4bf26f8d238666d7233177dba787eb Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Sat, 25 Apr 2020 14:13:13 -0700 Subject: feat: parsing multiline fastq files --- sys/libbio/test.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) (limited to 'sys/libbio/test.c') diff --git a/sys/libbio/test.c b/sys/libbio/test.c index f301ead..e943153 100644 --- a/sys/libbio/test.c +++ b/sys/libbio/test.c @@ -3,6 +3,16 @@ #include #include +#include "kseq.h" + +static +int +my_read(Stream *s, void *buf, int n) +{ + return io·read(s, 1, n, buf); +} + +KSEQ_INIT(Stream*, my_read) // ----------------------------------------------------------------------- // Point of entry for testing @@ -31,6 +41,7 @@ test·newick() err = bio·writenewick(t, wtr, fd[1]); io·flush(fd[1]); + io·close(fd[0]); io·close(fd[1]); @@ -85,6 +96,50 @@ test·fasta() return err <= 0 ? 0 : 1; } +error +test·fastq() +{ + error err; + Stream *fd; + + bio·Seq seq; + bio·FastqReader *rdr; + + clock_t t; + + int n, slen; + kseq_t *kseq; + + fd = io·open("/home/nolln/root/data/test/eg.fq", "r"); + + t = clock(); + kseq = kseq_init(fd); + while (kseq_read(kseq) >= 0) { + ++n, slen += kseq->seq.l; + } + t = clock() - t; + printf("heng's fastq code took %f ms to execute\n", 1000.*t/CLOCKS_PER_SEC); + + kseq_destroy(kseq); + + io·seek(fd, 0, seek·set); + + rdr = bio·openfastq((io·Reader){.read = &io·read}, fd, mem·sys, nil); + + t = clock(); + err = 0; + while (!err) { + err = bio·readfastq(rdr, &seq); + } + t = clock() - t; + printf("nick's fastq code took %f ms to execute\n", 1000.*t/CLOCKS_PER_SEC); + bio·closefastq(rdr); + + + io·close(fd); + return err <= 0 ? 0 : 1; +} + error main() { @@ -96,5 +151,9 @@ main() if (err = test·fasta(), err) { errorf("test fail: fasta"); } + + if (err = test·fastq(), err) { + errorf("test fail: fastq"); + } } -- cgit v1.2.1