Files
obitools4/pkg/obikmer/kmer_lcs_obialign_test.go
Eric Coissac a0d8187fd6 Implement k-mer distance metrics and constrained generation
Adds support for Hamming distance, constrained k-mer generation, and optimized Longest Common Subsequence (LCS) calculations using scalar, batch, and SIMD methods.

This includes new methods for k-mer distance calculation, structures for k-mer constraints, and SIMD-based batch processing for LCS to improve performance and correctness.
2026-11-03 09:23:37 +11:00

30 lines
989 B
Go

package obikmer_test
import (
"math/rand"
"testing"
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obialign"
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obikmer"
"git.metabarcoding.org/obitools/obitools4/obitools4/pkg/obiseq"
)
// KmerLCS must reproduce obialign.FastLCSScore on the decoded sequences.
func TestKmerLCSMatchesFastLCSScore(t *testing.T) {
rng := rand.New(rand.NewSource(4))
for _, k := range []int{1, 2, 4, 9, 15, 21, 31} {
mask := uint64(1)<<(2*uint(k)) - 1
for n := 0; n < 300; n++ {
a, b := rng.Uint64()&mask, rng.Uint64()&mask
sa := obiseq.NewBioSequence("a", obikmer.DecodeKmer(a, k, nil), "")
sb := obiseq.NewBioSequence("b", obikmer.DecodeKmer(b, k, nil), "")
lcs, alen := obialign.FastLCSScore(sa, sb, -1, nil)
got := obikmer.KmerLCS(a, b, k)
if got.LCS != lcs || got.AlignLen != alen {
t.Fatalf("k=%d %s/%s: KmerLCS=%+v, FastLCSScore=(%d,%d)",
k, sa.String(), sb.String(), got, lcs, alen)
}
}
}
}