Beispiel #1
0
func TestIntervalLine(t *testing.T) {
	s := []byte("chr1\t1235\t4567\tasdf")
	i, _ := parsers.IntervalFromBedLine(s)
	if i.Start() != uint32(1235) {
		t.Error("expected start of 1235")
	}
}
Beispiel #2
0
func (t *Tabix) Get(q interfaces.IPosition) []interfaces.IPosition {
	//cs := C.CString(fmt.Sprintf("%s:%d-%d", q.Chrom(), q.Start()+1, q.End()))
	ch := C.CString(q.Chrom())
	cs := C.tbx_name2id(t.tbx, ch)

	itr := C.tabix_itr_queryi(t.tbx, cs, C.int(q.Start()), C.int(q.End()))

	kstr := C.kstring_t{}
	overlaps := make([]interfaces.IPosition, 0, 4)
	l := C.int(10)
	for l > 0 {
		l := C.atbx_itr_next(t.htf, t.tbx, itr, &kstr)
		if l < 0 {
			break
		}
		//res := C.GoString(kstr.s)
		if t.typ == VCF {
			b := C.bcf_init()
			ret := C.vcf_parse(&kstr, t.hdr, b)
			if ret < 0 {
				log.Printf("error parsing %s\n", C.GoStringN(kstr.s, C.int(kstr.l)))
			}
			overlaps = append(overlaps, NewVariant(b, t.hdr, 1))
		} else if t.typ == BED {
			iv, err := parsers.IntervalFromBedLine(C.GoBytes(unsafe.Pointer(kstr.s), C.int(kstr.l)))
			if err != nil {
				log.Printf("error parsing %s:%s\n", C.GoStringN(kstr.s, C.int(kstr.l)), err)
			}
			if iv != nil {
				overlaps = append(overlaps, iv)
			}
		}

	}
	C.hts_itr_destroy(itr)
	C.free(unsafe.Pointer(ch))
	C.free(unsafe.Pointer(kstr.s))
	return overlaps
}
Beispiel #3
0
func (s *APISuite) SetUpTest(c *C) {

	h.Infos["DP"] = &vcfgo.Info{Id: "DP", Description: "depth", Number: "1", Type: "Integer"}
	h.Infos["SVLEN"] = &vcfgo.Info{Id: "SVLEN", Description: "SVLEN", Number: "1", Type: "Integer"}
	h.Infos["CIPOS"] = &vcfgo.Info{Id: "CIPOS", Description: "CIPOS", Number: "2", Type: "Integer"}
	h.Infos["CIEND"] = &vcfgo.Info{Id: "CIEND", Description: "CIEND", Number: "2", Type: "Integer"}
	h.Infos["AF"] = &vcfgo.Info{Id: "AF", Description: "AF", Number: "1", Type: "Float"}
	h.Infos["AC_AFR"] = &vcfgo.Info{Id: "AF_AFR", Description: "AF_AFR", Number: "1", Type: "Float"}

	vv := *v1
	vv.Info_ = vcfgo.NewInfoByte([]byte("DP=35"), h)
	s.v1 = &parsers.Variant{IVariant: &vv}
	s.v1.SetSource(0)
	v2 := *v1
	v2.Info_ = vcfgo.NewInfoByte([]byte("DP=44"), h)
	s.v2 = &parsers.Variant{IVariant: &v2}
	s.v2.Info().Set("AC_AFR", 33)
	s.v2.SetSource(1)

	sv1.Info_ = vcfgo.NewInfoByte([]byte("DP=35;SVLEN=15;CIPOS=-5,5;CIEND=-8,8"), h)
	s.sv1 = &parsers.Variant{IVariant: sv1}
	s.sv1.SetSource(0)

	v3 := *v1
	v3.Info_ = vcfgo.NewInfoByte([]byte("DP=88"), h)
	s.v3 = &parsers.Variant{IVariant: &v3}
	s.v3.SetSource(1)

	v, e := v1.Info_.Get("DP")
	c.Assert(e, IsNil)
	c.Assert(v, Equals, 35)

	v, e = v2.Info_.Get("DP")
	c.Assert(e, IsNil)
	c.Assert(v, Equals, 44)

	v, e = v3.Info_.Get("DP")
	c.Assert(e, IsNil)
	c.Assert(v, Equals, 88)

	s.v1.AddRelated(s.v2)
	s.v1.AddRelated(s.v3)
	s.sv1.AddRelated(s.v2)
	s.sv1.AddRelated(s.v3)

	c.Assert(2, Equals, len(s.v1.Related()))

	sbed, err := parsers.IntervalFromBedLine([]byte("chr1\t224\t244\t111\t222"))
	c.Assert(err, IsNil)
	s.bed = sbed.(*parsers.Interval)
	s.bed.SetSource(2)
	s.v1.AddRelated(s.bed)
	s.sv1.AddRelated(s.bed)

	s.src = Source{
		File:   "example/fitcons.bed",
		Op:     "mean",
		Name:   "fitcons_mean",
		Column: 4,
		Field:  "",
		Index:  1,
	}

	s.src0 = Source{
		File:   "example/exac.vcf",
		Op:     "first",
		Column: -1,
		Field:  "AC_AFR",
		Name:   "AC_AFR",
		Index:  0,
	}
	empty := make([]PostAnnotation, 0)

	code := `
function sum(t)
    local sum = 0
    for i=1,#t do
        sum = sum + t[i]
    end
    return sum
end

function mean(t)
    return sum(t) / #t
end
`

	s.annotator = NewAnnotator([]*Source{&s.src0, &s.src}, code, false, true, empty)

}
Beispiel #4
0
func makeBed(chrom string, start int, end int, val float32) *parsers.Interval {
	i, _ := parsers.IntervalFromBedLine([]byte(fmt.Sprintf("%s\t%d\t%d\t%.3f", chrom, start, end, val)))
	return i.(*parsers.Interval)
}