Skip to content

Commit 7dcfa52

Browse files
committed
formatting
1 parent f82799f commit 7dcfa52

File tree

13 files changed

+48
-25
lines changed

13 files changed

+48
-25
lines changed

src/smftools/cli/hmm_adata.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import copy
44
from dataclasses import dataclass
55
from pathlib import Path
6-
from typing import Any, List, Optional, Sequence, Tuple, Union, TYPE_CHECKING
6+
from typing import TYPE_CHECKING, Any, List, Optional, Sequence, Tuple, Union
77

88
import numpy as np
9+
910
from smftools.logging_utils import get_logger
1011
from smftools.optional_imports import require
1112

src/smftools/hmm/HMM.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import ast
44
import json
55
from pathlib import Path
6-
from typing import Any, Dict, List, Optional, Sequence, Tuple, Union, TYPE_CHECKING
6+
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence, Tuple, Union
77

88
import numpy as np
99
from scipy.sparse import issparse

src/smftools/informatics/bam_functions.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010
from concurrent.futures import ThreadPoolExecutor, as_completed
1111
from itertools import zip_longest
1212
from pathlib import Path
13-
import shutil
14-
from typing import Any, Dict, Iterable, List, Optional, Tuple, Union, TYPE_CHECKING
13+
from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Tuple, Union
1514

1615
import numpy as np
1716
from tqdm import tqdm
@@ -76,9 +75,10 @@ def _resolve_samtools_backend(backend: str | None) -> str:
7675

7776
def _has_bam_index(bam_path: Path) -> bool:
7877
"""Return True if the BAM index exists alongside the BAM."""
79-
return bam_path.with_suffix(bam_path.suffix + ".bai").exists() or Path(
80-
str(bam_path) + ".bai"
81-
).exists()
78+
return (
79+
bam_path.with_suffix(bam_path.suffix + ".bai").exists()
80+
or Path(str(bam_path) + ".bai").exists()
81+
)
8282

8383

