1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
package main
import (
"flag"
"fmt"
"io"
"log"
"os"
"github.com/brentp/vcfgo"
)
func main() {
flag.Parse()
files := flag.Args()
f, err := os.Open(files[0])
r := io.Reader(f)
vr, err := vcfgo.NewReader(r, false)
if err != nil {
panic(err)
}
fmt.Printf("%v\n", vr)
variant := vr.Read()
fmt.Println(vr.Error())
fmt.Println("variant:", variant)
if len(variant.Samples) > 0 {
if _, ok := vr.Header.SampleFormats["PL"]; ok {
if vr.Header.SampleFormats["PL"].Type == "Integer" {
fmt.Println(variant.GetGenotypeField(variant.Samples[0], "PL", int(-1)))
} else {
fmt.Println(variant.GetGenotypeField(variant.Samples[0], "PL", float32(-1)))
}
}
}
fmt.Println(vr.Error())
vr.Clear()
for {
variant = vr.Read()
if variant == nil {
if e := vr.Error(); e != io.EOF && e != nil {
vr.Clear()
}
break
}
if vr.Error() != nil {
fmt.Println(vr.Error())
}
vr.Clear()
if len(variant.Samples) > 0 {
var pl interface{}
if _, ok := vr.Header.SampleFormats["PL"]; ok {
if vr.Header.SampleFormats["PL"].Type == "Integer" {
pl, err = variant.GetGenotypeField(variant.Samples[0], "PL", int(-1))
} else {
pl, err = variant.GetGenotypeField(variant.Samples[0], "PL", float32(-1))
}
}
fmt.Println("ERR:", err)
fmt.Println(variant.Samples[0])
if err != nil && variant.Samples[0] != nil {
log.Println("BBBBBBBBBBBBBBBBBBB")
if _, ok := vr.Header.SampleFormats["PL"]; ok {
fmt.Println("")
fmt.Println(variant.Samples[0])
log.Println("DDDDDDDDDDDDDDDDD")
log.Fatal(err)
}
}
if variant.Samples[0] != nil {
fmt.Println("PL:", pl, "GQ:", variant.Samples[0].GQ, "DP:", variant.Samples[0].DP)
}
}
}
fmt.Println("OK")
}
|