Skip to content

Commit 13c24f0

Browse files
Add missing -f option to convert
1 parent 42e2a5a commit 13c24f0

File tree

3 files changed

+52
-12
lines changed

3 files changed

+52
-12
lines changed

bio2zarr/cli.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,17 +423,25 @@ def dencode_finalise(zarr_path, verbose):
423423
@click.command(name="convert")
424424
@vcfs
425425
@new_zarr_path
426+
@force
426427
@variants_chunk_size
427428
@samples_chunk_size
428429
@verbose
429430
@worker_processes
430431
def convert_vcf(
431-
vcfs, zarr_path, variants_chunk_size, samples_chunk_size, verbose, worker_processes
432+
vcfs,
433+
zarr_path,
434+
force,
435+
variants_chunk_size,
436+
samples_chunk_size,
437+
verbose,
438+
worker_processes,
432439
):
433440
"""
434441
Convert input VCF(s) directly to vcfzarr (not recommended for large files).
435442
"""
436443
setup_logging(verbose)
444+
check_overwrite_dir(zarr_path, force)
437445
vcf.convert(
438446
vcfs,
439447
zarr_path,

bio2zarr/vcf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2273,7 +2273,7 @@ def convert(
22732273
# TODO add arguments to control location of tmpdir
22742274
):
22752275
with tempfile.TemporaryDirectory(prefix="vcf2zarr") as tmp:
2276-
if_dir = pathlib.Path(tmp) / "if"
2276+
if_dir = pathlib.Path(tmp) / "icf"
22772277
explode(
22782278
if_dir,
22792279
vcfs,

tests/test_cli.py

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@
4747

4848
DEFAULT_DENCODE_FINALISE_ARGS = dict(show_progress=True)
4949

50+
DEFAULT_CONVERT_ARGS = dict(
51+
variants_chunk_size=None,
52+
samples_chunk_size=None,
53+
show_progress=True,
54+
worker_processes=1,
55+
)
56+
5057

5158
@dataclasses.dataclass
5259
class FakeWorkSummary:
@@ -508,11 +515,24 @@ def test_convert_vcf(self, mocked):
508515
mocked.assert_called_once_with(
509516
(self.vcf_path,),
510517
"zarr_path",
511-
variants_chunk_size=None,
512-
samples_chunk_size=None,
513-
worker_processes=1,
514-
show_progress=True,
518+
**DEFAULT_CONVERT_ARGS,
519+
)
520+
521+
@pytest.mark.parametrize("response", ["n", "N", "No"])
522+
@mock.patch("bio2zarr.vcf.convert")
523+
def test_vcf_convert_overwrite_zarr_confirm_no(self, mocked, tmp_path, response):
524+
zarr_path = tmp_path / "zarr"
525+
zarr_path.mkdir()
526+
runner = ct.CliRunner(mix_stderr=False)
527+
result = runner.invoke(
528+
cli.vcf2zarr,
529+
f"convert {self.vcf_path} {zarr_path}",
530+
catch_exceptions=False,
531+
input=response,
515532
)
533+
assert result.exit_code == 1
534+
assert "Aborted" in result.stderr
535+
mocked.assert_not_called()
516536

517537
@mock.patch("bio2zarr.plink.convert")
518538
def test_convert_plink(self, mocked):
@@ -523,13 +543,25 @@ def test_convert_plink(self, mocked):
523543
assert result.exit_code == 0
524544
assert len(result.stdout) == 0
525545
assert len(result.stderr) == 0
546+
mocked.assert_called_once_with("in", "out", **DEFAULT_CONVERT_ARGS)
547+
548+
@pytest.mark.parametrize("response", ["y", "Y", "yes"])
549+
@mock.patch("bio2zarr.vcf.convert")
550+
def test_vcf_convert_overwrite_zarr_confirm_yes(self, mocked, tmp_path, response):
551+
zarr_path = tmp_path / "zarr"
552+
zarr_path.mkdir()
553+
runner = ct.CliRunner(mix_stderr=False)
554+
result = runner.invoke(
555+
cli.vcf2zarr,
556+
f"convert {self.vcf_path} {zarr_path}",
557+
catch_exceptions=False,
558+
input=response,
559+
)
560+
assert result.exit_code == 0
561+
assert f"Do you want to overwrite {zarr_path}" in result.stdout
562+
assert len(result.stderr) == 0
526563
mocked.assert_called_once_with(
527-
"in",
528-
"out",
529-
worker_processes=1,
530-
samples_chunk_size=None,
531-
variants_chunk_size=None,
532-
show_progress=True,
564+
(self.vcf_path,), str(zarr_path), **DEFAULT_CONVERT_ARGS
533565
)
534566

535567

0 commit comments

Comments
 (0)