nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: cogent3/cogent3
Pull request #1376 (2023-04-21 06:12:58)

BUG: treat end as non-inclusive in generating SQL query


Patch:
diff --git a/src/cogent3/core/annotation_db.py b/src/cogent3/core/annotation_db.py
index e6cf1c981..23a8c83c3 100644
--- a/src/cogent3/core/annotation_db.py
+++ b/src/cogent3/core/annotation_db.py
@@ -217,7 +217,7 @@ def _matching_conditions(
         # only matches within bounds
         if partial:
             cond = [
-                f"(start <= {start} AND end >= {start})",  # straddles beginning of segment
+                f"(start <= {start} AND end > {start})",  # straddles beginning of segment
                 f"(start < {end} AND end >= {end})",  # straddles end of segment
                 f"(start <= {start} AND end >= {end})",  # includes segment
             ]
@@ -732,7 +732,7 @@ class GenbankAnnotationDb(SqliteAnnotationDbMixin):
             # we create the location data directly
             if location := record.get("location", None):
                 store["spans"] = numpy.array(
-                    sorted([sorted((s.start, s.stop)) for s in location]), dtype=int
+                    sorted([sorted((s.first(), s.last())) for s in location]), dtype=int
                 )
                 if strand := location.strand:
                     store["strand"] = strand


Test patch:
diff --git a/tests/test_core/test_annotation_db.py b/tests/test_core/test_annotation_db.py
index b259950de..b1809bc42 100644
--- a/tests/test_core/test_annotation_db.py
+++ b/tests/test_core/test_annotation_db.py
@@ -9,6 +9,7 @@ from cogent3.core.annotation_db import (
     GffAnnotationDb,
     SupportsFeatures,
     load_annotations,
+    _matching_conditions,
 )
 from cogent3.core.sequence import Sequence
 
@@ -248,7 +249,13 @@ def test_get_features_matching_start_stop(seq):
     got = list(seq.get_features_matching(start=2, stop=10))
     assert len(got) == 4
 
-@pytest.mark.xfail(reason="discuss with kath")
+
+def test_matching_conditions():
+    got, _ = _matching_conditions({'start': 1, 'end': 5}, partial=True)
+    expect = "((start <= 1 AND end > 1) OR (start < 5 AND end >= 5) OR (start <= 1 AND end >= 5))"
+    assert got == expect
+
+
 def test_get_features_matching_start_stop_seqview(seq):
     """testing that get_features_matching adjusts"""
     seq.annotate_from_gff(DATA_DIR / "simple.gff")
Repository: cogent3/cogent3
Pull request #1385 (2023-04-24 06:56:44)

ENH: SequenceCollectiuon.annotation_db can be reset
[CHANGED] removed over-ride of property in Alignment

[CHANGED] allow None to be assigned to SeqColl.annotation_db


Patch:
diff --git a/src/cogent3/core/alignment.py b/src/cogent3/core/alignment.py
index 05b5de8b8..8645e7ad2 100644
--- a/src/cogent3/core/alignment.py
+++ b/src/cogent3/core/alignment.py
@@ -65,7 +65,6 @@ from cogent3.core.genetic_code import get_code
 from cogent3.core.info import Info as InfoClass
 from cogent3.core.profile import PSSM, MotifCountsArray
 from cogent3.core.sequence import ArraySequence, Sequence, frac_same
-
 # which is a circular import otherwise.
 from cogent3.format.alignment import save_to_filename
 from cogent3.format.fasta import alignment_to_fasta
@@ -594,7 +593,7 @@ class _SequenceCollectionBase:
     def annotation_db(self, value):
         from cogent3.core.annotation_db import SupportsFeatures
 
-        if not isinstance(value, SupportsFeatures):
+        if value and not isinstance(value, SupportsFeatures):
             raise TypeError
         self._annotation_db = value
 
@@ -4623,26 +4622,6 @@ class Alignment(_Annotatable, AlignmentI, SequenceCollection):
         self.named_seqs = dict(list(zip(names, aligned_seqs)))
         self.seq_data = self._seqs = aligned_seqs
 
-    @property
-    def annotation_db(self):
-        return self._annotation_db
-
-    @annotation_db.setter
-    def annotation_db(self, value):
-        from cogent3.core.annotation_db import SupportsFeatures
-
-        if not isinstance(value, SupportsFeatures):
-            raise TypeError
-        self._annotation_db = value
-
-    @annotation_db.setter
-    def annotation_db(self, value):
-        from cogent3.core.annotation_db import SupportsFeatures
-
-        if not isinstance(value, SupportsFeatures):
-            raise TypeError
-        self._annotation_db = value
-
     def _coerce_seqs(self, seqs, is_array):
         if any(isinstance(seq, ArraySequence) for seq in seqs):
             seqs = [self.moltype.make_seq(str(seq), name=seq.name) for seq in seqs]


Test patch:
diff --git a/tests/test_core/test_alignment.py b/tests/test_core/test_alignment.py
index 692b86acd..3de02916a 100644
--- a/tests/test_core/test_alignment.py
+++ b/tests/test_core/test_alignment.py
@@ -3394,6 +3394,17 @@ def test_copy_annotations(cls, gff_db):
     assert seq_coll.annotation_db.num_matches() == expect
 
 
+@pytest.mark.parametrize("cls", (SequenceCollection, Alignment))
+def test_assign_none(cls, gff_db):
+    """assigning None to annotation_db breaks conection"""
+
+    seq_coll = cls({"seq1": "ACGU", "seq2": "CGUA", "test_seq": "CCGU"})
+    seq_coll.add_feature(seqid="seq1", biotype="xyz", name="abc", spans=[(1, 2)])
+    seq_coll.add_feature(seqid="seq2", biotype="xyzzz", name="abc", spans=[(1, 2)])
+    seq_coll.annotation_db = None
+    assert seq_coll.annotation_db is None
+
+
 def test_copy_annotations_incompat_fails(seqcoll_db, gb_db):
     """copy_annotations copies records from annotation db"""
     with pytest.raises(TypeError):