aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-04-25 12:43:11 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-04-25 12:43:11 -0700
commit622ec3cadbda926e02af594d2ff7e89d33833b36 (patch)
tree3a7b7edba269688bb6c502d9bb8a6eb41cb13ca3 /sys
parent50081012e8dcf3c4ee4163526f684afa707c5a98 (diff)
chore: prepare for refactoring to allow for fastq
Diffstat (limited to 'sys')
-rw-r--r--sys/libbio/io/fasta.c28
-rw-r--r--sys/libbio/test.c35
2 files changed, 56 insertions, 7 deletions
diff --git a/sys/libbio/io/fasta.c b/sys/libbio/io/fasta.c
index 891e222..5e659ab 100644
--- a/sys/libbio/io/fasta.c
+++ b/sys/libbio/io/fasta.c
@@ -132,15 +132,18 @@ fill(bio·FastaReader *rdr)
return 0;
}
+// -----------------------------------------------------------------------
+// Fasta files
+
bio·FastaReader*
-bio·newfastareader(io·Reader stream, void *s, mem·Allocator heap, void *h)
+bio·openfasta(io·Reader file, void *f, mem·Allocator heap, void *h)
{
error err;
bio·FastaReader *rdr;
rdr = heap.alloc(h, 1, sizeof(bio·FastaReader));
- rdr->file = stream;
- rdr->f = s;
+ rdr->file = file;
+ rdr->f = f;
rdr->eof = 0;
rdr->seq = heap.alloc(h, 1, sizeof(*rdr->seq) + INIT_NM_SIZE + INIT_SQ_SIZE);
@@ -236,3 +239,22 @@ SUCCESS:
return 0;
}
+
+error
+bio·closefasta(bio·FastaReader *rdr)
+{
+ mem·Allocator heap;
+ void *h;
+
+
+ heap = rdr->seq->heap;
+ h = rdr->seq->h;
+
+ heap.free(h, rdr->seq);
+ heap.free(h, rdr);
+
+ return 0;
+}
+
+// -----------------------------------------------------------------------
+// Fastq files
diff --git a/sys/libbio/test.c b/sys/libbio/test.c
index 14f2b06..d38bbc1 100644
--- a/sys/libbio/test.c
+++ b/sys/libbio/test.c
@@ -2,6 +2,9 @@
#include <libn.h>
#include <libbio.h>
+#include <time.h>
+#include "kseq.h"
+
// -----------------------------------------------------------------------
// Point of entry for testing
@@ -32,6 +35,7 @@ test·newick()
io·close(fd[0]);
io·close(fd[1]);
+ mem·freearena(mem);
return 0;
}
@@ -44,16 +48,39 @@ test·fasta()
bio·Seq seq;
bio·FastaReader *rdr;
+ clock_t t;
+
fd = io·open("/home/nolln/root/data/test/zika.fa", "r");
- rdr = bio·newfastareader((io·Reader){.read = &io·read}, fd, mem·sys, nil);
+ /* Benchmark against Heng */
+#if 0
+ int n, slen;
+ kseq_t *kseq;
+
+ t = clock();
+ kseq = kseq_init(fd);
+ while (kseq_read(kseq) >= 0) {
+ ++n, slen += kseq->seq.l;
+ }
+ t = clock() - t;
+ printf("heng's code took %f ms to execute\n", 1000.*t/CLOCKS_PER_SEC);
+
+ kseq_destroy(kseq);
+
+ io·seek(fd, 0, seek·set);
+#endif
+
+ rdr = bio·openfasta((io·Reader){.read = &io·read}, fd, mem·sys, nil);
+
+ t = clock();
err = 0;
while (!err) {
err = bio·readfasta(rdr, &seq);
- if (!err) {
- printf(">%s\n", seq.name);
- }
}
+ t = clock() - t;
+ printf("nick's code took %f ms to execute\n", 1000.*t/CLOCKS_PER_SEC);
+ bio·closefasta(rdr);
+
io·close(fd);
return err <= 0 ? 0 : 1;