From 22166f5328a566043f6bc67f3ee8767a093ad63f Mon Sep 17 00:00:00 2001 From: willtyler Date: Mon, 26 Aug 2024 23:42:22 +0000 Subject: [PATCH 1/2] Add output option to vcztools view --- tests/test_cli.py | 14 ++++++++++++++ vcztools/cli.py | 6 +++++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/test_cli.py diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..a11aa0e --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,14 @@ +import os.path +import pathlib + +from tests.test_bcftools_validation import run_vcztools +from tests.utils import vcz_path_cache + + +def test_view_output(tmp_path): + vcf_path = pathlib.Path("tests/data/vcf/sample.vcf.gz") + vcz_path = vcz_path_cache(vcf_path) + output = tmp_path / "output.vcf" + + run_vcztools(f"view {vcz_path} --output {output}") + assert os.path.exists(output) diff --git a/vcztools/cli.py b/vcztools/cli.py index 873880a..de32c83 100644 --- a/vcztools/cli.py +++ b/vcztools/cli.py @@ -46,6 +46,9 @@ def query(path, list_samples): @click.command @click.argument("path", type=click.Path()) +@click.option( + "-o", "--output", type=str, default=None, help="File path to write output to." +) @click.option( "-h", "--header-only", @@ -92,6 +95,7 @@ def query(path, list_samples): ) def view( path, + output, header_only, no_header, no_version, @@ -103,7 +107,7 @@ def view( ): vcf_writer.write_vcf( path, - sys.stdout, + output, header_only=header_only, no_header=no_header, variant_regions=regions, From db67740823afa7090e38f735a9bde58d949a8545 Mon Sep 17 00:00:00 2001 From: willtyler Date: Thu, 29 Aug 2024 17:40:29 +0000 Subject: [PATCH 2/2] Change CLI test to validation test --- tests/test_bcftools_validation.py | 21 +++++++++++++++++++++ tests/test_cli.py | 14 -------------- 2 files changed, 21 insertions(+), 14 deletions(-) delete mode 100644 tests/test_cli.py diff --git a/tests/test_bcftools_validation.py b/tests/test_bcftools_validation.py index 3a5cb88..65cf775 100644 --- a/tests/test_bcftools_validation.py +++ b/tests/test_bcftools_validation.py @@ -68,6 +68,27 @@ def test_vcf_output(tmp_path, args, vcf_file): assert_vcfs_close(bcftools_out_file, vcztools_out_file) +@pytest.mark.parametrize( + ("args", "vcf_file"), + [ + ("view --no-version", "sample.vcf.gz") + ], +) +def test_vcf_output_with_output_option(tmp_path, args, vcf_file): + vcf_path = pathlib.Path("tests/data/vcf") / vcf_file + vcz_path = vcz_path_cache(vcf_path) + + bcftools_out_file = tmp_path.joinpath("bcftools_out.vcf") + vcztools_out_file = tmp_path.joinpath("vcztools_out.vcf") + + bcftools_args = f"{args} -o {bcftools_out_file}" + vcztools_args = f"{args} -o {vcztools_out_file}" + + run_bcftools(f"{bcftools_args} {vcf_path}") + run_vcztools(f"{vcztools_args} {vcz_path}") + + assert_vcfs_close(bcftools_out_file, vcztools_out_file) + @pytest.mark.parametrize( ("args", "vcf_name"), diff --git a/tests/test_cli.py b/tests/test_cli.py deleted file mode 100644 index a11aa0e..0000000 --- a/tests/test_cli.py +++ /dev/null @@ -1,14 +0,0 @@ -import os.path -import pathlib - -from tests.test_bcftools_validation import run_vcztools -from tests.utils import vcz_path_cache - - -def test_view_output(tmp_path): - vcf_path = pathlib.Path("tests/data/vcf/sample.vcf.gz") - vcz_path = vcz_path_cache(vcf_path) - output = tmp_path / "output.vcf" - - run_vcztools(f"view {vcz_path} --output {output}") - assert os.path.exists(output)