Repository: cogent3/cogent3
Pull request #1623 (2023-11-15 02:35:55)

MAINT: misc changes


Patch:
diff --git a/doc/draw/aln/plot_aln-dotplot-1.rst b/doc/draw/aln/plot_aln-dotplot-1.rst
index 38aaad1d3..1ba54e734 100644
--- a/doc/draw/aln/plot_aln-dotplot-1.rst
+++ b/doc/draw/aln/plot_aln-dotplot-1.rst
@@ -14,8 +14,6 @@ The method returns a drawable, as demonstrated below between unaligned sequences
 
 .. jupyter-execute::
 
-    import os
-
     from cogent3 import load_unaligned_seqs
 
     seqs = load_unaligned_seqs("data/SCA1-cds.fasta", moltype="dna")
diff --git a/src/cogent3/align/pycompare.py b/src/cogent3/align/pycompare.py
index 2cdf0216e..ac68fe348 100644
--- a/src/cogent3/align/pycompare.py
+++ b/src/cogent3/align/pycompare.py
@@ -488,7 +488,7 @@ class MatchedSeqPaths:
         return trace
 
 
-def _calc_seed_size(w: int, t: int, min_val: int = 5) -> int:
+def _calc_seed_size(w: int, t: int) -> int:
     """computes k-mer size
 
     Parameters
@@ -497,23 +497,17 @@ def _calc_seed_size(w: int, t: int, min_val: int = 5) -> int:
         window size
     t : int
         threshold for minimum number of matches
-    min_val : int
-        minimum k-mer size
 
     Returns
     -------
     int
-        k-mer size
+        returns the larger of (w // k) * k <= t OR w - t + 1
     """
-
     assert 0 < t <= w, f"threshold={t} > window size={w}"
-    d = w - t
-    if w == t:
-        return w
-    elif d > t:
-        return t
-    k = t // d
-    return max(k, min_val)
+
+    # k should be such that (w % k) * k < threshold
+    denom = w - t + 1
+    return max(min(w // denom, t), denom)
 
 
 def find_matched_paths(
@@ -536,8 +530,7 @@ def find_matched_paths(
     window : int
         size of sequence segment to be compared
     threshold : int
-        Minimum number of positions that must be equal within the window.
-        Less than or equal to window.
+        Minimum number of positions that must be equal within the window.Less than or equal to window.
 
     Returns
     -------
@@ -579,16 +572,4 @@ def find_matched_paths(
 
         paths.append(ref_coord, other_coord)
 
-    for y_intercept in paths.paths:
-        if len(paths.paths[y_intercept]) == 1:
-            continue
-        merged = [paths.paths[y_intercept][0]]
-        for x2, y2 in paths.paths[y_intercept][1:]:
-            x1, y1 = merged[-1]
-            if x1.overlap(x2):
-                merged[-1] = (x1 | x2, y1 | y2)
-            else:
-                merged.append((x2, y2))
-        paths.paths[y_intercept] = merged
-
     return paths
diff --git a/src/cogent3/core/alignment.py b/src/cogent3/core/alignment.py
index 9d8539fd9..624bb89a3 100644
--- a/src/cogent3/core/alignment.py
+++ b/src/cogent3/core/alignment.py
@@ -1859,7 +1859,6 @@ class _SequenceCollectionBase:
             isinstance(self, AlignmentI),
             window=window,
             threshold=threshold,
-            k=k,
             min_gap=min_gap,
             xtitle=None if annotated else seq1.name,
             ytitle=None if annotated else seq2.name,


Test patch:
diff --git a/tests/test_align/test_compare.py b/tests/test_align/test_compare.py
index f45dbb631..9e2213fb8 100644
--- a/tests/test_align/test_compare.py
+++ b/tests/test_align/test_compare.py
@@ -60,15 +60,14 @@ def test_find_matched_k_eq_1():
 
 
 def test_calc_seed_size():
-    """default seed size should not be larger than than threshold"""
-    for i in range(2, 30):
-        x = _calc_seed_size(30, i)
-        assert x <= i
+    x = _calc_seed_size(20, 20)
+    assert x == 20
 
+    x = _calc_seed_size(20, 19)
+    assert x == 10
 
-def test_calc_seed_size_singleton_window():
-    x = _calc_seed_size(1, 1)
-    assert x == 1
+    x = _calc_seed_size(20, 14)
+    assert x == 7
 
 
 def test_segment():
@@ -390,16 +389,6 @@ def test_find_matched_with_rc():
     assert x == yrc
 
 
-def test_find_matched_with_small_seed():
-    s1 = make_seq("CACACCACTGCAGTCGGATAGACC", moltype="dna", name="s1")
-    s2 = make_seq("GGTCTATCCGACTGCAGTGGTGTG", moltype="dna", name="s2")
-    k = 2
-    expect = _brute_force(s1, s2, 4, 4)
-    sk = SeqKmers(s1, k=k, canonical="ACGT")
-    got = find_matched_paths(seq_kmers=sk, seq1=s1, seq2=s2, window=4, threshold=4)
-    assert got.paths == expect.paths
-
-
 @pytest.mark.parametrize("w,t", [(4, 4), (3, 3)])
 def test_find_matched_1seq(w, t):
     s = make_seq("CACACCACTGCAGTCGGATAGACC", moltype="dna", name="s1")
diff --git a/tests/test_core/test_annotation_db.py b/tests/test_core/test_annotation_db.py
index 7b10eab02..c90509ba2 100644
--- a/tests/test_core/test_annotation_db.py
+++ b/tests/test_core/test_annotation_db.py
@@ -949,4 +949,4 @@ def test_gbdb_get_parent_fails_no_coords(gb_db):
 
 def test_load_annotations_invalid_path():
     with pytest.raises(IOError):
-        db = load_annotations(path="invalidfile.gff3")
+        load_annotations(path="invalidfile.gff3")