Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions bio2zarr/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import numcodecs
import tabulate

from . import icf as icf_mod
from . import plink, provenance, vcf_utils
from . import vcf as vcf_mod

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -197,7 +197,7 @@ def check_partitions(num_partitions):
def get_compressor(cname):
if cname is None:
return None
config = icf_mod.ICF_DEFAULT_COMPRESSOR.get_config()
config = vcf_mod.ICF_DEFAULT_COMPRESSOR.get_config()
config["cname"] = cname
return numcodecs.get_codec(config)

Expand Down Expand Up @@ -236,7 +236,7 @@ def explode(
"""
setup_logging(verbose)
check_overwrite_dir(icf_path, force)
icf_mod.explode(
vcf_mod.explode(
icf_path,
vcfs,
worker_processes=worker_processes,
Expand Down Expand Up @@ -276,7 +276,7 @@ def dexplode_init(
setup_logging(verbose)
check_overwrite_dir(icf_path, force)
check_partitions(num_partitions)
work_summary = icf_mod.explode_init(
work_summary = vcf_mod.explode_init(
icf_path,
vcfs,
target_num_partitions=num_partitions,
Expand Down Expand Up @@ -304,7 +304,7 @@ def dexplode_partition(icf_path, partition, verbose, one_based):
setup_logging(verbose)
if one_based:
partition -= 1
icf_mod.explode_partition(icf_path, partition)
vcf_mod.explode_partition(icf_path, partition)


@click.command
Expand All @@ -315,7 +315,7 @@ def dexplode_finalise(icf_path, verbose):
Final step for distributed conversion of VCF(s) to intermediate columnar format.
"""
setup_logging(verbose)
icf_mod.explode_finalise(icf_path)
vcf_mod.explode_finalise(icf_path)


@click.command
Expand All @@ -326,7 +326,7 @@ def inspect(path, verbose):
Inspect an intermediate columnar format or Zarr path.
"""
setup_logging(verbose)
data = icf_mod.inspect(path)
data = vcf_mod.inspect(path)
click.echo(tabulate.tabulate(data, headers="keys"))


Expand All @@ -345,7 +345,7 @@ def mkschema(icf_path, variants_chunk_size, samples_chunk_size, local_alleles):
err=True,
)
stream = click.get_text_stream("stdout")
icf_mod.mkschema(
vcf_mod.mkschema(
icf_path,
stream,
variants_chunk_size=variants_chunk_size,
Expand Down Expand Up @@ -384,7 +384,7 @@ def encode(
"""
setup_logging(verbose)
check_overwrite_dir(zarr_path, force)
icf_mod.encode(
vcf_mod.encode(
icf_path,
zarr_path,
schema_path=schema,
Expand Down Expand Up @@ -438,7 +438,7 @@ def dencode_init(
setup_logging(verbose)
check_overwrite_dir(zarr_path, force)
check_partitions(num_partitions)
work_summary = icf_mod.encode_init(
work_summary = vcf_mod.encode_init(
icf_path,
zarr_path,
target_num_partitions=num_partitions,
Expand Down Expand Up @@ -466,7 +466,7 @@ def dencode_partition(zarr_path, partition, verbose, one_based):
setup_logging(verbose)
if one_based:
partition -= 1
icf_mod.encode_partition(zarr_path, partition)
vcf_mod.encode_partition(zarr_path, partition)


@click.command
Expand All @@ -478,7 +478,7 @@ def dencode_finalise(zarr_path, verbose, progress):
Final step for distributed conversion of ICF to VCF Zarr.
"""
setup_logging(verbose)
icf_mod.encode_finalise(zarr_path, show_progress=progress)
vcf_mod.encode_finalise(zarr_path, show_progress=progress)


@click.command(name="convert")
Expand Down Expand Up @@ -507,7 +507,7 @@ def convert_vcf(
"""
setup_logging(verbose)
check_overwrite_dir(zarr_path, force)
icf_mod.convert(
vcf_mod.convert(
vcfs,
zarr_path,
variants_chunk_size=variants_chunk_size,
Expand Down
File renamed without changes.
62 changes: 31 additions & 31 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class TestWithMocks:
vcf_path = "tests/data/vcf/sample.vcf.gz"

@pytest.mark.parametrize(("progress", "flag"), [(True, "-P"), (False, "-Q")])
@mock.patch("bio2zarr.icf.explode")
@mock.patch("bio2zarr.vcf.explode")
def test_vcf_explode(self, mocked, tmp_path, progress, flag):
icf_path = tmp_path / "icf"
runner = ct.CliRunner(mix_stderr=False)
Expand All @@ -101,7 +101,7 @@ def test_vcf_explode(self, mocked, tmp_path, progress, flag):
mocked.assert_called_once_with(str(icf_path), (self.vcf_path,), **args)

@pytest.mark.parametrize("compressor", ["lz4", "zstd"])
@mock.patch("bio2zarr.icf.explode")
@mock.patch("bio2zarr.vcf.explode")
def test_vcf_explode_compressor(self, mocked, tmp_path, compressor):
icf_path = tmp_path / "icf"
runner = ct.CliRunner(mix_stderr=False)
Expand All @@ -124,7 +124,7 @@ def test_vcf_explode_compressor(self, mocked, tmp_path, compressor):
)

@pytest.mark.parametrize("compressor", ["lz4", "zstd"])
@mock.patch("bio2zarr.icf.explode_init")
@mock.patch("bio2zarr.vcf.explode_init")
def test_vcf_dexplode_init_compressor(self, mocked, tmp_path, compressor):
icf_path = tmp_path / "icf"
runner = ct.CliRunner(mix_stderr=False)
Expand All @@ -148,7 +148,7 @@ def test_vcf_dexplode_init_compressor(self, mocked, tmp_path, compressor):
)

@pytest.mark.parametrize("compressor", ["LZ4", "asdf"])
@mock.patch("bio2zarr.icf.explode")
@mock.patch("bio2zarr.vcf.explode")
def test_vcf_explode_bad_compressor(self, mocked, tmp_path, compressor):
runner = ct.CliRunner(mix_stderr=False)
icf_path = tmp_path / "icf"
Expand All @@ -161,7 +161,7 @@ def test_vcf_explode_bad_compressor(self, mocked, tmp_path, compressor):
assert "Invalid value for '-C'" in result.stderr
mocked.assert_not_called()

@mock.patch("bio2zarr.icf.explode")
@mock.patch("bio2zarr.vcf.explode")
def test_vcf_explode_multiple_vcfs(self, mocked, tmp_path):
icf_path = tmp_path / "icf"
runner = ct.CliRunner(mix_stderr=False)
Expand All @@ -178,7 +178,7 @@ def test_vcf_explode_multiple_vcfs(self, mocked, tmp_path):
)

@pytest.mark.parametrize("response", ["y", "Y", "yes"])
@mock.patch("bio2zarr.icf.explode")
@mock.patch("bio2zarr.vcf.explode")
def test_vcf_explode_overwrite_icf_confirm_yes(self, mocked, tmp_path, response):
icf_path = tmp_path / "icf"
icf_path.mkdir()
Expand All @@ -197,7 +197,7 @@ def test_vcf_explode_overwrite_icf_confirm_yes(self, mocked, tmp_path, response)
)

@pytest.mark.parametrize("response", ["y", "Y", "yes"])
@mock.patch("bio2zarr.icf.encode")
@mock.patch("bio2zarr.vcf.encode")
def test_vcf_encode_overwrite_zarr_confirm_yes(self, mocked, tmp_path, response):
icf_path = tmp_path / "icf"
icf_path.mkdir()
Expand All @@ -218,7 +218,7 @@ def test_vcf_encode_overwrite_zarr_confirm_yes(self, mocked, tmp_path, response)
)

@pytest.mark.parametrize("force_arg", ["-f", "--force"])
@mock.patch("bio2zarr.icf.explode")
@mock.patch("bio2zarr.vcf.explode")
def test_vcf_explode_overwrite_icf_force(self, mocked, tmp_path, force_arg):
icf_path = tmp_path / "icf"
icf_path.mkdir()
Expand All @@ -236,7 +236,7 @@ def test_vcf_explode_overwrite_icf_force(self, mocked, tmp_path, force_arg):
)

@pytest.mark.parametrize("force_arg", ["-f", "--force"])
@mock.patch("bio2zarr.icf.encode")
@mock.patch("bio2zarr.vcf.encode")
def test_vcf_encode_overwrite_icf_force(self, mocked, tmp_path, force_arg):
icf_path = tmp_path / "icf"
icf_path.mkdir()
Expand All @@ -257,7 +257,7 @@ def test_vcf_encode_overwrite_icf_force(self, mocked, tmp_path, force_arg):
**DEFAULT_ENCODE_ARGS,
)

@mock.patch("bio2zarr.icf.explode")
@mock.patch("bio2zarr.vcf.explode")
def test_vcf_explode_missing_vcf(self, mocked, tmp_path):
icf_path = tmp_path / "icf"
runner = ct.CliRunner(mix_stderr=False)
Expand All @@ -272,7 +272,7 @@ def test_vcf_explode_missing_vcf(self, mocked, tmp_path):
mocked.assert_not_called()

@pytest.mark.parametrize("response", ["n", "N", "No"])
@mock.patch("bio2zarr.icf.explode")
@mock.patch("bio2zarr.vcf.explode")
def test_vcf_explode_overwrite_icf_confirm_no(self, mocked, tmp_path, response):
icf_path = tmp_path / "icf"
icf_path.mkdir()
Expand All @@ -287,7 +287,7 @@ def test_vcf_explode_overwrite_icf_confirm_no(self, mocked, tmp_path, response):
assert "Aborted" in result.stderr
mocked.assert_not_called()

@mock.patch("bio2zarr.icf.explode")
@mock.patch("bio2zarr.vcf.explode")
def test_vcf_explode_missing_and_existing_vcf(self, mocked, tmp_path):
icf_path = tmp_path / "icf"
runner = ct.CliRunner(mix_stderr=False)
Expand All @@ -302,7 +302,7 @@ def test_vcf_explode_missing_and_existing_vcf(self, mocked, tmp_path):
mocked.assert_not_called()

@pytest.mark.parametrize(("progress", "flag"), [(True, "-P"), (False, "-Q")])
@mock.patch("bio2zarr.icf.explode_init", return_value=FakeWorkSummary(5))
@mock.patch("bio2zarr.vcf.explode_init", return_value=FakeWorkSummary(5))
def test_vcf_dexplode_init(self, mocked, tmp_path, progress, flag):
runner = ct.CliRunner(mix_stderr=False)
icf_path = tmp_path / "icf"
Expand All @@ -324,7 +324,7 @@ def test_vcf_dexplode_init(self, mocked, tmp_path, progress, flag):
)

