Debian Codegraph @

align/align_test.go

raw symbols SCIP
1 // Copyright ©2011-2012 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 align
6
7 import (
8 "fmt"
9 "strings"
10 "testing"
11
12 "github.com/biogo/biogo/alphabet"
13 "github.com/biogo/biogo/io/seqio/fasta"
14 "github.com/biogo/biogo/seq/linear"
15 "gopkg.in/check.v1"
16 )
17
18 // Tests
19 func Test(t *testing.T) { check.TestingT(t) }
20
21 type S struct{}
22
23 var _ = check.Suite(&S{})
24
25 func (s *S) TestWarning(c *check.C) { c.Log("\nFIXME: Tests only in example tests.\n") }
26
27 // https://github.com/biogo/biogo/issues/58
28 func (s *S) TestIssue58(c *check.C) {
29 a := "GCTCACTAAAAACACAATCTACAACAGACGTTGCACTAACACTGTAATTGCCTTTAGTCC"
30 b := "ACTGCGTA"
31
32 nwsa := &linear.Seq{Seq: alphabet.BytesToLetters([]byte(a))}
33 nwsa.Alpha = alphabet.DNAgapped
34 nwsb := &linear.Seq{Seq: alphabet.BytesToLetters([]byte(b))}
35 nwsb.Alpha = alphabet.DNAgapped
36
37 needle := NWAffine{
38 Matrix: Linear{
39 {0, -1, -1, -1, -1},
40 {-1, 1, -1, -1, -1},
41 {-1, -1, 1, -1, -1},
42 {-1, -1, -1, 1, -1},
43 {-1, -1, -1, -1, 1},
44 },
45 GapOpen: -1,
46 }
47
48 aln, err := needle.Align(nwsa, nwsb)
49 c.Check(err, check.Equals, nil)
50 c.Check(fmt.Sprint(aln), check.Equals, "[[0,4)/-=-5 [4,7)/[0,3)=3 [7,32)/-=-26 [32,34)/[3,5)=2 [34,43)/-=-10 [43,46)/[5,8)=3 [46,60)/-=-15]")
51 }
52
53 func BenchmarkSWAlign(b *testing.B) {
54 t := &linear.Seq{}
55 t.Alpha = alphabet.DNAgapped
56 r := fasta.NewReader(strings.NewReader(crspFa), t)
57 swsa, _ := r.Read()
58 swsb, _ := r.Read()
59
60 smith := SW{
61 {2, -1, -1, -1, -1},
62 {-1, 2, -1, -1, -1},
63 {-1, -1, 2, -1, -1},
64 {-1, -1, -1, 2, -1},
65 {-1, -1, -1, -1, 0},
66 }
67 b.ResetTimer()
68 for i := 0; i < b.N; i++ {
69 smith.Align(swsa, swsb)
70 }
71 }
72
73 func BenchmarkNWAlign(b *testing.B) {
74 t := &linear.Seq{}
75 t.Alpha = alphabet.DNAgapped
76 r := fasta.NewReader(strings.NewReader(crspFa), t)
77 nwsa, _ := r.Read()
78 nwsb, _ := r.Read()
79
80 needle := NW{
81 {10, -3, -1, -4, -5},
82 {-3, 9, -5, 0, -5},
83 {-1, -5, 7, -3, -5},
84 {-4, 0, -3, 8, -5},
85 {-4, -4, -4, -4, 0},
86 }
87
88 b.ResetTimer()
89 for i := 0; i < b.N; i++ {
90 needle.Align(nwsa, nwsb)
91 }
92 }
93
94 func BenchmarkSWAffineAlign(b *testing.B) {
95 t := &linear.Seq{}
96 t.Alpha = alphabet.DNAgapped
97 r := fasta.NewReader(strings.NewReader(crspFa), t)
98 swsa, _ := r.Read()
99 swsb, _ := r.Read()
100
101 smith := SWAffine{
102 Matrix: Linear{
103 {2, -1, -1, -1, -1},
104 {-1, 2, -1, -1, -1},
105 {-1, -1, 2, -1, -1},
106 {-1, -1, -1, 2, -1},
107 {-1, -1, -1, -1, 0},
108 },
109 GapOpen: -5,
110 }
111 b.ResetTimer()
112 for i := 0; i < b.N; i++ {
113 smith.Align(swsa, swsb)
114 }
115 }
116
117 func BenchmarkNWAffineAlign(b *testing.B) {
118 t := &linear.Seq{}
119 t.Alpha = alphabet.DNAgapped
120 r := fasta.NewReader(strings.NewReader(crspFa), t)
121 nwsa, _ := r.Read()
122 nwsb, _ := r.Read()
123
124 needle := NWAffine{
125 Matrix: Linear{
126 {10, -3, -1, -4, -5},
127 {-3, 9, -5, 0, -5},
128 {-1, -5, 7, -3, -5},
129 {-4, 0, -3, 8, -5},
130 {-4, -4, -4, -4, 0},
131 },
132 GapOpen: -10,
133 }
134
135 b.ResetTimer()
136 for i := 0; i < b.N; i++ {
137 needle.Align(nwsa, nwsb)
138 }
139 }