|
8 | 8 | from pathlib import Path |
9 | 9 | from typing import TYPE_CHECKING |
10 | 10 |
|
11 | | -import matplotlib.pyplot as plt |
12 | 11 | import numpy as np |
13 | 12 | import pandas as pd |
14 | 13 |
|
@@ -58,13 +57,17 @@ def _require_pysam() -> "pysam_types": |
58 | 57 | return require("pysam", extra="pysam", purpose="FASTA indexing") |
59 | 58 |
|
60 | 59 |
|
61 | | -def _resolve_backend(backend: str | None, *, tool: str, python_available: bool, cli_name: str) -> str: |
| 60 | +def _resolve_backend( |
| 61 | + backend: str | None, *, tool: str, python_available: bool, cli_name: str |
| 62 | +) -> str: |
62 | 63 | choice = (backend or "auto").strip().lower() |
63 | 64 | if choice not in {"auto", "python", "cli"}: |
64 | 65 | raise ValueError(f"{tool}_backend must be one of: auto, python, cli") |
65 | 66 | if choice == "python": |
66 | 67 | if not python_available: |
67 | | - raise RuntimeError(f"{tool}_backend=python requires the Python package to be installed.") |
| 68 | + raise RuntimeError( |
| 69 | + f"{tool}_backend=python requires the Python package to be installed." |
| 70 | + ) |
68 | 71 | return "python" |
69 | 72 | if choice == "cli": |
70 | 73 | if not shutil.which(cli_name): |
@@ -143,7 +146,10 @@ def _bed_to_bigwig( |
143 | 146 |
|
144 | 147 | # 1) Compute coverage → bedGraph |
145 | 148 | bedtools_choice = _resolve_backend( |
146 | | - bedtools_backend, tool="bedtools", python_available=pybedtools is not None, cli_name="bedtools" |
| 149 | + bedtools_backend, |
| 150 | + tool="bedtools", |
| 151 | + python_available=pybedtools is not None, |
| 152 | + cli_name="bedtools", |
147 | 153 | ) |
148 | 154 | if bedtools_choice == "python": |
149 | 155 | logger.debug(f"[pybedtools] generating coverage bedgraph from {bed}") |
@@ -172,7 +178,10 @@ def _bed_to_bigwig( |
172 | 178 |
|
173 | 179 | # 2) Convert bedGraph → BigWig via pyBigWig |
174 | 180 | bigwig_choice = _resolve_backend( |
175 | | - bigwig_backend, tool="bigwig", python_available=pyBigWig is not None, cli_name="bedGraphToBigWig" |
| 181 | + bigwig_backend, |
| 182 | + tool="bigwig", |
| 183 | + python_available=pyBigWig is not None, |
| 184 | + cli_name="bedGraphToBigWig", |
176 | 185 | ) |
177 | 186 | if bigwig_choice == "python": |
178 | 187 | logger.debug(f"[pyBigWig] converting bedgraph → bigwig: {bigwig}") |
@@ -245,6 +254,8 @@ def _plot_bed_histograms( |
245 | 254 | coordinate_mode : {"one_based","zero_based"} |
246 | 255 | One-based, inclusive (your file) vs BED-standard zero-based, half-open. |
247 | 256 | """ |
| 257 | + plt = require("matplotlib.pyplot", extra="plotting", purpose="plotting BED histograms") |
| 258 | + |
248 | 259 | os.makedirs(plotting_directory, exist_ok=True) |
249 | 260 |
|
250 | 261 | bed_basename = os.path.basename(bed_file).rsplit(".bed", 1)[0] |
|
0 commit comments