@pytest.mark.parametrize("num_partitions", ["-1", "0", "asdf", "1.112"])
@mock.patch("bio2zarr.icf.explode_init", return_value=5)
@mock.patch("bio2zarr.vcf.explode_init", return_value=5)
def test_vcf_dexplode_init_bad_num_partitions(
self, mocked, tmp_path, num_partitions
):
Expand All @@ -339,7 +339,7 @@ def test_vcf_dexplode_init_bad_num_partitions(
assert "Invalid value for '-n'" in result.stderr
mocked.assert_not_called()

@mock.patch("bio2zarr.icf.explode_init", return_value=5)
@mock.patch("bio2zarr.vcf.explode_init", return_value=5)
def test_vcf_dexplode_init_no_partitions(self, mocked, tmp_path):
runner = ct.CliRunner(mix_stderr=False)
icf_path = tmp_path / "icf"
Expand All @@ -352,7 +352,7 @@ def test_vcf_dexplode_init_no_partitions(self, mocked, tmp_path):
assert "-n/--num-partitions must currently be specified" in result.stderr
mocked.assert_not_called()

@mock.patch("bio2zarr.icf.explode_partition")
@mock.patch("bio2zarr.vcf.explode_partition")
def test_vcf_dexplode_partition(self, mocked, tmp_path):
runner = ct.CliRunner(mix_stderr=False)
icf_path = tmp_path / "icf"
Expand All @@ -369,7 +369,7 @@ def test_vcf_dexplode_partition(self, mocked, tmp_path):
str(icf_path), 1, **DEFAULT_DEXPLODE_PARTITION_ARGS
)

