-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpal_test.go
113 lines (111 loc) · 2.62 KB
/
pal_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package pal
import (
"github.com/evolbioinf/fasta"
"io/ioutil"
"os"
"strconv"
"testing"
)
func TestScoreMatrix(t *testing.T) {
get := make([]string, 0)
want := make([]string, 0)
sm := NewScoreMatrix(1, -3)
get = append(get, sm.String())
bf := "./doc/blosum62.txt"
f, err := os.Open(bf)
if err != nil {
t.Errorf("can't open %q", bf)
}
defer f.Close()
sm = ReadScoreMatrix(f)
get = append(get, sm.String())
sm = NewByteScoreMatrix(1, -3)
s1 := int(sm.Score(byte('_'), byte('_')))
s2 := int(sm.Score(byte('_'), byte('%')))
get = append(get, strconv.Itoa(s1))
get = append(get, strconv.Itoa(s2))
for i, _ := range get {
f := "data/sm" + strconv.Itoa(i+1) + ".txt"
b, err := ioutil.ReadFile(f)
if err != nil {
t.Errorf("can't open %q", f)
}
want = append(want, string(b))
}
for i, g := range get {
w := want[i]
if g != w {
t.Errorf("get:\n%s\nwant:\n%s", g, w)
}
}
}
func TestAlignment(t *testing.T) {
get := make([]string, 0)
want := make([]string, 0)
bf := "./doc/blosum62.txt"
f, err := os.Open(bf)
if err != nil {
t.Errorf("can't open %q", bf)
}
defer f.Close()
sm := ReadScoreMatrix(f)
q := fasta.NewSequence("Q", []byte("MKFLALF"))
s := fasta.NewSequence("S", []byte("MKYLILLF"))
a := NewGlobalAlignment(q, s, sm, -5, -2)
a.Align()
get = append(get, a.String()+"\n")
s1 := "CATTGGGATGATGCACCTATATTGTGAGGTCTGTTACACTG" +
"TCGTTCCGCAGATCGAGCAATCCCGTATCCTTTACATAT" +
"TGCCGTGTGGGGTAAGGTGC"
s2 := "TTGTGAGGTCTGTTACACTGTCCGCAGATCGAGCAATCC" +
"CGTATCCTTTACATATTGCCGTGTGGGGTAAGGTGCC" +
"ATTGGGATGATGCACCTATA"
q = fasta.NewSequence("Q", []byte(s1))
s = fasta.NewSequence("S", []byte(s2))
sm = NewScoreMatrix(1, -3)
o := NewOverlapAlignment(q, s, sm, -5, -2)
o.Align()
get = append(get, o.String()+"\n")
fn := "data/dmAdhAdhdup.fasta"
f, err = os.Open(fn)
if err != nil {
t.Errorf("can't open %q", fn)
}
defer f.Close()
sc := fasta.NewScanner(f)
sc.ScanSequence()
q = sc.Sequence()
fn = "data/dgAdhAdhdup.fasta"
f, err = os.Open(fn)
if err != nil {
t.Errorf("can't open %q", fn)
}
defer f.Close()
sc = fasta.NewScanner(f)
sc.ScanSequence()
s = sc.Sequence()
l := NewLocalAlignment(q, s, sm, -5, -2)
l.Align()
str := l.String()
l.Align()
str += "\n" + l.String() + "\n"
get = append(get, str)
str = a.PrintMatrix('v')
get = append(get, str)
str = a.PrintMatrix('t')
get = append(get, str)
for i, _ := range get {
f := "data/a" + strconv.Itoa(i+1) + ".txt"
b, err := ioutil.ReadFile(f)
if err != nil {
t.Errorf("can't open %q", f)
}
want = append(want, string(b))
}
for i, g := range get {
w := want[i]
if g != w {
t.Errorf("get:\n%s\nwant:\n%s", g, w)
}
}
}