diff options
author | Nicholas Noll <nbnoll@eml.cc> | 2020-04-25 12:53:42 -0700 |
---|---|---|
committer | Nicholas Noll <nbnoll@eml.cc> | 2020-04-25 12:53:42 -0700 |
commit | 9ff2333d9fd84c3741bf71961532152976f8ddc7 (patch) | |
tree | b6501d7c37fbc2f86585bd03e0074c0dd9c1bcd2 /sys/libbio/io | |
parent | 622ec3cadbda926e02af594d2ff7e89d33833b36 (diff) |
chore: pulled out sequence header function to be used by fastq
Diffstat (limited to 'sys/libbio/io')
-rw-r--r-- | sys/libbio/io/fasta.c | 30 |
1 files changed, 22 insertions, 8 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; |