@mock.patch("bio2zarr.icf.explode_partition")
@mock.patch("bio2zarr.vcf.explode_partition")
def test_vcf_dexplode_partition_one_based(self, mocked, tmp_path):
runner = ct.CliRunner(mix_stderr=False)
icf_path = tmp_path / "icf"
Expand All @@ -386,7 +386,7 @@ def test_vcf_dexplode_partition_one_based(self, mocked, tmp_path):
str(icf_path), 0, **DEFAULT_DEXPLODE_PARTITION_ARGS
)

@mock.patch("bio2zarr.icf.explode_partition")
@mock.patch("bio2zarr.vcf.explode_partition")
def test_vcf_dexplode_partition_missing_dir(self, mocked, tmp_path):
runner = ct.CliRunner(mix_stderr=False)
icf_path = tmp_path / "icf"
Expand All @@ -401,7 +401,7 @@ def test_vcf_dexplode_partition_missing_dir(self, mocked, tmp_path):
mocked.assert_not_called()

@pytest.mark.parametrize("partition", ["-- -1", "asdf", "1.112"])
@mock.patch("bio2zarr.icf.explode_partition")
@mock.patch("bio2zarr.vcf.explode_partition")
def test_vcf_dexplode_partition_bad_partition(self, mocked, tmp_path, partition):
runner = ct.CliRunner(mix_stderr=False)
icf_path = tmp_path / "icf"
Expand All @@ -416,7 +416,7 @@ def test_vcf_dexplode_partition_bad_partition(self, mocked, tmp_path, partition)
assert len(result.stdout) == 0
mocked.assert_not_called()

