Skip to content

Commit

Permalink
raise ValueError for empty hap file in transform
Browse files Browse the repository at this point in the history
  • Loading branch information
aryarm authored Dec 1, 2024
1 parent 1eb7ffd commit 525fd44
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 2 additions & 0 deletions haptools/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
11 changes: 5 additions & 6 deletions tests/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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()
Expand Down

0 comments on commit 525fd44

Please sign in to comment.