Debian Codegraph @

examples/main.go

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