Skip to content

Commit

Permalink
DEP: fix end->stop deprecation warnings in other sectionds of code
Browse files Browse the repository at this point in the history
  • Loading branch information
rmcar17 committed Mar 13, 2024
1 parent 18608c8 commit 8ded05f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 19 deletions.
5 changes: 3 additions & 2 deletions src/cogent3/core/alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
passed in a stream of two-item label, sequence pairs. However, this can
cause confusion when testing.
"""

from __future__ import annotations

import functools
Expand Down Expand Up @@ -5289,7 +5290,7 @@ def _get_seq_features(
seqname = seqid_to_seqname[seqid]
seq = self.named_seqs[seqname]
# we use parent seqid, stored on SeqView
parent_id, start, end, _ = seq.data.parent_coordinates()
parent_id, start, stop, _ = seq.data.parent_coordinates()
offset = seq.data.annotation_offset

for feature in self.annotation_db.get_features_matching(
Expand All @@ -5299,7 +5300,7 @@ def _get_seq_features(
on_alignment=False,
allow_partial=allow_partial,
start=start,
end=end,
stop=stop,
):
if offset:
feature["spans"] = (array(feature["spans"]) - offset).tolist()
Expand Down
4 changes: 2 additions & 2 deletions src/cogent3/core/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,14 @@ def get_parent(self, **kwargs):
"""generator returns parent features of self optionally matching biotype"""
offset = getattr(self.parent, "annotation_offset", 0)
start = self.map.start + offset
end = self.map.end + offset
stop = self.map.end + offset

make_feature = self.parent.make_feature
db = self.parent.annotation_db
for record in db.get_feature_parent(
name=self.name,
start=start,
end=end,
stop=stop,
**kwargs,
):
record["spans"] = array(record["spans"]) - offset
Expand Down
33 changes: 22 additions & 11 deletions src/cogent3/core/annotation_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
import numpy
import typing_extensions

import cogent3.util.warning as c3warn

from cogent3._version import __version__
from cogent3.util.deserialise import register_deserialiser
from cogent3.util.misc import extend_docstring_from, get_object_provenance
from cogent3.util.progress_display import display_wrap
from cogent3.util.table import Table
import cogent3.util.warning as c3warn


OptionalInt = typing.Optional[int]
Expand Down Expand Up @@ -73,11 +74,14 @@ class FeatureDataType(typing.TypedDict):

@typing.runtime_checkable
class SerialisableType(typing.Protocol): # pragma: no cover
def to_rich_dict(self) -> dict: ...
def to_rich_dict(self) -> dict:
...

def to_json(self) -> str: ...
def to_json(self) -> str:
...

def from_dict(self, data): ...
def from_dict(self, data):
...


@typing.runtime_checkable
Expand All @@ -99,7 +103,8 @@ def get_features_matching(
strand: OptionalStr = None,
attributes: OptionalStr = None,
on_alignment: OptionalBool = None,
) -> typing.Iterator[FeatureDataType]: ...
) -> typing.Iterator[FeatureDataType]:
...

@c3warn.deprecated_args(
"2024.9",
Expand All @@ -113,7 +118,8 @@ def get_feature_children(
start: OptionalInt = None,
stop: OptionalInt = None,
**kwargs,
) -> typing.List[FeatureDataType]: ...
) -> typing.List[FeatureDataType]:
...

@c3warn.deprecated_args(
"2024.9",
Expand All @@ -127,7 +133,8 @@ def get_feature_parent(
start: OptionalInt = None,
stop: OptionalInt = None,
**kwargs,
) -> typing.List[FeatureDataType]: ...
) -> typing.List[FeatureDataType]:
...

def num_matches(
self,
Expand All @@ -138,7 +145,8 @@ def num_matches(
strand: OptionalStr = None,
attributes: OptionalStr = None,
on_alignment: OptionalBool = None,
) -> int: ...
) -> int:
...

@c3warn.deprecated_args(
"2024.9",
Expand All @@ -155,7 +163,8 @@ def subset(
stop: OptionalInt = None,
strand: OptionalStr = None,
attributes: OptionalStr = None,
): ...
):
...


@typing.runtime_checkable
Expand All @@ -172,15 +181,17 @@ def add_feature(
attributes: OptionalStr = None,
strand: OptionalStr = None,
on_alignment: bool = False,
) -> None: ...
) -> None:
...

def add_records(
self,
*,
records: typing.Sequence[dict],
# seqid required for genbank
seqid: OptionalStr = None,
) -> None: ...
) -> None:
...

def update(self, annot_db, seqids: OptionalStrList = None) -> None:
# update records with those from an instance of the same type
Expand Down
9 changes: 5 additions & 4 deletions src/cogent3/core/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
performance reasons, but don't alter the MolType or the sequence data after
creation.
"""

from __future__ import annotations

import contextlib
Expand Down Expand Up @@ -920,7 +921,7 @@ def get_features(
name
name of the feature
start, stop
start, end positions to search between, relative to offset
start, stop positions to search between, relative to offset
of this sequence. If not provided, entire span of sequence is used.
Notes
Expand Down Expand Up @@ -955,11 +956,11 @@ def get_features(
query_start = self._seq.absolute_position(start, include_boundary=False)
# we set include_boundary=True because stop is exclusive indexing,
# i,e., the stop can be equal to the length of the view
query_end = self._seq.absolute_position(stop, include_boundary=True)
query_stop = self._seq.absolute_position(stop, include_boundary=True)

rev_strand = strand == -1
if rev_strand:
query_start, query_end = query_end, query_start
query_start, query_stop = query_stop, query_start

query_start = max(query_start, 0)
# in the underlying db, features are always plus strand oriented
Expand All @@ -983,7 +984,7 @@ def get_features(
name=name,
biotype=biotype,
start=query_start,
end=query_end, # todo gah end should be stop
stop=query_stop,
allow_partial=allow_partial,
):
# spans need to be converted from absolute to relative positions
Expand Down

0 comments on commit 8ded05f

Please sign in to comment.