Skip to content

Commit

Permalink
Merge pull request #261 from andrewkern/interval_slice
Browse files Browse the repository at this point in the history
working towards a slice that will work on intervals
  • Loading branch information
jeromekelleher authored Aug 13, 2019
2 parents f676cd9 + e0b85c9 commit be86a85
Show file tree
Hide file tree
Showing 8 changed files with 639 additions and 292 deletions.
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

0 comments on commit be86a85

Please sign in to comment.