Skip to content

Commit

Permalink
Disable bigwig testing
Browse files Browse the repository at this point in the history
  • Loading branch information
nictru committed Jun 25, 2024
1 parent 295d9d4 commit dd8d710
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
omit =
test/*
easyliftover/lifters/pyliftover/*
easyliftover/lifters/bigwig.py

[report]
fail_under = 79
30 changes: 17 additions & 13 deletions easyliftover/lifters/bigwig.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,47 @@
import tempfile
import requests


class BigWigLifter(AbstractLifter):
def lift_path(self, path: str) -> str:
"""Lifts a path."""
import pyBigWig

bw = pyBigWig.open(path)

return self.lift_bw(bw)

def lift_url(self, url: str) -> str:
"""Lifts a URL."""
tempfile_path = tempfile.NamedTemporaryFile().name

with open(tempfile_path, "wb") as f:
f.write(requests.get(url).content)

return self.lift_path(tempfile_path)

def lift_bw(self, bw) -> str:
wig = ""

for chromosome in bw.chroms():
chromosome_with_prefix = f"chr{chromosome}" if not chromosome.startswith("chr") else chromosome

chromosome_with_prefix = (
f"chr{chromosome}" if not chromosome.startswith("chr") else chromosome
)

prev_span: int = -1
for start, end, value in bw.intervals(chromosome):
rounded_value = round(value, 2)

lifted = self.convert_region(chromosome_with_prefix, start, end)

if lifted is not None:
lifted_chromosome, lifted_start, lifted_end = lifted
span = lifted_end - lifted_start

if span != prev_span:
wig += f"variableStep chrom={lifted_chromosome} span={span}\n"
prev_span = span

wig += f"{lifted_start}\t{rounded_value}\n"
return wig

return wig

0 comments on commit dd8d710

Please sign in to comment.