Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VariantData #944

Merged
merged 1 commit into from
Jul 26, 2024
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
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
Loading