aboutsummaryrefslogtreecommitdiff
path: root/sys/libbio/test.c
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-04-25 14:13:13 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-04-25 14:13:13 -0700
commit98375c9c5e4bf26f8d238666d7233177dba787eb (patch)
tree32c23d1207e518935d8493ba7d5928d8f8ec2666 /sys/libbio/test.c
parent9ff2333d9fd84c3741bf71961532152976f8ddc7 (diff)
feat: parsing multiline fastq files
Diffstat (limited to 'sys/libbio/test.c')
-rw-r--r--sys/libbio/test.c59
1 files changed, 59 insertions, 0 deletions
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 <libbio.h>
#include <time.h>
+#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]);
@@ -86,6 +97,50 @@ test·fasta()
}
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()
{
error err;
@@ -96,5 +151,9 @@ main()
if (err = test·fasta(), err) {
errorf("test fail: fasta");
}
+
+ if (err = test·fastq(), err) {
+ errorf("test fail: fastq");
+ }
}