Skip to content

Commit

Permalink
fixups
Browse files Browse the repository at this point in the history
  • Loading branch information
nh13 committed Jul 31, 2024
1 parent 49ff82c commit 8283030
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pybedlite/bed_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def refname(self) -> str:
return self.chrom

@property
def is_negative(self) -> bool:
def negative(self) -> bool:
"""True if the interval is on the negative strand, False otherwise"""
return self.strand is not None and self.strand == BedStrand.Positive

Expand Down
15 changes: 5 additions & 10 deletions pybedlite/overlap_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
for sorting them in :func:`~pybedlite.overlap_detector.OverlapDetector.get_overlaps` using
the following property if it is present, otherwise assumed to be positive stranded:
* `is_negative (bool)`: Whether the feature is negative stranded or not
* `negative (bool)`: Whether the feature is negative stranded or not
This is encapsulated in the :class:`~pybedlite.overlap_detector.StrandedGenomicSpan` protocol.
Expand Down Expand Up @@ -101,7 +101,7 @@ def end(self) -> int:

class StrandedGenomicSpan(GenomicSpan, Protocol):
@property
def is_negative(self) -> bool:
def negative(self) -> bool:
"""True if the interval is on the negative strand, False otherwise"""


Expand Down Expand Up @@ -135,11 +135,6 @@ def __attrs_post_init__(self) -> None:
if self.end <= self.start:
raise ValueError(f"end <= start: {self.end} <= {self.start}")

@property
def is_negative(self) -> bool:
"""True if the interval is on the negative strand, False otherwise"""
return self.negative

def overlap(self, other: "Interval") -> int:
"""Returns the overlap between this interval and the other, or zero if there is none.
Expand Down Expand Up @@ -297,14 +292,14 @@ def get_overlaps(self, interval: GenomicSpan) -> List[GenericGenomicsSpan]:
key=lambda intv: (
intv.start,
intv.end,
self._is_negative(intv),
self._negative(intv),
intv.refname,
),
)

@staticmethod
def _is_negative(interval: GenomicSpan) -> bool:
return getattr(interval, "is_negative", False)
def _negative(interval: GenomicSpan) -> bool:
return getattr(interval, "negative", False)

def get_enclosing_intervals(self, interval: GenomicSpan) -> List[GenericGenomicsSpan]:
"""Returns the set of intervals in this detector that wholly enclose the query interval.
Expand Down
18 changes: 9 additions & 9 deletions pybedlite/tests/test_overlap_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class ZeroBasedOpenEndedProtocol:
end: int

@property
def is_negative(self) -> bool:
def negative(self) -> bool:
return False

@dataclass(eq=True, frozen=True)
Expand All @@ -226,7 +226,7 @@ def start(self) -> int:
return self.one_based_start - 1

@property
def is_negative(self) -> bool:
def negative(self) -> bool:
"""True if the interval is on the negative strand, False otherwise"""
return False

Expand All @@ -246,7 +246,7 @@ class ZeroBasedStranded:
refname: str
zero_based_start: int
end: int
is_negative: bool
negative: bool

@property
def start(self) -> int:
Expand All @@ -258,7 +258,7 @@ def start(self) -> int:
one_based_protocol = OneBasedProtocol(contig="chr1", one_based_start=10, end=60)
zero_based_unstranded = ZeroBasedUnstranded(refname="chr1", zero_based_start=20, end=70)
zero_based_stranded = ZeroBasedStranded(
refname="chr1", zero_based_start=30, end=80, is_negative=True
refname="chr1", zero_based_start=30, end=80, negative=True
)
# Set up an overlap detector to hold all the features we care about
AllKinds: TypeAlias = Union[
Expand All @@ -272,10 +272,10 @@ def start(self) -> int:
]
detector: OverlapDetector[AllKinds] = OverlapDetector(features)

assert OverlapDetector._is_negative(zero_based_protocol) is False
assert OverlapDetector._is_negative(one_based_protocol) is False
assert OverlapDetector._is_negative(zero_based_unstranded) is False
assert OverlapDetector._is_negative(zero_based_stranded) is True
assert OverlapDetector._negative(zero_based_protocol) is False
assert OverlapDetector._negative(one_based_protocol) is False
assert OverlapDetector._negative(zero_based_unstranded) is False
assert OverlapDetector._negative(zero_based_stranded) is True

# Query the overlap detector with yet another type
assert detector.get_overlaps(Interval("chr1", 0, 1)) == []
Expand Down Expand Up @@ -325,7 +325,7 @@ def start(self) -> int:
return self.zero_based_start

@property
def is_negative(self) -> bool:
def negative(self) -> bool:
"""True if the interval is on the negative strand, False otherwise"""
return False

Expand Down

0 comments on commit 8283030

Please sign in to comment.