| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "log" |
| 6 | "os" |
| 7 | "strconv" |
| 8 | |
| 9 | "github.com/brentp/bix" |
| 10 | "github.com/brentp/irelate/interfaces" |
| 11 | ) |
| 12 | |
| 13 | func check(e error) { |
| 14 | if e != nil { |
| 15 | log.Fatal(e) |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | func min(a, b int) int { |
| 20 | if a < b { |
| 21 | return a |
| 22 | } |
| 23 | return b |
| 24 | } |
| 25 | |
| 26 | type loc struct { |
| 27 | chrom string |
| 28 | start int |
| 29 | end int |
| 30 | } |
| 31 | |
| 32 | func (s loc) Chrom() string { |
| 33 | return s.chrom |
| 34 | } |
| 35 | func (s loc) Start() uint32 { |
| 36 | return uint32(s.start) |
| 37 | } |
| 38 | func (s loc) End() uint32 { |
| 39 | return uint32(s.end) |
| 40 | } |
| 41 | |
| 42 | func main() { |
| 43 | |
| 44 | f := os.Args[1] |
| 45 | tbx, err := bix.New(f) |
| 46 | check(err) |
| 47 | |
| 48 | chrom := os.Args[2] |
| 49 | |
| 50 | s, err := strconv.Atoi(os.Args[3]) |
| 51 | check(err) |
| 52 | |
| 53 | e, err := strconv.Atoi(os.Args[4]) |
| 54 | check(err) |
| 55 | |
| 56 | vals, _ := tbx.Query(loc{chrom, s, e}) |
| 57 | i := 0 |
| 58 | for { |
| 59 | v, err := vals.Next() |
| 60 | if err != nil { |
| 61 | break |
| 62 | } |
| 63 | fmt.Println(v.(interfaces.IVariant).String()[:40]) |
| 64 | i++ |
| 65 | } |
| 66 | tbx.Close() |
| 67 | |
| 68 | } |