Code refactoring

This commit is contained in:
2022-01-14 15:30:01 +01:00
parent 0d92b1f772
commit 402d54cb62
2 changed files with 26 additions and 26 deletions

View File

@ -1,6 +1,6 @@
package obialign package obialign
func __backtracking__(path_matrix []int, lseqA, lseqB int, path *[]int) []int { func _Backtracking(pathMatrix []int, lseqA, lseqB int, path *[]int) []int {
needed := (lseqA + lseqB) * 2 needed := (lseqA + lseqB) * 2
@ -19,7 +19,7 @@ func __backtracking__(path_matrix []int, lseqA, lseqB int, path *[]int) []int {
lleft := 0 lleft := 0
for i > -1 || j > -1 { for i > -1 || j > -1 {
step := __get_matrix__(&path_matrix, lseqA, i, j) step := __get_matrix__(&pathMatrix, lseqA, i, j)
// log.Printf("I: %d J:%d -> %d\n", i, j, step) // log.Printf("I: %d J:%d -> %d\n", i, j, step)
switch { switch {

View File

@ -4,7 +4,7 @@ import (
"math" "math"
) )
var __four_bits_count__ = []float64{ var _FourBitsCount = []float64{
0, // 0000 0, // 0000
1, // 0001 1, // 0001
1, // 0010 1, // 0010
@ -23,18 +23,18 @@ var __four_bits_count__ = []float64{
4, // 1111 4, // 1111
} }
var __initialized_dna_score__ = false var _InitializedDnaScore = false
var __nuc_part_match__ [32][32]float64 var _NucPartMatch [32][32]float64
var __nuc_score_part_match_match__ [100][100]int var _NucScorePartMatchMatch [100][100]int
var __nuc_score_part_match_mismatch__ [100][100]int var _NucScorePartMatchMismatch [100][100]int
func __match_ratio__(a, b byte) float64 { func _MatchRatio(a, b byte) float64 {
// count of common bits // count of common bits
cm := __four_bits_count__[a&b&15] cm := _FourBitsCount[a&b&15]
ca := __four_bits_count__[a&15] ca := _FourBitsCount[a&15]
cb := __four_bits_count__[b&15] cb := _FourBitsCount[b&15]
if cm == 0 || ca == 0 || cb == 0 { if cm == 0 || ca == 0 || cb == 0 {
return float64(0) return float64(0)
@ -43,7 +43,7 @@ func __match_ratio__(a, b byte) float64 {
return float64(cm) / float64(ca) / float64(cb) return float64(cm) / float64(ca) / float64(cb)
} }
func __logaddexp__(a, b float64) float64 { func _Logaddexp(a, b float64) float64 {
if a > b { if a > b {
a, b = b, a a, b = b, a
} }
@ -51,7 +51,7 @@ func __logaddexp__(a, b float64) float64 {
return b + math.Log1p(math.Exp(a-b)) return b + math.Log1p(math.Exp(a-b))
} }
func __match_score_ratio__(a, b byte) (float64, float64) { func _MatchScoreRatio(a, b byte) (float64, float64) {
l2 := math.Log(2) l2 := math.Log(2)
l3 := math.Log(3) l3 := math.Log(3)
@ -66,35 +66,35 @@ func __match_score_ratio__(a, b byte) (float64, float64) {
lO1E2 := lO1 + lE2 lO1E2 := lO1 + lE2
lO2E1 := lO2 + lE1 lO2E1 := lO2 + lE1
MM := __logaddexp__(lO1O2, lE1E2+l3) + l4 MM := _Logaddexp(lO1O2, lE1E2+l3) + l4
Mm := __logaddexp__(__logaddexp__(lO1E2, lO2E1), lE1E2+l2) + l4 Mm := _Logaddexp(_Logaddexp(lO1E2, lO2E1), lE1E2+l2) + l4
return MM, Mm return MM, Mm
} }
func __init_nuc_part_match__() { func _InitNucPartMatch() {
for i, a := range __four_bits_base_code__ { for i, a := range __four_bits_base_code__ {
for j, b := range __four_bits_base_code__ { for j, b := range __four_bits_base_code__ {
__nuc_part_match__[i][j] = __match_ratio__(a, b) _NucPartMatch[i][j] = _MatchRatio(a, b)
} }
} }
} }
func __init_nuc_score_part_match__() { func _InitNucScorePartMatch() {
for i := 0; i < 100; i++ { for i := 0; i < 100; i++ {
for j := 0; j < 100; j++ { for j := 0; j < 100; j++ {
MM, Mm := __match_score_ratio__(byte(i), byte(j)) MM, Mm := _MatchScoreRatio(byte(i), byte(j))
__nuc_score_part_match_match__[i][j] = int(MM*10 + 0.5) _NucScorePartMatchMatch[i][j] = int(MM*10 + 0.5)
__nuc_score_part_match_mismatch__[i][j] = int(Mm*10 + 0.5) _NucScorePartMatchMismatch[i][j] = int(Mm*10 + 0.5)
} }
} }
} }
func InitDNAScoreMatrix() { func _InitDNAScoreMatrix() {
if !__initialized_dna_score__ { if !_InitializedDnaScore {
__init_nuc_part_match__() _InitNucPartMatch()
__init_nuc_score_part_match__() _InitNucScorePartMatch()
__initialized_dna_score__ = true _InitializedDnaScore = true
} }
} }