@mock.patch("bio2zarr.icf.explode_finalise")
@mock.patch("bio2zarr.vcf.explode_finalise")
def test_vcf_dexplode_finalise(self, mocked, tmp_path):
runner = ct.CliRunner(mix_stderr=False)
result = runner.invoke(
Expand All @@ -427,7 +427,7 @@ def test_vcf_dexplode_finalise(self, mocked, tmp_path):
assert len(result.stderr) == 0
mocked.assert_called_once_with(str(tmp_path))

@mock.patch("bio2zarr.icf.inspect")
@mock.patch("bio2zarr.vcf.inspect")
def test_inspect(self, mocked, tmp_path):
runner = ct.CliRunner(mix_stderr=False)
result = runner.invoke(
Expand All @@ -438,7 +438,7 @@ def test_inspect(self, mocked, tmp_path):
assert len(result.stderr) == 0
mocked.assert_called_once_with(str(tmp_path))

@mock.patch("bio2zarr.icf.mkschema")
@mock.patch("bio2zarr.vcf.mkschema")
def test_mkschema(self, mocked, tmp_path):
runner = ct.CliRunner(mix_stderr=False)
result = runner.invoke(
Expand All @@ -455,7 +455,7 @@ def test_mkschema(self, mocked, tmp_path):
mocked.assert_called_once()

@pytest.mark.parametrize(("progress", "flag"), [(True, "-P"), (False, "-Q")])
@mock.patch("bio2zarr.icf.encode")
@mock.patch("bio2zarr.vcf.encode")
def test_encode(self, mocked, tmp_path, progress, flag):
icf_path = tmp_path / "icf"
icf_path.mkdir()
Expand All @@ -478,7 +478,7 @@ def test_encode(self, mocked, tmp_path, progress, flag):
)

@pytest.mark.parametrize(("progress", "flag"), [(True, "-P"), (False, "-Q")])
@mock.patch("bio2zarr.icf.encode_init", return_value=FakeWorkSummary(10))
@mock.patch("bio2zarr.vcf.encode_init", return_value=FakeWorkSummary(10))
def test_dencode_init(self, mocked, tmp_path, progress, flag):
icf_path = tmp_path / "icf"
icf_path.mkdir()
Expand All @@ -501,7 +501,7 @@ def test_dencode_init(self, mocked, tmp_path, progress, flag):
**args,
)

@mock.patch("bio2zarr.icf.encode_init", return_value=5)
@mock.patch("bio2zarr.vcf.encode_init", return_value=5)
def test_vcf_dencode_init_no_partitions(self, mocked, tmp_path):
runner = ct.CliRunner(mix_stderr=False)
icf_path = tmp_path / "icf"
Expand All @@ -516,7 +516,7 @@ def test_vcf_dencode_init_no_partitions(self, mocked, tmp_path):
assert "-n/--num-partitions must currently be specified" in result.stderr
mocked.assert_not_called()

@mock.patch("bio2zarr.icf.encode_partition")
@mock.patch("bio2zarr.vcf.encode_partition")
def test_vcf_dencode_partition(self, mocked, tmp_path):
runner = ct.CliRunner(mix_stderr=False)
zarr_path = tmp_path / "zarr"
Expand All @@ -533,7 +533,7 @@ def test_vcf_dencode_partition(self, mocked, tmp_path):
str(zarr_path), 1, **DEFAULT_DENCODE_PARTITION_ARGS
)

