示例#1
0
文件: dp_test.go 项目: frogs/biogo
func (s *S) TestAlignment(c *check.C) {
	l := [...]byte{'A', 'C', 'G', 'T'}
	Q := len(l)
	a := &seq.Seq{Seq: make([]byte, 0, util.Pow(Q, k))}
	for _, i := range util.DeBruijn(byte(Q), k) {
		a.Seq = append(a.Seq, l[i])
	}
	b := &seq.Seq{Seq: make([]byte, 0, util.Pow(Q, k-1))}
	for _, i := range util.DeBruijn(byte(Q), k-1) {
		b.Seq = append(b.Seq, l[i])
	}
	aligner := NewAligner(a, b, int(k), 50, 0.80)
	aligner.Config = &AlignConfig{
		MaxIGap:    maxIGap,
		DiffCost:   diffCost,
		SameCost:   sameCost,
		MatchCost:  matchCost,
		BlockCost:  blockCost,
		RMatchCost: rMatchCost,
	}
	hits := aligner.AlignTraps(T)
	c.Check(hits, check.DeepEquals, H)
	la, lb, err := hits.Sum()
	c.Check(la, check.Equals, 791)
	c.Check(lb, check.Equals, 664)
	c.Check(err, check.Equals, nil)
	for _, h := range H {
		sa, sb := &seq.Seq{Seq: a.Seq[h.Abpos:h.Aepos]}, &seq.Seq{Seq: b.Seq[h.Bbpos:h.Bepos]}
		swm := [][]int{
			{2, -1, -1, -1, -1},
			{-1, 2, -1, -1, -1},
			{-1, -1, 2, -1, -1},
			{-1, -1, -1, 2, -1},
			{-1, -1, -1, -1, 0},
		}

		smith := &sw.Aligner{Matrix: swm, LookUp: sw.LookUpN, GapChar: '-'}
		swa, _ := smith.Align(sa, sb)
		c.Logf("a: %s\nb: %s\n", swa[0], swa[1])
	}
}
示例#2
0
文件: pals_test.go 项目: frogs/biogo
func (s *S) TestPack(c *check.C) {
	p := NewPacker("")
	for k := byte(1); k <= maxk; k++ {
		a := &seq.Seq{ID: fmt.Sprintf("deBruijn%d", k), Seq: make([]byte, 0, util.Pow(Q, k))}
		for _, i := range util.DeBruijn(byte(Q), k) {
			a.Seq = append(a.Seq, l[i])
		}
		c.Logf("%d: %s", k, p.Pack(a))
	}
	p.FinalisePack()
	c.Check(p.Packed.Len(), check.Equals, 94208)
}
示例#3
0
文件: pals_test.go 项目: frogs/biogo
func (s *S) SetUpSuite(c *check.C) {
	p := NewPacker("")
	for k := byte(1); k <= maxk; k++ {
		a := &seq.Seq{ID: fmt.Sprintf("deBruijn%d", k), Seq: make([]byte, 0, util.Pow(Q, k))}
		for _, i := range util.DeBruijn(byte(Q), k) {
			a.Seq = append(a.Seq, l[i])
		}
		p.Pack(a)
	}
	p.FinalisePack()
	ps = p.Packed
}
示例#4
0
func (s *S) TestFilterAndMerge(c *check.C) {
	l := [...]byte{'A', 'C', 'G', 'T'}
	Q := len(l)
	a := &seq.Seq{Seq: make([]byte, 0, util.Pow(Q, k))}
	for _, i := range util.DeBruijn(byte(Q), k) {
		a.Seq = append(a.Seq, l[i])
	}
	b := &seq.Seq{Seq: make([]byte, 0, util.Pow(Q, k-1))}
	for _, i := range util.DeBruijn(byte(Q), k-1) {
		b.Seq = append(b.Seq, l[i])
	}
	i, err := kmerindex.New(int(k), a)
	if err != nil {
		c.Fatalf("Failed to create kmerindex: %v", err)
	}
	i.Build()
	p := &Params{WordSize: int(k), MinMatch: 50, MaxError: 4, TubeOffset: 32}
	f := New(i, p)
	var sorter *morass.Morass
	if sorter, err = morass.New(FilterHit{}, "", "", 2<<20, false); err != nil {
		c.Fatalf("Failed to create morass: %v", err)
	}
	f.Filter(b, false, false, sorter)
	c.Check(sorter.Len(), check.Equals, int64(12))
	r := make([]FilterHit, 1, sorter.Len())
	for {
		err = sorter.Pull(&r[len(r)-1])
		if err != nil {
			r = r[:len(r)-1]
			break
		}
		r = append(r, FilterHit{})
	}
	c.Check(r, check.DeepEquals, []FilterHit{
		{QFrom: 0, QTo: 163, DiagIndex: 32},
		{QFrom: 141, QTo: 247, DiagIndex: 64},
		{QFrom: 237, QTo: 433, DiagIndex: 1120},
		{QFrom: 241, QTo: 347, DiagIndex: 96},
		{QFrom: 341, QTo: 452, DiagIndex: 128},
		{QFrom: 447, QTo: 565, DiagIndex: 1952},
		{QFrom: 542, QTo: 628, DiagIndex: 1984},
		{QFrom: 627, QTo: 814, DiagIndex: 2592},
		{QFrom: 786, QTo: 898, DiagIndex: 2624},
		{QFrom: 868, QTo: 939, DiagIndex: 2880},
		{QFrom: 938, QTo: 997, DiagIndex: 3040},
		{QFrom: 938, QTo: 1024, DiagIndex: 3072},
	})
	m := NewMerger(i, b, p, 5, false)
	for _, h := range r {
		m.MergeFilterHit(&h)
	}
	t := m.FinaliseMerge()
	sorter.CleanUp()
	c.Check(len(t), check.Equals, 6)
	la, lb := t.Sum()
	c.Check(la, check.Equals, 1257)
	c.Check(lb, check.Equals, 402)
	c.Check(t, check.DeepEquals, Trapezoids{
		{Next: nil, Top: 452, Bottom: 0, Left: -128, Right: 3},
		{Next: nil, Top: 433, Bottom: 237, Left: -1120, Right: -1085},
		{Next: nil, Top: 628, Bottom: 447, Left: -1984, Right: -1917},
		{Next: nil, Top: 898, Bottom: 627, Left: -2624, Right: -2557},
		{Next: nil, Top: 939, Bottom: 868, Left: -2880, Right: -2845},
		{Next: nil, Top: 1024, Bottom: 938, Left: -3072, Right: -3005},
	})
}