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

working towards a slice that will work on intervals #261

Merged
merged 7 commits into from
Aug 13, 2019
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
3 changes: 1 addition & 2 deletions python/tests/test_genotypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,8 @@ def test_jukes_cantor_n20(self):

def test_zero_edge_missing_data(self):
ts = msprime.simulate(10, random_seed=2, mutation_rate=2)
ts = ts.slice(0.25, 0.75, reset_coordinates=False)
tables = ts.tables.keep_intervals([[0.25, 0.75]])
# add some sites in the deleted regions
tables = ts.dump_tables()
tables.sites.add_row(0.1, "A")
tables.sites.add_row(0.2, "A")
tables.sites.add_row(0.8, "A")
Expand Down
35 changes: 34 additions & 1 deletion python/tests/test_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1600,7 +1600,22 @@ def test_asdict(self):
"provenances": t.provenances.asdict()}
d2 = t.asdict()
self.assertEqual(set(d1.keys()), set(d2.keys()))
# TODO test the fromdict constructor

def test_from_dict(self):
ts = msprime.simulate(10, mutation_rate=1, random_seed=1)
t1 = ts.tables
d = {
"sequence_length": t1.sequence_length,
"individuals": t1.individuals.asdict(),
"populations": t1.populations.asdict(),
"nodes": t1.nodes.asdict(),
"edges": t1.edges.asdict(),
"sites": t1.sites.asdict(),
"mutations": t1.mutations.asdict(),
"migrations": t1.migrations.asdict(),
"provenances": t1.provenances.asdict()}
t2 = tskit.TableCollection.fromdict(d)
self.assertEquals(t1, t2)

def test_iter(self):
def test_iter(table_collection):
Expand All @@ -1621,6 +1636,21 @@ def test_equals_sequence_length(self):
tskit.TableCollection(sequence_length=1),
tskit.TableCollection(sequence_length=2))

def test_copy(self):
pop_configs = [msprime.PopulationConfiguration(5) for _ in range(2)]
migration_matrix = [[0, 1], [1, 0]]
t1 = msprime.simulate(
population_configurations=pop_configs,
migration_matrix=migration_matrix,
mutation_rate=1,
record_migrations=True,
random_seed=100).dump_tables()
t2 = t1.copy()
self.assertIsNot(t1, t2)
self.assertEqual(t1, t2)
t1.edges.clear()
self.assertNotEqual(t1, t2)

def test_equals(self):
pop_configs = [msprime.PopulationConfiguration(5) for _ in range(2)]
migration_matrix = [[0, 1], [1, 0]]
Expand All @@ -1637,6 +1667,9 @@ def test_equals(self):
record_migrations=True,
random_seed=1).dump_tables()
self.assertEqual(t1, t1)
self.assertEqual(t1, t1.copy())
self.assertEqual(t1.copy(), t1)

# The provenances may or may not be equal depending on the clock
# precision for record. So clear them first.
t1.provenances.clear()
Expand Down
Loading