Skip to content

Commit

Permalink
The parser for FASTA files in elPrep didn't accept empty lines before…
Browse files Browse the repository at this point in the history
… new description lines. This is fixed.
  • Loading branch information
Pascal Costanza committed Apr 29, 2019
1 parent bab5e82 commit f6a70a4
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 23 deletions.
2 changes: 1 addition & 1 deletion cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const (
// ProgramName is "elprep"
ProgramName = "elprep"
// ProgramVersion is the version of the elprep binary
ProgramVersion = "4.1.2"
ProgramVersion = "4.1.3"
// ProgramURL is the repository for the elprep source code
ProgramURL = "http://github.com/exascience/elprep"
)
Expand Down
46 changes: 39 additions & 7 deletions fasta/fasta-files.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// elPrep: a high-performance tool for preparing SAM/BAM files.
// Copyright (c) 2017, 2018 imec vzw.
// Copyright (c) 2017-2019 imec vzw.

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
Expand Down Expand Up @@ -156,8 +156,11 @@ func ParseFasta(filename string, fai map[string]FaiReference, toUpper, toN bool)
return nil, fmt.Errorf("empty fasta file %v", filename)
}
b := scanner.Bytes()
if len(b) == 0 {
return nil, fmt.Errorf("invalid fasta file %v - empty line", filename)
for len(b) == 0 {
if !scanner.Scan() {
return nil, fmt.Errorf("empty fasta file %v", filename)
}
b = scanner.Bytes()
}
if b[0] != '>' {
return nil, fmt.Errorf("invalid fasta file %v - missing first header", filename)
Expand All @@ -167,10 +170,23 @@ func ParseFasta(filename string, fai map[string]FaiReference, toUpper, toN bool)
seq := initSeq(contig, fai)
fasta = make(map[string][]byte)

scanLoop:
for scanner.Scan() {
b := scanner.Bytes()
if len(b) == 0 {
return nil, fmt.Errorf("invalid fasta file %v - empty line", filename)
if !scanner.Scan() {
break scanLoop
}
b = scanner.Bytes()
for len(b) == 0 {
if !scanner.Scan() {
break scanLoop
}
b = scanner.Bytes()
}
if b[0] != '>' {
return nil, fmt.Errorf("invalid fasta file %v - empty line", filename)
}
}
if b[0] == '>' {
fasta[contig] = seq
Expand Down Expand Up @@ -391,8 +407,11 @@ func OpenConcurrentFasta(filename, fai string, toUpper, toN bool) (fasta Concurr
return nil, fmt.Errorf("empty fasta file %v", filename)
}
b := scanner.Bytes()
if len(b) == 0 {
return nil, fmt.Errorf("invalid fasta file %v - empty line", filename)
for len(b) == 0 {
if !scanner.Scan() {
return nil, fmt.Errorf("empty fasta file %v", filename)
}
b = scanner.Bytes()
}
if b[0] != '>' {
return nil, fmt.Errorf("invalid fasta file %v - missing first header", filename)
Expand All @@ -409,10 +428,23 @@ func OpenConcurrentFasta(filename, fai string, toUpper, toN bool) (fasta Concurr
ref := faiMap[contig]
seq := make([]byte, 0, ref.Length)

scanLoop:
for scanner.Scan() {
b := scanner.Bytes()
if len(b) == 0 {
log.Fatal(fmt.Errorf("invalid fasta file %v - empty line", filename))
if !scanner.Scan() {
break scanLoop
}
b = scanner.Bytes()
for len(b) == 0 {
if !scanner.Scan() {
break scanLoop
}
b = scanner.Bytes()
}
if b[0] != '>' {
log.Fatal(fmt.Errorf("invalid fasta file %v - empty line", filename))
}
}
if b[0] == '>' {
entry := fasta[contig]
Expand Down
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
module github.com/exascience/elprep/v4

require (
github.com/exascience/pargo v1.0.0
golang.org/x/sys v0.0.0-20181011152604-fa43e7bc11ba
gonum.org/v1/gonum v0.0.0-20181017130424-4c3d8206805c // indirect
gonum.org/v1/netlib v0.0.0-20181018051557-57e1e4db57a7 // indirect
github.com/exascience/pargo v1.0.1
golang.org/x/exp v0.0.0-20190426190305-956cc1757749 // indirect
golang.org/x/sys v0.0.0-20190429094411-2cc0cad0ac78
gonum.org/v1/gonum v0.0.0-20190424212039-2a1643c79af2 // indirect
gonum.org/v1/netlib v0.0.0-20190331212654-76723241ea4e // indirect
)
41 changes: 30 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
github.com/exascience/pargo v1.0.0 h1:q2dUG8+KeoRPCHMEGJYG6O0OUOFWL5EqLA4a0+9r8mc=
github.com/exascience/pargo v1.0.0/go.mod h1:S4dDBaMIgxplCJMMiIqd+TG7gHUo8h7dhLxsCWBiyWU=
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de h1:xSjD6HQTqT0H/k60N5yYBtnN1OEkVy7WIo/DYyxKRO0=
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/sys v0.0.0-20181011152604-fa43e7bc11ba h1:nZJIJPGow0Kf9bU9QTc1U6OXbs/7Hu4e+cNv+hxH+Zc=
golang.org/x/sys v0.0.0-20181011152604-fa43e7bc11ba/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gonum.org/v1/gonum v0.0.0-20181017130424-4c3d8206805c h1:d95cUzTUV6w+XVqfxIr/EyaPdDUW569t0SYM+Bmvxao=
gonum.org/v1/gonum v0.0.0-20181017130424-4c3d8206805c/go.mod h1:Y+Yx5eoAFn32cQvJDxZx5Dpnq+c3wtXuadVZAcxbbBo=
gonum.org/v1/netlib v0.0.0-20181018051557-57e1e4db57a7 h1:biGE8p3sxXv+JdArdlsXEJZBPPFk51mQHVwOv6h1gnY=
gonum.org/v1/netlib v0.0.0-20181018051557-57e1e4db57a7/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/exascience/pargo v1.0.1 h1:SFxXIEHI5fQ50b5aEzB7bRTBtxzva/uqCi4Yg/CkFLI=
github.com/exascience/pargo v1.0.1/go.mod h1:S4dDBaMIgxplCJMMiIqd+TG7gHUo8h7dhLxsCWBiyWU=
github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190312203227-4b39c73a6495/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
golang.org/x/exp v0.0.0-20190426190305-956cc1757749 h1:Bduxdpx1O6126WsH6F6NwKywZ/FPncphlTduoPxFG78=
golang.org/x/exp v0.0.0-20190426190305-956cc1757749/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190429094411-2cc0cad0ac78 h1:ddnrbGOgFiC0zV+uaYoSkl0f47vnII6Zu426zWQrWkg=
golang.org/x/sys v0.0.0-20190429094411-2cc0cad0ac78/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190206041539-40960b6deb8e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
gonum.org/v1/gonum v0.0.0-20190331200053-3d26580ed485/go.mod h1:2ltnJ7xHfj0zHS40VVPYEAAMTa3ZGguvHGBSJeRWqE0=
gonum.org/v1/gonum v0.0.0-20190424212039-2a1643c79af2 h1:KTRD63fFTJiXuYJfxAI7BLujKCVAi7s9QD7rgzfY7MU=
gonum.org/v1/gonum v0.0.0-20190424212039-2a1643c79af2/go.mod h1:2ltnJ7xHfj0zHS40VVPYEAAMTa3ZGguvHGBSJeRWqE0=
gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw=
gonum.org/v1/netlib v0.0.0-20190331212654-76723241ea4e h1:jRyg0XfpwWlhEV8mDfdNGBeSJM2fuyh9Yjrnd8kF2Ts=
gonum.org/v1/netlib v0.0.0-20190331212654-76723241ea4e/go.mod h1:kS+toOQn6AQKjmKJ7gzohV1XkqsFehRA2FbsbkopSuQ=
modernc.org/cc v1.0.0/go.mod h1:1Sk4//wdnYJiUIxnW8ddKpaOJCF37yAdqYnkxUpaYxw=
modernc.org/golex v1.0.0/go.mod h1:b/QX9oBD/LhixY6NDh+IdGv17hgB+51fET1i2kPSmvk=
modernc.org/mathutil v1.0.0/go.mod h1:wU0vUrJsVWBZ4P6e7xtFJEhFSNsfRLJ8H458uRjg03k=
modernc.org/strutil v1.0.0/go.mod h1:lstksw84oURvj9y3tn8lGvRxyRC1S2+g5uuIzNfIOBs=
modernc.org/xc v1.0.0/go.mod h1:mRNCo0bvLjGhHO9WsyuKVU4q0ceiDDDoEeWDJHrNx8I=

0 comments on commit f6a70a4

Please sign in to comment.