Skip to content

Commit

Permalink
VariantData class
Browse files Browse the repository at this point in the history
  • Loading branch information
benjeffery committed Jul 26, 2024
1 parent 0c5d895 commit c6a4458
Show file tree
Hide file tree
Showing 5 changed files with 300 additions and 130 deletions.
37 changes: 27 additions & 10 deletions tests/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -1411,20 +1411,24 @@ def test_cache_used_by_timing(self, tmpdir):
sample_data, ancestor_ts, match_data_dir=tmpdir
)
time2 = time.time() - t
assert time2 < time1 / 1.25
assert time2 < time1
final_ts1.tables.assert_equals(final_ts2.tables, ignore_provenance=True)


@pytest.mark.skipif(sys.platform == "win32", reason="No cyvcf2 on windows")
class TestBatchAncestorMatching:
def test_equivalance(self, tmp_path, tmpdir):
ts, zarr_path = tsutil.make_ts_and_zarr(tmp_path)
samples = tsinfer.SgkitSampleData(zarr_path)
samples = tsinfer.VariantData(zarr_path, "variant_ancestral_allele")
ancestors = tsinfer.generate_ancestors(
samples, path=str(tmpdir / "ancestors.zarr")
)
metadata = tsinfer.match_ancestors_batch_init(
tmpdir / "work", zarr_path, tmpdir / "ancestors.zarr", 1000
tmpdir / "work",
zarr_path,
"variant_ancestral_allele",
tmpdir / "ancestors.zarr",
1000,
)
for group_index, _ in enumerate(metadata["ancestor_grouping"]):
tsinfer.match_ancestors_batch_groups(
Expand All @@ -1436,12 +1440,16 @@ def test_equivalance(self, tmp_path, tmpdir):

def test_equivalance_many_at_once(self, tmp_path, tmpdir):
ts, zarr_path = tsutil.make_ts_and_zarr(tmp_path)
samples = tsinfer.SgkitSampleData(zarr_path)
samples = tsinfer.VariantData(zarr_path, "variant_ancestral_allele")
ancestors = tsinfer.generate_ancestors(
samples, path=str(tmpdir / "ancestors.zarr")
)
metadata = tsinfer.match_ancestors_batch_init(
tmpdir / "work", zarr_path, tmpdir / "ancestors.zarr", 1000
tmpdir / "work",
zarr_path,
"variant_ancestral_allele",
tmpdir / "ancestors.zarr",
1000,
)
tsinfer.match_ancestors_batch_groups(
tmpdir / "work", 0, len(metadata["ancestor_grouping"]) // 2, 2
Expand All @@ -1459,12 +1467,16 @@ def test_equivalance_many_at_once(self, tmp_path, tmpdir):

def test_equivalance_with_partitions(self, tmp_path, tmpdir):
ts, zarr_path = tsutil.make_ts_and_zarr(tmp_path)
samples = tsinfer.SgkitSampleData(zarr_path)
samples = tsinfer.VariantData(zarr_path, "variant_ancestral_allele")
ancestors = tsinfer.generate_ancestors(
samples, path=str(tmpdir / "ancestors.zarr")
)
metadata = tsinfer.match_ancestors_batch_init(
tmpdir / "work", zarr_path, tmpdir / "ancestors.zarr", 1000
tmpdir / "work",
zarr_path,
"variant_ancestral_allele",
tmpdir / "ancestors.zarr",
1000,
)
for group_index, group in enumerate(metadata["ancestor_grouping"]):
if group["partitions"] is None:
Expand All @@ -1485,13 +1497,14 @@ def test_equivalance_with_partitions(self, tmp_path, tmpdir):

def test_max_partitions(self, tmp_path, tmpdir):
ts, zarr_path = tsutil.make_ts_and_zarr(tmp_path)
samples = tsinfer.SgkitSampleData(zarr_path)
samples = tsinfer.VariantData(zarr_path, "variant_ancestral_allele")
ancestors = tsinfer.generate_ancestors(
samples, path=str(tmpdir / "ancestors.zarr")
)
metadata = tsinfer.match_ancestors_batch_init(
tmpdir / "work",
zarr_path,
"variant_ancestral_allele",
tmpdir / "ancestors.zarr",
10000,
max_num_partitions=2,
Expand All @@ -1516,10 +1529,14 @@ def test_max_partitions(self, tmp_path, tmpdir):

def test_errors(self, tmp_path, tmpdir):
ts, zarr_path = tsutil.make_ts_and_zarr(tmp_path)
samples = tsinfer.SgkitSampleData(zarr_path)
samples = tsinfer.VariantData(zarr_path, "variant_ancestral_allele")
tsinfer.generate_ancestors(samples, path=str(tmpdir / "ancestors.zarr"))
metadata = tsinfer.match_ancestors_batch_init(
tmpdir / "work", zarr_path, tmpdir / "ancestors.zarr", 1000
tmpdir / "work",
zarr_path,
"variant_ancestral_allele",
tmpdir / "ancestors.zarr",
1000,
)
with pytest.raises(ValueError, match="out of range"):
tsinfer.match_ancestors_batch_groups(tmpdir / "work", -1, 1)
Expand Down
Loading

0 comments on commit c6a4458

Please sign in to comment.