Skip to content

Commit

Permalink
Merge pull request cogent3#1849 from GavinHuttley/develop
Browse files Browse the repository at this point in the history
DEP: deleted code marked for deprecation in upcoming release, fixes cogent3#1840
  • Loading branch information
GavinHuttley committed May 2, 2024
2 parents 8f97f07 + 43910d7 commit 692a872
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 244 deletions.
230 changes: 0 additions & 230 deletions src/cogent3/core/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,236 +860,6 @@ def relative_position(self, abs_pos: T) -> T:
return abs_pos - self.start


@c3warn.deprecated_callable(
version="2024.3", reason="No being used.", is_discontinued=True
)
class SpansOnly(ConstrainedList): # pragma: no cover
"""List that converts elements to Spans on addition."""

mask = FunctionWrapper(Span)
_constraint = ClassChecker(Span)


@c3warn.deprecated_callable(
version="2024.3", reason="No being used.", is_discontinued=True
)
@total_ordering
class Range(SpanI): # pragma: no cover
"""Complex object consisting of many spans."""

def __init__(self, spans=None):
"""Returns a new Range object with data in spans."""
spans = [] if spans is None else spans
result = SpansOnly()
# need to check if we got a single Span, since they define __iter__.
if isinstance(spans, Span):
result.append(spans)
elif hasattr(spans, "spans"): # probably a single range object?
result.extend(spans.spans)
else:
for s in iterable(spans):
if hasattr(s, "spans"):
result.extend(s.spans)
else:
result.append(s)
self.spans = result

def __str__(self):
"""Returns string representation of self."""
return f"({','.join(map(str, self.spans))})"

def __len__(self):
"""Returns sum of span lengths.
NOTE: if spans overlap, will count multiple times. Use reduce() to
get rid of overlaps.
"""
return sum(map(len, self.spans))

def __lt__(self, other):
"""Compares spans of self with indices of other."""
if hasattr(other, "spans"):
return self.spans < other.spans
elif len(self.spans) == 1 and hasattr(other, "start") and hasattr(other, "end"):
return self.spans[0].start < other.start or self.spans[0].end < other.end
else:
return object < other

def __eq__(self, other):
"""Compares spans of self with indices of other."""
if hasattr(other, "spans"):
return self.spans == other.spans
elif len(self.spans) == 1 and hasattr(other, "start") and hasattr(other, "end"):
return self.spans[0].start == other.start and self.spans[0].end == other.end
else:
return object == other

def _get_start(self):
"""Finds earliest start of items in self.spans."""
return min([i.start for i in self.spans])

start = property(_get_start)

def _get_end(self):
"""Finds latest end of items in self.spans."""
return max([i.end for i in self.spans])

end = property(_get_end)

def _get_reverse(self):
"""reverse is True if any piece is reversed."""
for i in self.spans:
if i.reverse:
return True
return False

reverse = property(_get_reverse)

def reverses(self):
"""Reverses all spans in self."""
for i in self.spans:
i.reverses()

def __contains__(self, other):
"""Returns True if other completely contained in self.
other must either be a number or have start and end properties.
"""
if hasattr(other, "spans"):
for curr in other.spans:
found = False
for i in self.spans:
if curr in i:
found = True
break
if not found:
return False
return True
else:
for i in self.spans:
if other in i:
return True
return False

def overlaps(self, other):
"""Returns True if any positions in self are also in other."""
if hasattr(other, "spans"):
for i in self.spans:
for j in other.spans:
if i.overlaps(j):
return True
else:
for i in self.spans:
if i.overlaps(other):
return True
return False

def overlaps_extent(self, other):
"""Returns True if any positions in self's extent also in other's."""
if hasattr(other, "extent"):
return self.extent.overlaps(other.extent)
else:
return self.extent.overlaps(other)

def sort(self):
"""Sorts the spans in self."""
self.spans.sort()

def __iter__(self):
"""Iterates over indices contained in self."""
return chain(*[iter(i) for i in self.spans])

def _get_extent(self):
"""Returns Span object representing the extent of self."""
return Span(self.start, self.end)

extent = property(_get_extent)

def simplify(self):
"""Reduces the spans in self in-place to get fewest spans.
Will not condense spans with opposite directions.
Will condense adjacent but nonoverlapping spans (e.g. (1,3) and (4,5)).
"""
forward = []
reverse = []
spans = self.spans[:]
spans.sort()
for span in spans:
if span.reverse:
direction = reverse
else:
direction = forward

found_overlap = False
for other in direction:
if (
span.overlaps(other)
or (span.start == other.end)
or (other.start == span.end)
): # handle adjacent spans also
other.start = min(span.start, other.start)
other.end = max(span.end, other.end)
found_overlap = True
break
if not found_overlap:
direction.append(span)
self.spans[:] = forward + reverse


@c3warn.deprecated_callable(
version="2024.3", reason="No being used.", is_discontinued=True
)
class Point(Span): # pragma: no cover
"""Point is a special case of Span, where start always equals end.
Note that, as per Python standard, a point is _between_ two elements
in a sequence. In other words, a point does not contain any elements.
If you want a single element, use a Span where end = start + 1.
A Point does have a direction (i.e. a reverse property) to indicate
where successive items would go if it were expanded.
"""

def __init__(self, start, reverse=False):
"""Returns new Point object."""
self.reverse = reverse
self._start = start

def _get_start(self):
"""Returns self.start."""
return self._start

def _set_start(self, start):
"""Sets self.start and self.end."""
self._start = start

start = property(_get_start, _set_start)
end = start # start and end are synonyms for the same property


@c3warn.deprecated_callable(
version="2024.3", reason="No being used.", is_discontinued=True
)
def RangeFromString(string, delimiter=","): # pragma: no cover
"""Returns Range object from string of the form 1-5,11,20,30-50.
Ignores whitespace; expects values to be comma-delimited and positive.
"""
result = Range()
pairs = list(map(strip, string.split(delimiter)))
for p in pairs:
if not p: # adjacent delimiters?
continue
if "-" in p: # treat as pair
first, second = p.split("-")
result.spans.append(Span(int(first), int(second)))
else:
result.spans.append(Span(int(p)))
return result


class MapABC(ABC):
"""base class for genomic map objects"""

Expand Down
14 changes: 0 additions & 14 deletions src/cogent3/util/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1941,12 +1941,6 @@ def to_list(self, columns=None):

return result

@c3warn.deprecated_callable(version="2024.1", reason="PEP8", new="to_list")
def tolist(self, **kwargs): # pragma: no cover
"""deprecated, use to_list"""

return self.to_list(**kwargs)

@extend_docstring_from(DictArray.to_dict)
def to_dict(self, flatten=False):
index = self.columns[self.index_name] if self.index_name else self.shape[0]
Expand Down Expand Up @@ -1987,14 +1981,6 @@ def to_pandas(self, categories=None):

return df

@c3warn.deprecated_callable(
version="2024.3", reason="to enable usage by plotly", new="to_pandas()"
)
def to_dataframe(self, **kwargs): # pragma: no cover
"""deprecated, use to_pandas()"""

return self.to_pandas(**kwargs)

def to_plotly(self, width=500, font_size=12, layout=None, **kwargs):
"""returns a Plotly Table"""
from cogent3.draw.drawable import Drawable
Expand Down

0 comments on commit 692a872

Please sign in to comment.