Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_bad_genotypes(self):
n = 2
ts = msprime.simulate(n, mutation_rate=5, random_seed=1)
self.assertGreater(ts.num_sites, 1)
with tsinfer.SampleData(sequence_length=ts.sequence_length) as samples:
for var in ts.variants():
samples.add_site(
position=var.site.position, alleles=var.alleles, genotypes=[0, 0]
)
with self.assertRaises(ValueError):
tsinfer.verify(samples, ts)
def test_bad_num_samples(self):
n = 5
ts = msprime.simulate(n, mutation_rate=5, random_seed=1)
self.assertGreater(ts.num_sites, 1)
with tsinfer.SampleData() as samples:
for j in range(ts.num_sites):
samples.add_site(j, genotypes=[0, 1])
with self.assertRaises(ValueError):
tsinfer.verify(samples, ts)
def verify_from_source(self, remove_leaves):
ts = msprime.simulate(15, recombination_rate=1, mutation_rate=2, random_seed=3)
samples = tsinfer.SampleData.from_tree_sequence(ts)
ancestors_ts = tsinfer.make_ancestors_ts(
samples, ts, remove_leaves=remove_leaves
)
tsinfer.check_ancestors_ts(ancestors_ts)
for engine in [tsinfer.PY_ENGINE, tsinfer.C_ENGINE]:
final_ts = tsinfer.match_samples(samples, ancestors_ts, engine=engine)
tsinfer.verify(samples, final_ts)
def test_nominal_case(self):
ts = msprime.simulate(10, mutation_rate=5, random_seed=1)
self.assertGreater(ts.num_sites, 0)
samples = tsinfer.SampleData.from_tree_sequence(ts)
inferred_ts = tsinfer.infer(samples)
tsinfer.verify(samples, inferred_ts)
tsinfer.verify(samples, ts)
def verify_from_inferred(self, remove_leaves):
ts = msprime.simulate(15, recombination_rate=1, mutation_rate=2, random_seed=3)
samples = tsinfer.SampleData.from_tree_sequence(ts)
inferred = tsinfer.infer(samples)
ancestors_ts = tsinfer.make_ancestors_ts(
samples, inferred, remove_leaves=remove_leaves
)
tsinfer.check_ancestors_ts(ancestors_ts)
for engine in [tsinfer.PY_ENGINE, tsinfer.C_ENGINE]:
final_ts = tsinfer.match_samples(samples, ancestors_ts, engine=engine)
tsinfer.verify(samples, final_ts)
def verify(self, samples):
ts = tsinfer.infer(samples, simplify=False)
ancestors_ts_1 = self.insert_srb_ancestors(samples, ts)
ancestors_ts_2 = tsinfer.insert_srb_ancestors(samples, ts)
t1 = ancestors_ts_1.dump_tables()
t2 = ancestors_ts_2.dump_tables()
t1.provenances.clear()
t2.provenances.clear()
self.assertEqual(t1, t2)
tsinfer.check_ancestors_ts(ancestors_ts_1)
ts2 = tsinfer.match_samples(samples, ancestors_ts_1)
tsinfer.verify(samples, ts2)
def test_bad_num_sites(self):
n = 2
ts = msprime.simulate(n, mutation_rate=5, random_seed=1)
self.assertGreater(ts.num_sites, 1)
with tsinfer.SampleData() as samples:
samples.add_site(0, genotypes=[0, 1])
with self.assertRaises(ValueError):
tsinfer.verify(samples, ts)
# print("edges before = ", simplified.num_edges)
# new_ancestors_ts = insert_srb_ancestors(ts)
# ts = tsinfer.match_samples(samples, new_ancestors_ts,
# path_compression=False, engine=engine,
# simplify=True)
# for tree in ts.trees():
# print(tree.interval)
# print(tree.draw(format="unicode"))
# print(ts.tables.edges)
# for tree in ts.trees():
# print(tree.draw(format="unicode"))
tsinfer.verify(samples, ts)