Skip to content

Commit

Permalink
Merge pull request #348 from teharrison/master
Browse files Browse the repository at this point in the history
fix fastq last record index
  • Loading branch information
teharrison authored Apr 30, 2018
2 parents 67cd370 + 84f25d4 commit 0ebb808
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions shock-server/node/file/format/fastq/fastq.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 0ebb808

Please sign in to comment.