Skip to content

Commit

Permalink
refactor: rename value and update strand extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
msto committed Apr 4, 2024
1 parent 7bb0999 commit 9e9eb97
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions pybedlite/overlap_detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def from_bedrecord(cls: Type["Interval"], record: BedRecord) -> "Interval":
@classmethod
def from_ucsc(
cls: Type["Interval"],
ucsc: str,
value: str,
name: Optional[str] = None,
) -> "Interval":
"""
Expand All @@ -170,7 +170,7 @@ def from_ucsc(
reading a record that does not have a specified strand.
Args:
position: The UCSC "position"-formatted string.
value: The UCSC "position"-formatted string.
name: An optional name for the interval.
Returns:
Expand All @@ -181,18 +181,17 @@ def from_ucsc(
ValueError: If the string is not a valid UCSC position-formatted string.
"""

# First, check to see if the strand is specified, and remove it from the string.
strand_match = UCSC_STRAND_REGEX.match(ucsc)
if strand_match is not None:
negative = strand_match.group(1) == "-"
ucsc = ucsc[:-3]
else:
negative = False
# First, check to see if the strand is specified, and remove it from the string if so.
strand_match = UCSC_STRAND_REGEX.match(value)
value = value if strand_match is None else value[:-3]

# Intervals are positive by default if no strand is specified
negative = strand_match is not None and strand_match.group(1) == "-"

# Then parse the location
interval_match = UCSC_INTERVAL_REGEX.match(ucsc)
interval_match = UCSC_INTERVAL_REGEX.match(value)
if interval_match is None:
raise ValueError(f"Not a valid UCSC position-formatted string: {ucsc}")
raise ValueError(f"Not a valid UCSC position-formatted string: {value}")

Check warning on line 194 in pybedlite/overlap_detector.py

View check run for this annotation

Codecov / codecov/patch

pybedlite/overlap_detector.py#L194

Added line #L194 was not covered by tests

refname = interval_match.group(1)
start = int(interval_match.group(2)) - 1
Expand Down

0 comments on commit 9e9eb97

Please sign in to comment.