@mock.patch("bio2zarr.icf.encode_partition")
@mock.patch("bio2zarr.vcf.encode_partition")
def test_vcf_dencode_partition_one_based(self, mocked, tmp_path):
runner = ct.CliRunner(mix_stderr=False)
zarr_path = tmp_path / "zarr"
Expand All @@ -551,7 +551,7 @@ def test_vcf_dencode_partition_one_based(self, mocked, tmp_path):
)

@pytest.mark.parametrize(("progress", "flag"), [(True, "-P"), (False, "-Q")])
@mock.patch("bio2zarr.icf.encode_finalise")
@mock.patch("bio2zarr.vcf.encode_finalise")
def test_vcf_dencode_finalise(self, mocked, tmp_path, progress, flag):
runner = ct.CliRunner(mix_stderr=False)
result = runner.invoke(
Expand All @@ -567,7 +567,7 @@ def test_vcf_dencode_finalise(self, mocked, tmp_path, progress, flag):
mocked.assert_called_once_with(str(tmp_path), **args)

@pytest.mark.parametrize(("progress", "flag"), [(True, "-P"), (False, "-Q")])
@mock.patch("bio2zarr.icf.convert")
@mock.patch("bio2zarr.vcf.convert")
def test_convert_vcf(self, mocked, progress, flag):
runner = ct.CliRunner(mix_stderr=False)
result = runner.invoke(
Expand All @@ -587,7 +587,7 @@ def test_convert_vcf(self, mocked, progress, flag):
)

@pytest.mark.parametrize("response", ["n", "N", "No"])
@mock.patch("bio2zarr.icf.convert")
@mock.patch("bio2zarr.vcf.convert")
def test_vcf_convert_overwrite_zarr_confirm_no(self, mocked, tmp_path, response):
zarr_path = tmp_path / "zarr"
zarr_path.mkdir()
Expand Down Expand Up @@ -617,7 +617,7 @@ def test_convert_plink(self, mocked, progress, flag):
mocked.assert_called_once_with("in", "out", **args)

@pytest.mark.parametrize("response", ["y", "Y", "yes"])
@mock.patch("bio2zarr.icf.convert")
@mock.patch("bio2zarr.vcf.convert")
def test_vcf_convert_overwrite_zarr_confirm_yes(self, mocked, tmp_path, response):
zarr_path = tmp_path / "zarr"
zarr_path.mkdir()
Expand Down
Loading