|
1 | 1 | package main |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "bufio" |
4 | 5 | "bytes" |
5 | 6 | "errors" |
6 | 7 | "fmt" |
7 | 8 | "io" |
8 | 9 | "log" |
| 10 | + "os" |
9 | 11 | "strconv" |
10 | 12 | "strings" |
11 | 13 |
|
12 | 14 | "github.com/alexflint/go-arg" |
| 15 | + "github.com/biogo/hts/bgzf" |
13 | 16 | "github.com/brentp/xopen" |
14 | 17 | "github.com/gogetdata/ggd-utils" |
15 | 18 | ) |
@@ -105,7 +108,19 @@ func checkTab(path string, gf *ggd_utils.GenomeFile, getter chromStartGetter) { |
105 | 108 | if !(xopen.Exists(path+".tbi") || xopen.Exists(path+".csi")) { |
106 | 109 | log.Fatalf("BED: %s should have a .tbi", path) |
107 | 110 | } |
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) |
109 | 124 | iline := 1 |
110 | 125 | check(err) |
111 | 126 | afterHeader := false |
@@ -142,8 +157,18 @@ func checkVCF(path string, gf *ggd_utils.GenomeFile) { |
142 | 157 | log.Fatal("VCF should have a .tbi or .csi") |
143 | 158 | } |
144 | 159 |
|
145 | | - rdr, err := xopen.Ropen(path) |
| 160 | + fh, err := os.Open(path) |
146 | 161 | 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 | + |
147 | 172 | afterHeader := false |
148 | 173 | iline := 1 |
149 | 174 | lastChrom := []byte("") |
|
0 commit comments