Skip to content

Commit 49f7e7a

Browse files
committed
more defensive programming
1 parent fa90827 commit 49f7e7a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

genomefile.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ggd_utils
33

44
import (
55
"bytes"
6+
"fmt"
67
"io"
78
"regexp"
89
"strconv"
@@ -33,6 +34,8 @@ func ReadGenomeFile(path string) (*GenomeFile, error) {
3334
defer rdr.Close()
3435

3536
space := regexp.MustCompile("\\s+")
37+
// allow us to bypass a header. found indicates when we have a usable line.
38+
found := false
3639

3740
for {
3841
line, err := rdr.ReadBytes('\n')
@@ -56,11 +59,18 @@ func ReadGenomeFile(path string) (*GenomeFile, error) {
5659
chrom := toks[0]
5760
length, err := strconv.Atoi(toks[1])
5861
if err != nil {
62+
if !found {
63+
continue
64+
}
5965
return nil, err
6066
}
67+
found = true
6168
gf.Lengths[chrom] = length
6269
gf.Order[chrom] = len(gf.Order)
6370

6471
}
72+
if !found {
73+
return nil, fmt.Errorf("no usable lengths found for %s\n", path)
74+
}
6575
return gf, nil
6676
}

0 commit comments

Comments
 (0)