From 8283030e7fc4f954508eb8545bd13aca0b3cfae0 Mon Sep 17 00:00:00 2001 From: Nils Homer Date: Wed, 31 Jul 2024 14:04:46 -0700 Subject: [PATCH] fixups --- pybedlite/bed_record.py | 2 +- pybedlite/overlap_detector.py | 15 +++++---------- pybedlite/tests/test_overlap_detector.py | 18 +++++++++--------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/pybedlite/bed_record.py b/pybedlite/bed_record.py index 1f685a1..37d90c3 100644 --- a/pybedlite/bed_record.py +++ b/pybedlite/bed_record.py @@ -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 diff --git a/pybedlite/overlap_detector.py b/pybedlite/overlap_detector.py index f19acb0..c79ead1 100644 --- a/pybedlite/overlap_detector.py +++ b/pybedlite/overlap_detector.py @@ -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. @@ -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""" @@ -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. @@ -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. diff --git a/pybedlite/tests/test_overlap_detector.py b/pybedlite/tests/test_overlap_detector.py index c458ddc..38e3bd5 100644 --- a/pybedlite/tests/test_overlap_detector.py +++ b/pybedlite/tests/test_overlap_detector.py @@ -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) @@ -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 @@ -246,7 +246,7 @@ class ZeroBasedStranded: refname: str zero_based_start: int end: int - is_negative: bool + negative: bool @property def start(self) -> int: @@ -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[ @@ -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)) == [] @@ -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