github.com/biogo/biogo@v1.0.4/align/pals/dp/dp_test.go (about) 1 // Copyright ©2011-2013 The bíogo Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package dp 6 7 import ( 8 "testing" 9 10 "gopkg.in/check.v1" 11 12 "github.com/biogo/biogo/align" 13 "github.com/biogo/biogo/align/pals/filter" 14 "github.com/biogo/biogo/alphabet" 15 "github.com/biogo/biogo/seq/linear" 16 "github.com/biogo/biogo/util" 17 ) 18 19 var ( 20 k byte = 6 21 22 T = filter.Trapezoids{ 23 {Top: 452, Bottom: 0, Left: -128, Right: 3}, 24 {Top: 433, Bottom: 237, Left: -1120, Right: -1085}, 25 {Top: 628, Bottom: 447, Left: -1984, Right: -1917}, 26 {Top: 898, Bottom: 627, Left: -2624, Right: -2557}, 27 {Top: 939, Bottom: 868, Left: -2880, Right: -2845}, 28 {Top: 1024, Bottom: 938, Left: -3072, Right: -3005}, 29 } 30 H = Hits{ 31 {Abpos: 1, Bbpos: 0, Aepos: 290, Bepos: 242, LowDiagonal: -3, HighDiagonal: 54, Score: 101, Error: 0.19421487603305784}, 32 {Abpos: 365, Bbpos: 286, Aepos: 435, Bepos: 345, LowDiagonal: 74, HighDiagonal: 96, Score: 26, Error: 0.1864406779661017}, 33 {Abpos: 437, Bbpos: 341, Aepos: 507, Bepos: 400, LowDiagonal: 91, HighDiagonal: 113, Score: 26, Error: 0.1864406779661017}, 34 {Abpos: 3201, Bbpos: 642, Aepos: 3477, Bepos: 873, LowDiagonal: 2553, HighDiagonal: 2610, Score: 96, Error: 0.19480519480519481}, 35 {Abpos: 3980, Bbpos: 948, Aepos: 4066, Bepos: 1021, LowDiagonal: 3026, HighDiagonal: 3054, Score: 30, Error: 0.1917808219178082}, 36 } 37 ) 38 39 var ( 40 maxIGap = 5 41 diffCost = 3 42 sameCost = 1 43 matchCost = diffCost + sameCost 44 blockCost = diffCost * maxIGap 45 rMatchCost = float64(diffCost) + 1 46 ) 47 48 // Tests 49 func Test(t *testing.T) { check.TestingT(t) } 50 51 type S struct{} 52 53 var _ = check.Suite(&S{}) 54 55 func (s *S) TestAlignment(c *check.C) { 56 l := [...]byte{'A', 'C', 'G', 'T'} 57 Q := len(l) 58 a := &linear.Seq{Seq: make(alphabet.Letters, 0, util.Pow(Q, k))} 59 a.Alpha = alphabet.DNA 60 for _, i := range util.DeBruijn(byte(Q), k) { 61 a.Seq = append(a.Seq, alphabet.Letter(l[i])) 62 } 63 b := &linear.Seq{Seq: make(alphabet.Letters, 0, util.Pow(Q, k-1))} 64 b.Alpha = alphabet.DNA 65 for _, i := range util.DeBruijn(byte(Q), k-1) { 66 b.Seq = append(b.Seq, alphabet.Letter(l[i])) 67 } 68 aligner := NewAligner(a, b, int(k), 50, 0.80) 69 aligner.Costs = &Costs{ 70 MaxIGap: maxIGap, 71 DiffCost: diffCost, 72 SameCost: sameCost, 73 MatchCost: matchCost, 74 BlockCost: blockCost, 75 RMatchCost: rMatchCost, 76 } 77 hits := aligner.AlignTraps(T) 78 c.Check(hits, check.DeepEquals, H) 79 la, lb, err := hits.Sum() 80 c.Check(la, check.Equals, 791) 81 c.Check(lb, check.Equals, 664) 82 c.Check(err, check.Equals, nil) 83 for _, h := range H { 84 sa, sb := &linear.Seq{Seq: a.Seq[h.Abpos:h.Aepos]}, &linear.Seq{Seq: b.Seq[h.Bbpos:h.Bepos]} 85 sa.Alpha = alphabet.DNAgapped 86 sb.Alpha = alphabet.DNAgapped 87 smith := align.SW{ 88 {0, -1, -1, -1, -1}, 89 {-1, 2, -1, -1, -1}, 90 {-1, -1, 2, -1, -1}, 91 {-1, -1, -1, 2, -1}, 92 {-1, -1, -1, -1, 2}, 93 } 94 swa, _ := smith.Align(sa, sb) 95 fa := align.Format(sa, sb, swa, sa.Alpha.Gap()) 96 c.Logf("%v\n", swa) 97 c.Logf("%s\n%s\n", fa[0], fa[1]) 98 } 99 }