diff --git a/haptools/transform.py b/haptools/transform.py index 4e406a39..f43ccb84 100644 --- a/haptools/transform.py +++ b/haptools/transform.py @@ -593,6 +593,8 @@ def transform_haps( "that the IDs in your .hap file correspond with those you provided. " f"Here are the first few missing haplotypes: {diff[:first_few]}" ) + if len(hp.data) == 0: + raise ValueError("Didn't load any haplotypes from the .hap file") log.info("Extracting variants from haplotypes") variants = {vr.id for id in hp.type_ids["H"] for vr in hp.data[id].variants} diff --git a/tests/test_transform.py b/tests/test_transform.py index ac4f9868..c094e720 100644 --- a/tests/test_transform.py +++ b/tests/test_transform.py @@ -386,10 +386,10 @@ def test_transform_empty_hap(capfd): # can we run transform with the empty hap file? cmd = f"transform --region 1:10116-10122 {gt_file} {hp_file}" runner = CliRunner() - result = runner.invoke(main, cmd.split(" "), catch_exceptions=False) + result = runner.invoke(main, cmd.split(" ")) captured = capfd.readouterr() assert all(line for line in captured.out.split("\n") if line.startswith("#")) - assert result.exit_code == 0 + assert result.exit_code != 0 # now, index the empty hap file and try again cmd = f"index {hp_file}" @@ -400,13 +400,12 @@ def test_transform_empty_hap(capfd): assert hp_file_gz.exists() assert hp_file_idx.exists() - # what about now? does it still work? + # what about now? does it still fail? cmd = f"transform --region 1:10116-10122 {gt_file} {hp_file_gz}" runner = CliRunner() - result = runner.invoke(main, cmd.split(" "), catch_exceptions=False) + result = runner.invoke(main, cmd.split(" ")) captured = capfd.readouterr() - assert all(line for line in captured.out.split("\n") if line.startswith("#")) - assert result.exit_code == 0 + assert result.exit_code != 0 hp_file.unlink() hp_file_gz.unlink()