mirror of
https://github.com/metabarcoding/obitools4.git
synced 2026-11-10 01:24:41 +00:00
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.
This commit is contained in:
1 parent
0012a55cad
commit
a0d8187fd6
11 files changed
+601
-19
No files matched your search
@@ -0,0 +1,29 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user