8484
def _ensure_bam_index(bam_path: Path, backend: str) -> None:
@@ -215,9 +215,7 @@ def _index_bam_with_pysam(bam_path: Union[str, Path], threads: Optional[int] = N
215215
pysam_mod.index(bam_path)
216216

217217

218-
def _bam_to_fastq_with_samtools(
219-
bam_path: Union[str, Path], fastq_path: Union[str, Path]
220-
) -> None:
218+
def _bam_to_fastq_with_samtools(bam_path: Union[str, Path], fastq_path: Union[str, Path]) -> None:
221219
"""Convert BAM to FASTQ using samtools."""
222220
if not shutil.which("samtools"):
223221
raise RuntimeError("samtools is required but not available in PATH.")
@@ -881,7 +879,8 @@ def _to_path_pair(x) -> Tuple[Path, Path]:
881879
rg_fields = [f"ID:{bc}"]
882880
if rg_sample_field:
883881
rg_fields.append(f"SM:{rg_sample_field}")
884-
header_lines.append(f"@RG\t{'\t'.join(rg_fields)}")
882+
rg_body = "\t".join(rg_fields)
883+
header_lines.append(f"@RG\t{rg_body}")
885884
header_lines.append("@PG\tID:concat-fastq\tPN:concatenate_fastqs_to_bam\tVN:1")
886885
bam_out_ctx.stdin.write("\n".join(header_lines) + "\n")
887886

@@ -917,7 +916,9 @@ def _clean(n: Optional[str]) -> Optional[str]:
917916
)
918917
if name is None:
919918
name = (
920-
_clean(getattr(rec2, "name", None) if backend_choice == "python" else rec2[0])
919+
_clean(
920+
getattr(rec2, "name", None) if backend_choice == "python" else rec2[0]
921+
)
921922
if rec2 is not None
922923
else None
923924
)
@@ -1354,9 +1355,10 @@ def extract_readnames_from_bam(aligned_BAM, samtools_backend: str | None = "auto
13541355

13551356
if backend_choice == "python":
13561357
pysam_mod = _require_pysam()
1357-
with pysam_mod.AlignmentFile(aligned_BAM, "rb") as bam, open(
1358-
txt_output, "w", encoding="utf-8"
1359-
) as output_file:
1358+
with (
1359+
pysam_mod.AlignmentFile(aligned_BAM, "rb") as bam,
1360+
open(txt_output, "w", encoding="utf-8") as output_file,
1361+
):
13601362
for read in bam:
13611363
output_file.write(f"{read.query_name}\n")
13621364
return
@@ -1370,7 +1372,7 @@ def extract_readnames_from_bam(aligned_BAM, samtools_backend: str | None = "auto
13701372
if not line.strip():
13711373
continue
13721374
qname = line.split("\t", 1)[0]
1373-
output_file.write(f"{qname}\n")
1375+
output_file.write(f"{qname}\n")
13741376
rc = samtools_view.wait()
13751377
if rc != 0:
13761378
stderr = samtools_view.stderr.read() if samtools_view.stderr else ""

src/smftools/informatics/bed_functions.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,17 @@ def _require_pysam() -> "pysam_types":
5757
return require("pysam", extra="pysam", purpose="FASTA indexing")
5858

5959

60-
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:
6163
choice = (backend or "auto").strip().lower()
6264
if choice not in {"auto", "python", "cli"}:
6365
raise ValueError(f"{tool}_backend must be one of: auto, python, cli")
6466
if choice == "python":
6567
if not python_available:
66-
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+
)
6771
return "python"
6872
if choice == "cli":
6973
if not shutil.which(cli_name):
@@ -142,7 +146,10 @@ def _bed_to_bigwig(
142146

143147
# 1) Compute coverage → bedGraph
144148
bedtools_choice = _resolve_backend(
145-
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",
146153
)
147154
if bedtools_choice == "python":
148155
logger.debug(f"[pybedtools] generating coverage bedgraph from {bed}")
@@ -171,7 +178,10 @@ def _bed_to_bigwig(
171178

172179
# 2) Convert bedGraph → BigWig via pyBigWig
173180
bigwig_choice = _resolve_backend(
174-
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",
175185
)
176186
if bigwig_choice == "python":
177187
logger.debug(f"[pyBigWig] converting bedgraph → bigwig: {bigwig}")

src/smftools/informatics/converted_BAM_to_adata.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
import traceback
88
from multiprocessing import Manager, Pool, current_process
99
from pathlib import Path
10-
from typing import Iterable, Optional, Union, TYPE_CHECKING
10+
from typing import TYPE_CHECKING, Iterable, Optional, Union
1111

1212
import anndata as ad
1313
import numpy as np
1414
import pandas as pd
15+
1516
from smftools.logging_utils import get_logger
1617
from smftools.optional_imports import require
1718

src/smftools/informatics/fasta_functions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from concurrent.futures import ProcessPoolExecutor
77
from importlib.util import find_spec
88
from pathlib import Path
9-
from typing import Dict, Iterable, Tuple, TYPE_CHECKING
9+
from typing import TYPE_CHECKING, Dict, Iterable, Tuple
1010

1111
import numpy as np
1212
from Bio import SeqIO
@@ -29,6 +29,7 @@ def _require_pysam() -> "pysam_module":
2929
return pysam_types
3030
return require("pysam", extra="pysam", purpose="FASTA access")
3131

32+
3233
pysam_types = None
3334
if find_spec("pysam") is not None:
3435
pysam_types = require("pysam", extra="pysam", purpose="FASTA access")

src/smftools/machine_learning/training/train_lightning_model.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
torch = require("torch", extra="ml-base", purpose="Lightning training")
66
pytorch_lightning = require("pytorch_lightning", extra="ml-extended", purpose="Lightning training")
7-
pl_callbacks = require("pytorch_lightning.callbacks", extra="ml-extended", purpose="Lightning training")
7+
pl_callbacks = require(
8+
"pytorch_lightning.callbacks", extra="ml-extended", purpose="Lightning training"
9+
)
810

911
Trainer = pytorch_lightning.Trainer
1012
EarlyStopping = pl_callbacks.EarlyStopping

src/smftools/plotting/classifiers.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
plt = require("matplotlib.pyplot", extra="plotting", purpose="model plots")
1010
torch = require("torch", extra="ml-base", purpose="model saliency plots")
1111

12+
1213
def plot_model_performance(metrics, save_path=None):
1314
"""Plot ROC and precision-recall curves for model metrics.
1415
@@ -356,6 +357,7 @@ def plot_model_curves_from_adata_with_frequency_grid(
356357
import os
357358

358359
import numpy as np
360+
359361
sklearn_metrics = require("sklearn.metrics", extra="ml-base", purpose="model curves")
360362
auc = sklearn_metrics.auc
361363
precision_recall_curve = sklearn_metrics.precision_recall_curve

src/smftools/plotting/position_stats.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ def plot_positionwise_matrix(
236236

237237
import numpy as np
238238
import pandas as pd
239+
239240
plt = require("matplotlib.pyplot", extra="plotting", purpose="position stats plots")
240241
sns = require("seaborn", extra="plotting", purpose="position stats plots")
241242

src/smftools/plotting/qc_plotting.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
plt = require("matplotlib.pyplot", extra="plotting", purpose="QC plots")
1111

12+
1213
def plot_read_qc_histograms(
1314
adata,
1415
outdir,

0 commit comments

Comments
 (0)