|
61 | 61 | local_alleles=False,
|
62 | 62 | )
|
63 | 63 |
|
| 64 | +DEFAULT_TSKIT_CONVERT_ARGS = dict( |
| 65 | + contig_id=None, |
| 66 | + isolated_as_missing=False, |
| 67 | + variants_chunk_size=None, |
| 68 | + samples_chunk_size=None, |
| 69 | + show_progress=True, |
| 70 | + worker_processes=1, |
| 71 | +) |
| 72 | + |
64 | 73 | DEFAULT_PLINK_CONVERT_ARGS = dict(
|
65 | 74 | variants_chunk_size=None,
|
66 | 75 | samples_chunk_size=None,
|
@@ -635,6 +644,116 @@ def test_vcf_convert_overwrite_zarr_confirm_yes(self, mocked, tmp_path, response
|
635 | 644 | (self.vcf_path,), str(zarr_path), **DEFAULT_CONVERT_ARGS
|
636 | 645 | )
|
637 | 646 |
|
| 647 | + @pytest.mark.parametrize(("progress", "flag"), [(True, "-P"), (False, "-Q")]) |
| 648 | + @mock.patch("bio2zarr.tskit.convert") |
| 649 | + def test_convert_tskit(self, mocked, tmp_path, progress, flag): |
| 650 | + ts_path = "tests/data/ts/example.trees" |
| 651 | + zarr_path = tmp_path / "zarr" |
| 652 | + runner = ct.CliRunner(mix_stderr=False) |
| 653 | + result = runner.invoke( |
| 654 | + cli.tskit2zarr, |
| 655 | + f"convert {ts_path} {zarr_path} {flag}", |
| 656 | + catch_exceptions=False, |
| 657 | + ) |
| 658 | + assert result.exit_code == 0 |
| 659 | + assert len(result.stdout) == 0 |
| 660 | + assert len(result.stderr) == 0 |
| 661 | + args = dict(DEFAULT_TSKIT_CONVERT_ARGS) |
| 662 | + args["show_progress"] = progress |
| 663 | + mocked.assert_called_once_with( |
| 664 | + ts_path, |
| 665 | + str(zarr_path), |
| 666 | + **args, |
| 667 | + ) |
| 668 | + |
| 669 | + @pytest.mark.parametrize("response", ["y", "Y", "yes"]) |
| 670 | + @mock.patch("bio2zarr.tskit.convert") |
| 671 | + def test_tskit_convert_overwrite_zarr_confirm_yes(self, mocked, tmp_path, response): |
| 672 | + ts_path = "tests/data/ts/example.trees" |
| 673 | + zarr_path = tmp_path / "zarr" |
| 674 | + zarr_path.mkdir() |
| 675 | + runner = ct.CliRunner(mix_stderr=False) |
| 676 | + result = runner.invoke( |
| 677 | + cli.tskit2zarr, |
| 678 | + f"convert {ts_path} {zarr_path}", |
| 679 | + catch_exceptions=False, |
| 680 | + input=response, |
| 681 | + ) |
| 682 | + assert result.exit_code == 0 |
| 683 | + assert f"Do you want to overwrite {zarr_path}" in result.stdout |
| 684 | + assert len(result.stderr) == 0 |
| 685 | + mocked.assert_called_once_with( |
| 686 | + ts_path, |
| 687 | + str(zarr_path), |
| 688 | + **DEFAULT_TSKIT_CONVERT_ARGS, |
| 689 | + ) |
| 690 | + |
| 691 | + @pytest.mark.parametrize("response", ["n", "N", "No"]) |
| 692 | + @mock.patch("bio2zarr.tskit.convert") |
| 693 | + def test_tskit_convert_overwrite_zarr_confirm_no(self, mocked, tmp_path, response): |
| 694 | + ts_path = "tests/data/ts/example.trees" |
| 695 | + zarr_path = tmp_path / "zarr" |
| 696 | + zarr_path.mkdir() |
| 697 | + runner = ct.CliRunner(mix_stderr=False) |
| 698 | + result = runner.invoke( |
| 699 | + cli.tskit2zarr, |
| 700 | + f"convert {ts_path} {zarr_path}", |
| 701 | + catch_exceptions=False, |
| 702 | + input=response, |
| 703 | + ) |
| 704 | + assert result.exit_code == 1 |
| 705 | + assert "Aborted" in result.stderr |
| 706 | + mocked.assert_not_called() |
| 707 | + |
| 708 | + @pytest.mark.parametrize("force_arg", ["-f", "--force"]) |
| 709 | + @mock.patch("bio2zarr.tskit.convert") |
| 710 | + def test_tskit_convert_overwrite_zarr_force(self, mocked, tmp_path, force_arg): |
| 711 | + ts_path = "tests/data/ts/example.trees" |
| 712 | + zarr_path = tmp_path / "zarr" |
| 713 | + zarr_path.mkdir() |
| 714 | + runner = ct.CliRunner(mix_stderr=False) |
| 715 | + result = runner.invoke( |
| 716 | + cli.tskit2zarr, |
| 717 | + f"convert {ts_path} {zarr_path} {force_arg}", |
| 718 | + catch_exceptions=False, |
| 719 | + ) |
| 720 | + assert result.exit_code == 0 |
| 721 | + assert len(result.stdout) == 0 |
| 722 | + assert len(result.stderr) == 0 |
| 723 | + mocked.assert_called_once_with( |
| 724 | + ts_path, |
| 725 | + str(zarr_path), |
| 726 | + **DEFAULT_TSKIT_CONVERT_ARGS, |
| 727 | + ) |
| 728 | + |
| 729 | + @mock.patch("bio2zarr.tskit.convert") |
| 730 | + def test_tskit_convert_with_options(self, mocked, tmp_path): |
| 731 | + ts_path = "tests/data/ts/example.trees" |
| 732 | + zarr_path = tmp_path / "zarr" |
| 733 | + runner = ct.CliRunner(mix_stderr=False) |
| 734 | + result = runner.invoke( |
| 735 | + cli.tskit2zarr, |
| 736 | + f"convert {ts_path} {zarr_path} --contig-id chr1 " |
| 737 | + "--isolated-as-missing -l 100 -w 50 -p 4", |
| 738 | + catch_exceptions=False, |
| 739 | + ) |
| 740 | + assert result.exit_code == 0 |
| 741 | + assert len(result.stdout) == 0 |
| 742 | + assert len(result.stderr) == 0 |
| 743 | + |
| 744 | + expected_args = dict(DEFAULT_TSKIT_CONVERT_ARGS) |
| 745 | + expected_args["contig_id"] = "chr1" |
| 746 | + expected_args["isolated_as_missing"] = True |
| 747 | + expected_args["variants_chunk_size"] = 100 |
| 748 | + expected_args["samples_chunk_size"] = 50 |
| 749 | + expected_args["worker_processes"] = 4 |
| 750 | + |
| 751 | + mocked.assert_called_once_with( |
| 752 | + ts_path, |
| 753 | + str(zarr_path), |
| 754 | + **expected_args, |
| 755 | + ) |
| 756 | + |
638 | 757 |
|
639 | 758 | class TestVcfEndToEnd:
|
640 | 759 | vcf_path = "tests/data/vcf/sample.vcf.gz"
|
@@ -908,10 +1027,36 @@ def test_part_size_multiple_vcfs(self):
|
908 | 1027 |
|
909 | 1028 |
|
910 | 1029 | @pytest.mark.parametrize(
|
911 |
| - "cmd", [main.bio2zarr, cli.vcf2zarr_main, cli.plink2zarr, cli.vcfpartition] |
| 1030 | + "cmd", |
| 1031 | + [ |
| 1032 | + main.bio2zarr, |
| 1033 | + cli.vcf2zarr_main, |
| 1034 | + cli.plink2zarr, |
| 1035 | + cli.vcfpartition, |
| 1036 | + cli.tskit2zarr, |
| 1037 | + ], |
912 | 1038 | )
|
913 | 1039 | def test_version(cmd):
|
914 | 1040 | runner = ct.CliRunner(mix_stderr=False)
|
915 | 1041 | result = runner.invoke(cmd, ["--version"], catch_exceptions=False)
|
916 | 1042 | s = f"version {provenance.__version__}\n"
|
917 | 1043 | assert result.stdout.endswith(s)
|
| 1044 | + |
| 1045 | + |
| 1046 | +class TestTskitEndToEnd: |
| 1047 | + def test_convert(self, tmp_path): |
| 1048 | + ts_path = "tests/data/ts/example.trees" |
| 1049 | + zarr_path = tmp_path / "zarr" |
| 1050 | + runner = ct.CliRunner(mix_stderr=False) |
| 1051 | + result = runner.invoke( |
| 1052 | + cli.tskit2zarr, |
| 1053 | + f"convert {ts_path} {zarr_path}", |
| 1054 | + catch_exceptions=False, |
| 1055 | + ) |
| 1056 | + assert result.exit_code == 0 |
| 1057 | + result = runner.invoke( |
| 1058 | + cli.vcf2zarr_main, f"inspect {zarr_path}", catch_exceptions=False |
| 1059 | + ) |
| 1060 | + assert result.exit_code == 0 |
| 1061 | + # Arbitrary check |
| 1062 | + assert "variant_position" in result.stdout |
0 commit comments