-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcablastp_test.go
136 lines (125 loc) · 2.86 KB
/
cablastp_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
package mica
import (
"bytes"
"strings"
"testing"
)
func TestSeedHashing(t *testing.T) {
seedSize := 4
seedLowComplexity := 6
type test struct {
kmer string
hash int
}
tests := []test{
{"ABCD", 578},
{"AAAA", 0},
}
seeds := NewSeeds(seedSize, seedLowComplexity)
for _, test := range tests {
thash := seeds.hashKmer([]byte(test.kmer))
tkmer := seeds.unhashKmer(test.hash)
if thash != test.hash {
t.Fatalf("The kmer '%s' hashed to %d but should have hashed to %d.",
test.kmer, thash, test.hash)
}
if string(tkmer) != test.kmer {
t.Fatalf("The hash %d unhashed to '%s' but should have "+
"unhashed to '%s'.", test.hash, string(tkmer), test.kmer)
}
}
}
func TestDBConfIO(t *testing.T) {
dbConf := DefaultDBConf
buf := new(bytes.Buffer)
dbConf.Write(buf)
dbConfTest, err := LoadDBConf(buf)
if err != nil {
t.Fatal(err)
}
if dbConf != dbConfTest {
t.Fatalf("%v != %v", dbConf, dbConfTest)
}
}
func TestEditScripts(t *testing.T) {
type test struct {
fromSeq, toSeq string
alignedFromSeq, alignedToSeq string
script string
}
tests := []test{
{
// Yes, this is a nucleotide sequence. But that doesn't matter.
// This is taken straight from the CaBLAST paper.
"GTTCACTTATGTATTCATATGATTTTGGCAA",
"GTTCACGTGTATATTTATATAATTTTGGCAA",
"GTTCACTTATGTATTC--ATATGATTTTGGCAA", // in alignment
"GTTCACG--TGTATATTTATATAATTTTGGCAA", // in alignment
"s6Gd1--s7ATi2TTs4A",
},
}
sep := strings.Repeat("-", 45)
for _, test := range tests {
// Check that the edit script generated by the alignment of 'from'
// and 'to' is correct.
tval := newEditScript(
[]byte(test.alignedFromSeq), []byte(test.alignedToSeq))
t.Log("")
for _, mod := range tval.mods {
t.Log(mod.String())
}
if tval.String() != test.script {
t.Fatalf(
`The EditScript generated by
%s
%s
%s
%s
resulted in
%s
%s
%s
but should be
%s
%s
%s`,
sep, test.alignedFromSeq, test.alignedToSeq, sep,
sep, tval.String(), sep,
sep, test.script, sep)
}
// Check that parsing the script and converting it back to a string
// yields the same script.
checkScript, err := NewEditScriptParse(test.script)
if err != nil {
t.Fatalf("Parsing '%s' caused: %s", test.script, err)
}
if checkScript.String() != test.script {
t.Fatalf(
`Parsing
%s
%s
%s
and converting it back to a string resulted in
%s
%s
%s
but should be
%s
%s
%s`,
sep, test.script, sep,
sep, checkScript.String(), sep,
sep, test.script, sep)
}
// Finally, check that re-applying test.script to fromSeq
// yields toSeq exactly.
toSeq := string(tval.Apply([]byte(test.fromSeq)))
if toSeq != test.toSeq {
t.Fatalf("Applying the edit script '%s' to the sequence '%s' "+
"resulted in\n%s\n%s\n%s\nbut should be\n%s\n%s\n%s",
test.script, test.fromSeq,
sep, toSeq, sep,
sep, test.toSeq, sep)
}
}
}