Skip to content

Commit

Permalink
From Black to Ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
bede committed May 16, 2024
1 parent cb98c9d commit d571108
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 22 deletions.
16 changes: 6 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.3.0
hooks:
- id: black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.4.4
hooks:
- id: ruff
args: [ --fix ]
- id: ruff-format
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,5 +264,6 @@ cd hostile
conda env create -y -f environment.yml
conda activate hostile
pip install --editable '.[dev]'
pre-commit install
pytest
```
1 change: 1 addition & 0 deletions src/hostile/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
"""Accurate host read removal"""

__version__ = "1.1.0"
4 changes: 2 additions & 2 deletions src/hostile/aligner.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def gen_clean_cmd(
count_after_path = out_dir / f"{fastq_stem}.reads_out.txt"
if not force and fastq_out_path.exists():
raise FileExistsError(
f"Output file already exists. Use --force to overwrite"
"Output file already exists. Use --force to overwrite"
)
filter_cmd = " | samtools view -hF 4 -" if invert else " | samtools view -f 4 -"
reorder_cmd = " | samtools sort -n -O sam -@ 6 -m 1G" if reorder else ""
Expand Down Expand Up @@ -175,7 +175,7 @@ def gen_paired_clean_cmd(
count_after_path = out_dir / f"{fastq1_stem}.reads_out.txt"
if not force and (fastq1_out_path.exists() or fastq2_out_path.exists()):
raise FileExistsError(
f"Output files already exist. Use --force to overwrite"
"Output files already exist. Use --force to overwrite"
)
filter_cmd = (
" | samtools view -hF 12 -" if invert else " | samtools view -f 12 -"
Expand Down
2 changes: 1 addition & 1 deletion src/hostile/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def choose_default_thread_count(cpu_count: int) -> int:

CWD = Path.cwd()
CACHE_DIR = (
Path(os.environ.get("HOSTILE_CACHE_DIR"))
Path(os.environ.get("HOSTILE_CACHE_DIR", ""))
if os.environ.get("HOSTILE_CACHE_DIR")
else Path(user_data_dir("hostile", "Bede Constantinides"))
)
Expand Down
19 changes: 10 additions & 9 deletions tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ def test_paired_rename():

def test_with_and_without_force():
shutil.rmtree(out_dir, ignore_errors=True)
stats = lib.clean_paired_fastqs(
lib.clean_paired_fastqs(
fastqs=[
(
data_dir / "tuberculosis_1_2.fastq.gz",
Expand All @@ -297,7 +297,7 @@ def test_with_and_without_force():
out_dir=out_dir,
)
with pytest.raises(FileExistsError):
stats = lib.clean_paired_fastqs(
lib.clean_paired_fastqs(
fastqs=[
(
data_dir / "tuberculosis_1_2.fastq.gz",
Expand All @@ -313,7 +313,7 @@ def test_with_and_without_force():


def test_no_rename():
stats = lib.clean_paired_fastqs(
lib.clean_paired_fastqs(
fastqs=[
(
data_dir / "tuberculosis_1_2.fastq.gz",
Expand All @@ -334,7 +334,7 @@ def test_no_rename():

def test_broken_fastq_path():
with pytest.raises(FileNotFoundError):
stats = lib.clean_fastqs(
lib.clean_fastqs(
fastqs=[Path("invalid_path.fastq.gz")],
aligner=lib.ALIGNER.bowtie2,
index=data_dir / "sars-cov-2/sars-cov-2",
Expand Down Expand Up @@ -603,7 +603,7 @@ def test_invert_paired_2():


def test_minimap2_reordering_linux():
stats = lib.clean_paired_fastqs(
lib.clean_paired_fastqs(
fastqs=[
(
data_dir / "sars-cov-2_1_1.fastq",
Expand Down Expand Up @@ -676,6 +676,7 @@ def test_fixing_empty_fastqs_single():
force=True,
)
run(f"gzip -dc {stats[0]['fastq1_out_path']}")
shutil.rmtree(out_dir, ignore_errors=True)


def test_fixing_empty_fastqs_paired():
Expand All @@ -699,7 +700,7 @@ def test_fixing_empty_fastqs_paired():
def test_mismatched_number_of_reads_bowtie2():
"""This has caused sinister errors in the wild, yet is handled gracefully here"""
with pytest.raises(subprocess.CalledProcessError):
stats = lib.clean_paired_fastqs(
lib.clean_paired_fastqs(
fastqs=[
(
data_dir / "sars-cov-2_100_1.fastq.gz",
Expand All @@ -711,15 +712,15 @@ def test_mismatched_number_of_reads_bowtie2():
out_dir=out_dir,
force=True,
)
shutil.rmtree(out_dir, ignore_errors=True)
shutil.rmtree(out_dir, ignore_errors=True)


def test_offline_invalid_standard_index_name():
with pytest.raises(FileNotFoundError):
stats = lib.clean_fastqs(
lib.clean_fastqs(
fastqs=[data_dir / "sars-cov-2_1_1.fastq"],
index="invalid_index_name",
out_dir=out_dir,
offline=True,
)
shutil.rmtree(out_dir, ignore_errors=True)
shutil.rmtree(out_dir, ignore_errors=True)

0 comments on commit d571108

Please sign in to comment.