From 84f25d433aee02a8ffd2e54ca94a30682167ecd9 Mon Sep 17 00:00:00 2001 From: Travis Harrison Date: Mon, 30 Apr 2018 11:09:49 -0500 Subject: [PATCH] fix fastq last record index --- shock-server/node/file/format/fastq/fastq.go | 43 ++++++++++---------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/shock-server/node/file/format/fastq/fastq.go b/shock-server/node/file/format/fastq/fastq.go index d0cce999..0997b856 100644 --- a/shock-server/node/file/format/fastq/fastq.go +++ b/shock-server/node/file/format/fastq/fastq.go @@ -8,6 +8,7 @@ import ( "bufio" "bytes" "errors" + "fmt" "github.com/MG-RAST/Shock/shock-server/conf" "github.com/MG-RAST/Shock/shock-server/node/file" "github.com/MG-RAST/Shock/shock-server/node/file/format/seq" @@ -63,14 +64,16 @@ func (self *Reader) Read() (sequence *seq.Seq, err error) { empty = true } - if empty { - err = errors.New("Invalid format: empty line(s) between records") - return - } else if (err == io.EOF) && (len(seqId) > 1) { - err = errors.New("Invalid format: truncated fastq record") + if err == io.EOF { + if len(seqId) > 0 { + err = errors.New("Invalid format: truncated fastq record") + } return } else if err != nil { return + } else if empty { + err = errors.New("Invalid format: empty line(s) between records") + return } else if !bytes.HasPrefix(seqId, []byte{'@'}) { err = errors.New("Invalid format: id line does not start with @") return @@ -111,16 +114,14 @@ func (self *Reader) Read() (sequence *seq.Seq, err error) { } qualBody, err = self.r.ReadBytes('\n') - if (err == io.EOF) && (len(seqBody) != len(qualBody)) { - err = errors.New("Invalid format: length of sequence and quality lines do not match") - return - } else if err != nil { + if (err != nil) && (err != io.EOF) { return - } else if len(seqBody) != len(qualBody)-1 { + } + qualBody = bytes.TrimSpace(qualBody) + if len(seqBody) != len(qualBody) { err = errors.New("Invalid format: length of sequence and quality lines do not match") return } - qualBody = bytes.TrimSpace(qualBody) sequence = seq.New(seqId, seqBody, qualBody) return @@ -147,14 +148,16 @@ func (self *Reader) GetReadOffset() (n int, err error) { empty = true } - if empty { - err = errors.New("Invalid format: empty line(s) between records") - return - } else if (err == io.EOF) && (len(seqId) > 1) { - err = errors.New("Invalid format: truncated fastq record") + if err == io.EOF { + if len(seqId) > 0 { + err = errors.New("Invalid format: truncated fastq record") + } return } else if err != nil { return + } else if empty { + err = errors.New("Invalid format: empty line(s) between records") + return } else if !bytes.HasPrefix(seqId, []byte{'@'}) { err = errors.New("Invalid format: id line does not start with @") return @@ -194,12 +197,10 @@ func (self *Reader) GetReadOffset() (n int, err error) { curr += len(qualId) qualBody, err = self.r.ReadBytes('\n') - if (err == io.EOF) && (len(seqBody)-1 != len(qualBody)) { - err = errors.New("Invalid format: length of sequence and quality lines do not match") + if (err != nil) && (err != io.EOF) { return - } else if err != nil { - return - } else if len(seqBody) != len(qualBody) { + } + if len(bytes.TrimSpace(seqBody)) != len(bytes.TrimSpace(qualBody)) { err = errors.New("Invalid format: length of sequence and quality lines do not match") return }