Skip to content

Commit d294745

Browse files
committed
check for EOF
1 parent 5858fb2 commit d294745

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

cmd/check-sort-order/main.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
package main
22

33
import (
4+
"bufio"
45
"bytes"
56
"errors"
67
"fmt"
78
"io"
89
"log"
10+
"os"
911
"strconv"
1012
"strings"
1113

1214
"github.com/alexflint/go-arg"
15+
"github.com/biogo/hts/bgzf"
1316
"github.com/brentp/xopen"
1417
"github.com/gogetdata/ggd-utils"
1518
)
@@ -105,7 +108,19 @@ func checkTab(path string, gf *ggd_utils.GenomeFile, getter chromStartGetter) {
105108
if !(xopen.Exists(path+".tbi") || xopen.Exists(path+".csi")) {
106109
log.Fatalf("BED: %s should have a .tbi", path)
107110
}
108-
rdr, err := xopen.Ropen(path)
111+
fh, err := os.Open(path)
112+
if err != nil {
113+
log.Fatalf("BED: unable to open file: %s", path)
114+
}
115+
if ok, _ := bgzf.HasEOF(fh); !ok {
116+
log.Fatal("missing EOF")
117+
}
118+
119+
bgz, err := bgzf.NewReader(fh, 1)
120+
defer bgz.Close()
121+
defer fh.Close()
122+
123+
rdr := bufio.NewReader(bgz)
109124
iline := 1
110125
check(err)
111126
afterHeader := false
@@ -142,8 +157,18 @@ func checkVCF(path string, gf *ggd_utils.GenomeFile) {
142157
log.Fatal("VCF should have a .tbi or .csi")
143158
}
144159

145-
rdr, err := xopen.Ropen(path)
160+
fh, err := os.Open(path)
146161
check(err)
162+
defer fh.Close()
163+
if ok, _ := bgzf.HasEOF(fh); !ok {
164+
log.Fatalf("missing EOF in %s", path)
165+
}
166+
167+
bgz, err := bgzf.NewReader(fh, 1)
168+
check(err)
169+
defer bgz.Close()
170+
rdr := bufio.NewReader(bgz)
171+
147172
afterHeader := false
148173
iline := 1
149174
lastChrom := []byte("")

0 commit comments

Comments
 (0)