-
Notifications
You must be signed in to change notification settings - Fork 3
/
align_test.go
146 lines (129 loc) · 4.26 KB
/
align_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
141
142
143
144
145
146
// Copyright 2015 TREAT Authors. All rights reserved.
//
// This file is part of TREAT.
//
// TREAT is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// TREAT is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with TREAT. If not, see <http://www.gnu.org/licenses/>.
package treat
import (
"bytes"
"fmt"
"os"
"regexp"
"strconv"
"strings"
"testing"
"github.com/aebruno/gofasta"
)
func TestAlign(t *testing.T) {
fe := "TTTCTGAGTTTAGTAT"
pe := "TTTTTTCTTTTGAGTTTTTTAGTATT"
cl := "TTTTCTTTGAGTTTAGTATTT"
a := NewFragment("a", fe, FORWARD, 't')
b := NewFragment("b", pe, FORWARD, 't')
c := NewFragment("c", cl, FORWARD, 't')
tmpl, err := NewTemplate(a, b, nil, nil)
if err != nil {
t.Errorf("%s", err)
}
buf := new(bytes.Buffer)
aln := NewAlignment(c, tmpl, false)
aln.WriteTo(buf, c, tmpl, 80)
//fmt.Printf("%s", buf.String())
}
func parseKeyVal(id string) map[string]int {
attr := make(map[string]int)
pattern := regexp.MustCompile(`[^=\s]+=\-?\d+`)
matches := pattern.FindAllString(id, -1)
for _, kv := range matches {
parts := strings.Split(kv, "=")
ival, _ := strconv.Atoi(parts[1])
attr[parts[0]] = ival
}
return attr
}
func TestAlignFragments(t *testing.T) {
tmpl, err := NewTemplateFromFasta("examples/test-templates.fa", FORWARD, 't')
if err != nil {
t.Errorf("%s", err)
}
if tmpl.Size() != 3 {
t.Errorf("Wrong template size. %d != %d", tmpl.Size(), 5)
}
f, err := os.Open("examples/test-sample.fa")
if err != nil {
t.Errorf("Failed to open test sample data")
}
defer f.Close()
for rec := range gofasta.SimpleParser(f) {
attr := parseKeyVal(rec.Id)
frag := NewFragment(rec.Id, rec.Seq, FORWARD, rune('t'))
aln := NewAlignment(frag, tmpl, false)
if int(aln.EditStop) != attr["ess"] {
buf := new(bytes.Buffer)
aln.WriteTo(buf, frag, tmpl, 80)
fmt.Printf("%s", buf.String())
t.Errorf("Wrong ESS. %d != %d for sequence id: %s", int(aln.EditStop), attr["ess"], rec.Id)
}
if int(aln.JuncStart) != attr["jss"] {
buf := new(bytes.Buffer)
aln.WriteTo(buf, frag, tmpl, 80)
fmt.Printf("%s", buf.String())
t.Errorf("Wrong JSS. %d != %d for sequence id: %s", int(aln.JuncStart), attr["jss"], rec.Id)
}
if int(aln.JuncEnd) != attr["jes"] {
buf := new(bytes.Buffer)
aln.WriteTo(buf, frag, tmpl, 80)
fmt.Printf("%s", buf.String())
t.Errorf("Wrong JES. %d != %d for sequence id: %s", int(aln.JuncEnd), attr["jes"], rec.Id)
}
if int(aln.JuncLen) != (attr["jes"] - attr["ess"]) {
buf := new(bytes.Buffer)
aln.WriteTo(buf, frag, tmpl, 80)
fmt.Printf("%s", buf.String())
t.Errorf("Wrong Junc Length. %d != %d for sequence id: %s", int(aln.JuncLen), (attr["jes"] - attr["ess"]), rec.Id)
}
if int(aln.AltEditing) != attr["alt"] {
buf := new(bytes.Buffer)
aln.WriteTo(buf, frag, tmpl, 80)
fmt.Printf("%s", buf.String())
t.Errorf("Wrong Alt Editing. %d != %d for sequence id: %s", int(aln.AltEditing), attr["alt"], rec.Id)
}
if int(aln.HasMutation) != attr["has_mutation"] {
buf := new(bytes.Buffer)
aln.WriteTo(buf, frag, tmpl, 80)
fmt.Printf("%s", buf.String())
t.Errorf("Wrong Has Mutation. %d != %d for sequence id: %s", int(aln.HasMutation), attr["has_mutation"], rec.Id)
}
if int(aln.Mismatches) != attr["mismatches"] {
buf := new(bytes.Buffer)
aln.WriteTo(buf, frag, tmpl, 80)
fmt.Printf("%s", buf.String())
t.Errorf("Wrong Mismatch count. %d != %d for sequence id: %s", int(aln.Mismatches), attr["mismatches"], rec.Id)
}
if int(aln.Indel) != attr["indel"] {
buf := new(bytes.Buffer)
aln.WriteTo(buf, frag, tmpl, 80)
fmt.Printf("%s", buf.String())
t.Errorf("Wrong Indel. %d != %d for sequence id: %s", int(aln.Indel), attr["indel"], rec.Id)
}
}
}
func BenchmarkBinaryMarshal(b *testing.B) {
a := new(Alignment)
x := new(Alignment)
for i := 0; i < b.N; i++ {
buf, _ := a.MarshalBinary()
x.UnmarshalBinary(buf)
}
}