Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the OverlapDetector to be generic over input feature types #34

Merged
merged 18 commits into from
Aug 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: fixup stale docs
  • Loading branch information
clintval committed Aug 1, 2024
commit 04382f213519405cbe665fd6a0b12d759cfc212a
2 changes: 1 addition & 1 deletion pybedlite/bed_record.py
Original file line number Diff line number Diff line change
@@ -184,13 +184,13 @@

@property
def refname(self) -> str:
"""A reference sequence name."""
"""The reference name of the interval described by the record."""
return self.chrom

Check warning on line 188 in pybedlite/bed_record.py

Codecov / codecov/patch

pybedlite/bed_record.py#L188

Added line #L188 was not covered by tests

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

Check warning on line 193 in pybedlite/bed_record.py

Codecov / codecov/patch

pybedlite/bed_record.py#L193

Added line #L193 was not covered by tests

def as_bed_line(self, number_of_output_fields: Optional[int] = None) -> str:
"""
22 changes: 13 additions & 9 deletions pybedlite/overlap_detector.py
Original file line number Diff line number Diff line change
@@ -80,10 +80,9 @@
from pybedlite.bed_source import BedSource


class GenomicSpan(Protocol):
class GenomicSpan(Hashable, Protocol):
clintval marked this conversation as resolved.
Show resolved Hide resolved
"""
A genomic span which has protected methods that must be implemented by all subclasses to give
a zero-based open-ended genomic span.
A structural type for a span on a reference sequence with zero-based open-ended coordinates.
"""

@property
@@ -100,6 +99,11 @@


class StrandedGenomicSpan(GenomicSpan, Protocol):
"""
A structural type for a stranded span on a reference sequence with zero-based open-ended
coordinates.
"""

@property
def negative(self) -> bool:
"""True if the interval is on the negative strand, False otherwise"""
@@ -177,8 +181,8 @@

GenericGenomicSpan = TypeVar("GenericGenomicSpan", bound=Union[GenomicSpan, StrandedGenomicSpan])
clintval marked this conversation as resolved.
Show resolved Hide resolved
"""
A generic genomic feature. This type variable is used for describing the
generic type contained within the :class:`~pybedlite.overlap_detector.OverlapDetector`.
A generic genomic span. This type variable is used for describing the generic type contained within
the :class:`~pybedlite.overlap_detector.OverlapDetector`.
"""


@@ -187,16 +191,16 @@

The overlap detector may contain any interval-like Python objects that have the following
properties:
* `chrom` or `contig` or `refname`: The reference sequence name

* `refname`: The reference sequence name
* `start`: A 0-based start position
* `end`: A 0-based exclusive end position

Interval-like Python objects may also contain strandedness information which will be used
for sorting them in :func:`~pybedlite.overlap_detector.OverlapDetector.get_overlaps` using
either of the following properties if they are present:
the following property if it is present:

* `negative (bool)`: Whether or not the feature is negative stranded or not
* `strand (BedStrand)`: The BED strand of the feature
* `strand (str)`: The strand of the feature (`"-"` for negative)

The same interval may be added multiple times, but only a single instance will be returned
when querying for overlaps.
@@ -349,9 +353,9 @@
Returns:
An overlap detector for the regions in the BED file.
"""
detector: OverlapDetector[BedRecord] = OverlapDetector()

Check warning on line 356 in pybedlite/overlap_detector.py

Codecov / codecov/patch

pybedlite/overlap_detector.py#L356

Added line #L356 was not covered by tests

for region in BedSource(path):
detector.add(region)

Check warning on line 359 in pybedlite/overlap_detector.py

Codecov / codecov/patch

pybedlite/overlap_detector.py#L359

Added line #L359 was not covered by tests

return detector
Loading