Skip to content

Commit 4aa8193

Browse files
committed
Merge pull request #4 from 6br/linear_fix
Fix the calc of point score
2 parents 2fb758c + d4db4f0 commit 4aa8193

File tree

1 file changed

+29
-21
lines changed

1 file changed

+29
-21
lines changed

src/real_linear_gotoh.go

+29-21
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func (l *Rgotoh) Length() {
4545
l.RegionAlign(0, len(l.x), 0, len(l.y), true)
4646
}
4747

48-
func (l *Rgotoh) RegionAlign(i1 int, i2 int, j1 int, j2 int, order bool) (result int, class int) {
48+
func (l *Rgotoh) RegionAlign(i1 int, i2 int, j1 int, j2 int, order bool) (int, int, int) {
4949
var m = i2 - i1
5050
var n = j2 - j1
5151
l.h[0][0][0] = 0
@@ -85,7 +85,7 @@ func (l *Rgotoh) RegionAlign(i1 int, i2 int, j1 int, j2 int, order bool) (result
8585
l.h[2][i][0] = l.h[2][i][1]
8686
}
8787
}
88-
return l.ScoreArgs(m)
88+
return l.h[0][m][0], l.h[1][m][0], l.h[2][m][0] //l.ScoreArgs(m)
8989
}
9090

9191
func (l Rgotoh) ScoreArgs(x int) (e int, k int) {
@@ -104,6 +104,29 @@ func (l Rgotoh) Print(i int, j int) (string, string, string) {
104104
//return l.linearSpaceAlign(0, len(l.x), 0, len(l.y))
105105
}
106106

107+
func (l Rgotoh) pointMaxScore(i1 int, j1 int, i2 int, j2 int, ih int, jh int) int {
108+
tmp11, tmp12, tmp13 := l.RegionAlign(i1, ih, j1, jh, true)
109+
tmp21, tmp22, tmp23 := l.RegionAlign(ih, i2, jh, j2, false)
110+
_, d := l.Geted()
111+
array := make([]int, 8)
112+
array[0] = tmp11 + tmp21
113+
array[1] = tmp11 + tmp22
114+
array[2] = tmp11 + tmp23
115+
array[3] = tmp12 + tmp21
116+
array[4] = tmp12 + tmp22 + d
117+
array[5] = tmp12 + tmp23
118+
array[6] = tmp13 + tmp21
119+
array[7] = tmp13 + tmp23 + d
120+
121+
tmp := math.MinInt64
122+
for _, v := range array {
123+
if tmp < v {
124+
tmp = v
125+
}
126+
}
127+
return tmp
128+
}
129+
107130
func (l Rgotoh) LinearSpace(i0 int, j0 int, i int, j int, score int) (p string, q string, r string) {
108131
if (i < i0 && j == j0) || (j < j0 && i == i0) {
109132
return
@@ -128,13 +151,7 @@ func (l Rgotoh) LinearSpace(i0 int, j0 int, i int, j int, score int) (p string,
128151
min = j - 70
129152
}
130153
for jh := j; jh >= min; jh-- {
131-
tmp1, err1 := l.RegionAlign(0, i, 0, jh, true)
132-
tmp2, err2 := l.RegionAlign(i, len(l.x), jh, len(l.y), false)
133-
tmp := tmp1 + tmp2
134-
_, d := l.Geted()
135-
if err1 == err2 && err2 >= 1 {
136-
tmp += d
137-
}
154+
tmp := l.pointMaxScore(0, 0, len(l.x), len(l.y), i, jh)
138155
//fmt.Println(tmp1, tmp2, err1, err2, tmp, jh)
139156
if tmp == score {
140157
maxj = jh
@@ -169,23 +186,14 @@ func (l Rgotoh) LinearSpace(i0 int, j0 int, i int, j int, score int) (p string,
169186

170187
func (l Rgotoh) LinearBinaryAlign(i1 int, i2 int, j1 int, j2 int, score int) (p string, q string, r string) {
171188
if i2-i1 <= 100 || j2-j1 <= 100 {
172-
//fmt.Println(i1, j1, i2, j2, "delegate")
173189
return l.LinearSpace(i1, j1, i2, j2, score)
174190
}
175191
ih := ((i1 + i2) / 2)
176-
if ih >= len(l.x) || ih < i1 {
177-
panic(i1 + i2)
178-
}
192+
179193
maxscore, maxj := -1000, j1+1
180194
for jh := j2; jh >= j1; jh-- {
181-
tmp1, err1 := l.RegionAlign(i1, ih, j1, jh, true)
182-
tmp2, err2 := l.RegionAlign(ih, i2, jh, j2, false)
183-
//fmt.Println(tmp1, tmp2)
184-
tmp := tmp1 + tmp2
185-
_, d := l.Geted()
186-
if err1 >= 1 && err2 >= 1 {
187-
tmp += d
188-
}
195+
tmp := l.pointMaxScore(i1, j1, i2, j2, ih, jh)
196+
189197
//fmt.Println(i1, i2, j1, j2, ih, jh, tmp)
190198
if tmp > maxscore {
191199
maxscore = tmp

0 commit comments

Comments
 (0)