def verify_dump_equality(self, ts): """ Verifies that we can dump a copy of the specified tree sequence to the specified file, and load an identical copy. """ ts.dump(self.temp_file) ts2 = _tskit.TreeSequence() ts2.load(self.temp_file) self.assertEqual(ts.get_num_samples(), ts2.get_num_samples()) self.assertEqual(ts.get_sequence_length(), ts2.get_sequence_length()) self.assertEqual(ts.get_num_mutations(), ts2.get_num_mutations()) self.assertEqual(ts.get_num_nodes(), ts2.get_num_nodes()) records1 = [ts.get_edge(j) for j in range(ts.get_num_edges())] records2 = [ts2.get_edge(j) for j in range(ts2.get_num_edges())] self.assertEqual(records1, records2) mutations1 = [ ts.get_mutation(j) for j in range(ts.get_num_mutations()) ] mutations2 = [ ts2.get_mutation(j) for j in range(ts2.get_num_mutations()) ] self.assertEqual(mutations1, mutations2) provenances1 = [ ts.get_provenance(j) for j in range(ts.get_num_provenances()) ] provenances2 = [ ts2.get_provenance(j) for j in range(ts2.get_num_provenances()) ] self.assertEqual(provenances1, provenances2)
def f(mutations): position = [] node = [] site = [] ancestral_state = [] ancestral_state_offset = [0] derived_state = [] derived_state_offset = [0] for j, (p, n) in enumerate(mutations): site.append(j) position.append(p) ancestral_state.append("0") ancestral_state_offset.append(ancestral_state_offset[-1] + 1) derived_state.append("1") derived_state_offset.append(derived_state_offset[-1] + 1) node.append(n) tables.sites.set_columns( dict(position=position, ancestral_state=ancestral_state, ancestral_state_offset=ancestral_state_offset, metadata=None, metadata_offset=None)) tables.mutations.set_columns( dict(site=site, node=node, derived_state=derived_state, derived_state_offset=derived_state_offset, parent=None, metadata=None, metadata_offset=None)) ts2 = _tskit.TreeSequence() ts2.load_tables(tables)
def test_initial_state(self): # Check the initial state to make sure that it is empty. ts = _tskit.TreeSequence() self.assertRaises(ValueError, ts.get_num_samples) self.assertRaises(ValueError, ts.get_sequence_length) self.assertRaises(ValueError, ts.get_num_trees) self.assertRaises(ValueError, ts.get_num_edges) self.assertRaises(ValueError, ts.get_num_mutations) self.assertRaises(ValueError, ts.get_num_migrations) self.assertRaises(ValueError, ts.get_num_migrations) self.assertRaises(ValueError, ts.get_genotype_matrix) self.assertRaises(ValueError, ts.dump)
def test_uninitialised_tree_sequence(self): ts = _tskit.TreeSequence() self.assertRaises(ValueError, _tskit.LdCalculator, ts)
def test_uninitialised_tree_sequence(self): ts = _tskit.TreeSequence() self.assertRaises(ValueError, _tskit.HaplotypeGenerator, ts)
def test_uninitialised_tree_sequence(self): ts = _tskit.TreeSequence() self.assertRaises(ValueError, _tskit.VcfConverter, ts)
def loader(*args): ts2 = _tskit.TreeSequence() ts2.load(*args)