Skip to content

Commit bd2ec9d

Browse files
Add --force to plink CLI
1 parent 9a4efad commit bd2ec9d

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

bio2zarr/cli.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ def vcf2zarr_main():
531531
Convert VCF file(s) to VCF Zarr format.
532532
533533
See the online documentation at https://sgkit-dev.github.io/bio2zarr/
534+
534535
for more information.
535536
"""
536537

@@ -551,6 +552,7 @@ def vcf2zarr_main():
551552
@click.command(name="convert")
552553
@click.argument("in_path", type=click.Path())
553554
@click.argument("zarr_path", type=click.Path())
555+
@force
554556
@worker_processes
555557
@progress
556558
@verbose
@@ -559,6 +561,7 @@ def vcf2zarr_main():
559561
def convert_plink(
560562
in_path,
561563
zarr_path,
564+
force,
562565
verbose,
563566
worker_processes,
564567
progress,
@@ -571,6 +574,7 @@ def convert_plink(
571574
then running `vcf2zarr convert tmp.vcf zarr_path`
572575
"""
573576
setup_logging(verbose)
577+
check_overwrite_dir(zarr_path, force)
574578
plink.convert(
575579
in_path,
576580
zarr_path,

tests/test_cli.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,66 @@ def test_tskit_convert_with_options(self, mocked, tmp_path):
754754
**expected_args,
755755
)
756756

757+
@pytest.mark.parametrize("response", ["y", "Y", "yes"])
758+
@mock.patch("bio2zarr.plink.convert")
759+
def test_plink_convert_overwrite_zarr_confirm_yes(self, mocked, tmp_path, response):
760+
prefix = "tests/data/plink/example"
761+
zarr_path = tmp_path / "zarr"
762+
zarr_path.mkdir()
763+
runner = ct.CliRunner()
764+
result = runner.invoke(
765+
cli.plink2zarr_main,
766+
f"convert {prefix} {zarr_path}",
767+
catch_exceptions=False,
768+
input=response,
769+
)
770+
assert result.exit_code == 0
771+
assert f"Do you want to overwrite {zarr_path}" in result.stdout
772+
assert len(result.stderr) == 0
773+
mocked.assert_called_once_with(
774+
prefix,
775+
str(zarr_path),
776+
**DEFAULT_PLINK_CONVERT_ARGS,
777+
)
778+
779+
@pytest.mark.parametrize("response", ["n", "N", "No"])
780+
@mock.patch("bio2zarr.plink.convert")
781+
def test_plink_convert_overwrite_zarr_confirm_no(self, mocked, tmp_path, response):
782+
prefix = "tests/data/plink/example"
783+
zarr_path = tmp_path / "zarr"
784+
zarr_path.mkdir()
785+
runner = ct.CliRunner()
786+
result = runner.invoke(
787+
cli.plink2zarr_main,
788+
f"convert {prefix} {zarr_path}",
789+
catch_exceptions=False,
790+
input=response,
791+
)
792+
assert result.exit_code == 1
793+
assert "Aborted" in result.stderr
794+
mocked.assert_not_called()
795+
796+
@pytest.mark.parametrize("force_arg", ["-f", "--force"])
797+
@mock.patch("bio2zarr.plink.convert")
798+
def test_plink_convert_overwrite_zarr_force(self, mocked, tmp_path, force_arg):
799+
prefix = "tests/data/plink/example"
800+
zarr_path = tmp_path / "zarr"
801+
zarr_path.mkdir()
802+
runner = ct.CliRunner()
803+
result = runner.invoke(
804+
cli.plink2zarr_main,
805+
f"convert {prefix} {zarr_path} {force_arg}",
806+
catch_exceptions=False,
807+
)
808+
assert result.exit_code == 0
809+
assert len(result.stdout) == 0
810+
assert len(result.stderr) == 0
811+
mocked.assert_called_once_with(
812+
prefix,
813+
str(zarr_path),
814+
**DEFAULT_PLINK_CONVERT_ARGS,
815+
)
816+
757817

758818
class TestVcfEndToEnd:
759819
vcf_path = "tests/data/vcf/sample.vcf.gz"

0 commit comments

Comments
 (0)