-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmsa_test.go
140 lines (121 loc) · 2.85 KB
/
msa_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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package seq
import (
"fmt"
"testing"
)
func TestMSAA3M(t *testing.T) {
tests := [][]string{
alignA3M,
trickyA3M,
trickyA3MShort,
}
answers := [][]string{
alignA2M,
trickyA2M,
trickyA2MShort,
}
for i := 0; i < len(tests); i++ {
test := makeSeqs(tests[i])
answer := makeMSA(makeSeqs(answers[i]))
computed := NewMSA()
computed.AddSlice(test)
testEqualAlign(t, computed, answer)
}
}
func TestMSAA2M(t *testing.T) {
tests := [][]string{
alignA2M,
}
answers := [][]string{
alignA2M,
}
for i := 0; i < len(tests); i++ {
test := makeSeqs(tests[i])
answer := makeMSA(makeSeqs(answers[i]))
computed := NewMSA()
computed.AddSlice(test)
testEqualAlign(t, computed, answer)
}
}
func TestMSAFasta(t *testing.T) {
tests := [][]string{
alignFasta,
}
answers := [][]string{
alignA2M,
}
for i := 0; i < len(tests); i++ {
test := makeSeqs(tests[i])
answer := makeMSA(makeSeqs(answers[i]))
computed := NewMSA()
computed.AddFastaSlice(test)
testEqualAlign(t, computed, answer)
}
}
func TestGetA3M(t *testing.T) {
test := "ABCD---...ABCD"
answer := []Residue("ABCD---ABCD")
msa := makeMSA(makeSeqs([]string{test}))
testEqualSeq(t, msa.GetA3M(0).Residues, answer)
}
func TestGetA2M(t *testing.T) {
test := "ABCD---...ABCD"
msa := makeMSA(makeSeqs([]string{test}))
testEqualSeq(t, msa.GetA2M(0).Residues, []Residue(test))
}
func TestGetFasta(t *testing.T) {
test := "ABCD---...ABCD"
answer := []Residue("ABCD------ABCD")
msa := makeMSA(makeSeqs([]string{test}))
testEqualSeq(t, msa.GetFasta(0).Residues, answer)
}
func testEqualAlign(t *testing.T, computed, answer MSA) {
if computed.Len() != answer.Len() {
t.Fatalf("Lengths of MSAs differ: %d != %d",
computed.Len(), answer.Len())
}
scomputed := makeStrings(computed.Entries)
sanswer := makeStrings(answer.Entries)
if len(scomputed) != len(sanswer) {
t.Fatalf("\nLengths of entries in MSAs differ: %d != %d",
len(scomputed), len(sanswer))
}
for i := 0; i < len(scomputed); i++ {
c, a := scomputed[i], sanswer[i]
if c != a {
t.Fatalf("\nComputed sequence in MSA is\n\n%s\n\n"+
"but answer is\n\n%s", c, a)
}
}
}
func testEqualSeq(t *testing.T, computed, answer []Residue) {
scomputed := fmt.Sprintf("%s", computed)
sanswer := fmt.Sprintf("%s", answer)
if scomputed != sanswer {
t.Fatalf("\nComputed sequence is\n\n%s\n\n"+
"but answer is\n\n%s", scomputed, sanswer)
}
}
func makeMSA(seqs []Sequence) MSA {
return MSA{
Entries: seqs,
length: len(seqs[0].Residues),
}
}
func makeSeqs(strs []string) []Sequence {
seqs := make([]Sequence, len(strs))
for i, str := range strs {
seqs[i] = Sequence{
Name: fmt.Sprintf("%d", i),
Residues: []Residue(str),
}
}
return seqs
}
func makeStrings(seqs []Sequence) []string {
strs := make([]string, len(seqs))
for i, s := range seqs {
strs[i] = fmt.Sprintf("%s", s.Residues)
}
return strs
}