aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-04-25 12:53:42 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-04-25 12:53:42 -0700
commit9ff2333d9fd84c3741bf71961532152976f8ddc7 (patch)
treeb6501d7c37fbc2f86585bd03e0074c0dd9c1bcd2 /sys
parent622ec3cadbda926e02af594d2ff7e89d33833b36 (diff)
chore: pulled out sequence header function to be used by fastq
Diffstat (limited to 'sys')
-rw-r--r--sys/libbio/io/fasta.c30
-rw-r--r--sys/libbio/test.c1
2 files changed, 22 insertions, 9 deletions
diff --git a/sys/libbio/io/fasta.c b/sys/libbio/io/fasta.c
index 5e659ab..e26fd70 100644
--- a/sys/libbio/io/fasta.c
+++ b/sys/libbio/io/fasta.c
@@ -96,6 +96,9 @@ push(struct Seqbuf **sb, int n, void *buf)
return 0;
}
+// -----------------------------------------------------------------------
+// Fasta files
+
struct bio·FastaReader {
byte eof;
io·Reader file;
@@ -132,9 +135,6 @@ fill(bio·FastaReader *rdr)
return 0;
}
-// -----------------------------------------------------------------------
-// Fasta files
-
bio·FastaReader*
bio·openfasta(io·Reader file, void *f, mem·Allocator heap, void *h)
{
@@ -165,8 +165,9 @@ ERROR:
return nil;
}
+static
error
-bio·readfasta(bio·FastaReader *rdr, bio·Seq *seq)
+readfasta(bio·FastaReader *rdr, bio·Seq *seq, byte tok)
{
error err;
byte *beg;
@@ -179,7 +180,7 @@ bio·readfasta(bio·FastaReader *rdr, bio·Seq *seq)
// NOTE: Can this case happen?
Assert(rdr->b != rdr->bend);
- if (*rdr->b++ != '>') {
+ if (*rdr->b++ != tok) {
errorf("fasta format: expected '>', found '%c'", *rdr->b--);
return 1;
}
@@ -213,7 +214,7 @@ SEQL:
beg = rdr->b + 1;
}
- if (*rdr->b == '>' || *rdr->b == '\0') {
+ if (*rdr->b == tok || *rdr->b == '\0') {
goto SUCCESS;
}
@@ -232,12 +233,26 @@ SUCCESS:
push(&rdr->seq, rdr->b - beg, beg);
put(&rdr->seq, '\0');
+ return 0;
+}
+
+error
+bio·readfasta(bio·FastaReader *rdr, bio·Seq *seq)
+{
+ error err;
+
+ err = readfasta(rdr, seq, '>');
+ if (err && err != EOF) {
+ errorf("parse fail: could not read record");
+ return err;
+ }
+
seq->name = rdr->seq->b;
seq->s = rdr->seq->b + rdr->seq->off;
seq->len = rdr->seq->it - seq->s;
seq->q = nil;
- return 0;
+ return err;
}
error
@@ -246,7 +261,6 @@ bio·closefasta(bio·FastaReader *rdr)
mem·Allocator heap;
void *h;
-
heap = rdr->seq->heap;
h = rdr->seq->h;
diff --git a/sys/libbio/test.c b/sys/libbio/test.c
index d38bbc1..f301ead 100644
--- a/sys/libbio/test.c
+++ b/sys/libbio/test.c
@@ -3,7 +3,6 @@
#include <libbio.h>
#include <time.h>
-#include "kseq.h"
// -----------------------------------------------------------------------
// Point of entry for testing