Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Will-Tyler committed Jul 16, 2024
1 parent 827c93d commit a8fd845
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 9 deletions.
Binary file modified tests/data/vcf/local_alleles.vcf.gz
Binary file not shown.
Binary file modified tests/data/vcf/local_alleles.vcf.gz.csi
Binary file not shown.
Binary file added tests/data/vcf/triploid2.vcf.gz
Binary file not shown.
Binary file added tests/data/vcf/triploid2.vcf.gz.csi
Binary file not shown.
Binary file added tests/data/vcf/triploid3.vcf.gz
Binary file not shown.
Binary file added tests/data/vcf/triploid3.vcf.gz.csi
Binary file not shown.
28 changes: 19 additions & 9 deletions tests/test_vcf_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,8 @@ def test_call_LAA(self, ds):
[[1, -2, -2], [-1, -2, -2]],
[[2, -2, -2], [2, -2, -2]],
[[1, -2, -2], [-2, -2, -2]],
[[-2, -2, -2], [-2, -2, -2]],
[[1, -2, -2], [1, -2, -2]],
]
nt.assert_array_equal(ds.call_LAA.values, call_LAA)

Expand Down Expand Up @@ -493,29 +495,37 @@ def test_call_LPL(self, ds):
[30, 30, 30, -2, -2, -2, -2, -2, -2, -2],
[30, -1, 0, -2, -2, -2, -2, -2, -2, -2],
],
[
[-1, -1, -1, -2, -2, -2, -2, -2, -2, -2],
[-1, -1, -1, -2, -2, -2, -2, -2, -2, -2],
],
[
[-1, -1, -2, -2, -2, -2, -2, -2, -2, -2],
[-1, -1, -2, -2, -2, -2, -2, -2, -2, -2],
],
]
nt.assert_array_equal(ds.call_LPL.values, call_LPL)


class TestTriploidExample:
data_path = "tests/data/vcf/triploid.vcf.gz"

@pytest.fixture(scope="class")
def ds(self, tmp_path_factory):
@pytest.fixture(scope="class", params=["triploid", "triploid2", "triploid3"])
def ds(self, tmp_path_factory, request):
data_path = f"tests/data/vcf/{request.param}.vcf.gz"
out = tmp_path_factory.mktemp("data") / "example.vcf.zarr"
vcf2zarr.convert([self.data_path], out, local_alleles=False)
vcf2zarr.convert([data_path], out, local_alleles=False)
return sg.load_dataset(out)

def test_error_with_local_alleles(self, tmp_path_factory):
icf_path = tmp_path_factory.mktemp("data") / "triploid.icf"
@pytest.mark.parametrize("name", ["triploid", "triploid2", "triploid3"])
def test_error_with_local_alleles(self, tmp_path_factory, name):
data_path = f"tests/data/vcf/{name}.vcf.gz"
icf_path = tmp_path_factory.mktemp("data") / f"{name}.icf"
with pytest.raises(ValueError, match=re.escape("Cannot handle ploidy = 3")):
vcf2zarr.explode(
icf_path, [self.data_path], worker_processes=0, local_alleles=True
icf_path, [data_path], worker_processes=0, local_alleles=True
)

def test_ok_without_local_alleles(self, ds):
nt.assert_array_equal(ds.call_genotype.values, [[[0, 0, 0]]])
nt.assert_array_equal(ds.call_PL.values, [[[0, 0, 0, 0]]])


class Test1000G2020Example:
Expand Down

0 comments on commit a8fd845

Please sign in to comment.