How to use the tskit.TableCollection function in tskit

To help you get started, we’ve selected a few tskit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tskit-dev / msprime / tskit_tests / test_tables.py View on Github external
def test_empty_tables(self):
        tables = tskit.TableCollection(1)
        tables.sort()
        self.assertEqual(tables.nodes.num_rows, 0)
        self.assertEqual(tables.edges.num_rows, 0)
        self.assertEqual(tables.sites.num_rows, 0)
        self.assertEqual(tables.mutations.num_rows, 0)
        self.assertEqual(tables.migrations.num_rows, 0)
github tskit-dev / msprime / tskit_tests / test_metadata.py View on Github external
def test_nodes(self):
        tables = tskit.TableCollection(sequence_length=1)
        metadata = ExampleMetadata(one="node1", two="node2")
        pickled = pickle.dumps(metadata)
        tables.nodes.add_row(time=0.125, metadata=pickled)
        ts = tables.tree_sequence()
        node = ts.node(0)
        self.assertEqual(node.time, 0.125)
        self.assertEqual(node.metadata, pickled)
        unpickled = pickle.loads(node.metadata)
        self.assertEqual(unpickled.one, metadata.one)
        self.assertEqual(unpickled.two, metadata.two)
github tskit-dev / msprime / tests / test_likelihood.py View on Github external
def test_gap_in_ancestral_material(self):
        tables = tskit.TableCollection(sequence_length=1)
        tables.nodes.add_row(flags=tskit.NODE_IS_SAMPLE, population=0,
                             individual=-1, time=0)
        tables.nodes.add_row(flags=tskit.NODE_IS_SAMPLE, population=0,
                             individual=-1, time=0)

        tables.edges.add_row(left=0, right=0.3, parent=2, child=0)
        tables.edges.add_row(left=0.3, right=1, parent=3, child=0)
        tables.nodes.add_row(flags=msprime.NODE_IS_RE_EVENT, population=0,
                             individual=-1, time=0.1)
        tables.nodes.add_row(flags=msprime.NODE_IS_RE_EVENT, population=0,
                             individual=-1, time=0.1)

        tables.edges.add_row(left=0.3, right=0.5, parent=4, child=3)
        tables.edges.add_row(left=0.5, right=1, parent=5, child=3)
        tables.nodes.add_row(flags=msprime.NODE_IS_RE_EVENT, population=0,
                             individual=-1, time=0.2)
github tskit-dev / msprime / tskit_tests / test_file_format.py View on Github external
def test_empty_file(self):
        tables = tskit.TableCollection(sequence_length=3)
        self.verify_round_trip(tables.tree_sequence(), 10)
github tskit-dev / msprime / tests / wright_fisher.py View on Github external
def run(self, ngens):
        L = 1
        if self.num_loci is not None:
            L = self.num_loci
        tables = tskit.TableCollection(sequence_length=L)
        tables.populations.add_row()
        if self.deep_history:
            # initial population
            init_ts = msprime.simulate(
                self.N, recombination_rate=1.0, length=L, random_seed=self.seed)
            init_tables = init_ts.dump_tables()
            flags = init_tables.nodes.flags
            if not self.initial_generation_samples:
                flags = np.zeros_like(init_tables.nodes.flags)
            tables.nodes.set_columns(
                time=init_tables.nodes.time + ngens,
                flags=flags)
            tables.edges.set_columns(
                left=init_tables.edges.left, right=init_tables.edges.right,
                parent=init_tables.edges.parent, child=init_tables.edges.child)
        else:
github tskit-dev / msprime / tskit_tests / test_tables.py View on Github external
def test_sequence_length(self):
        for sequence_length in [0, 1, 100.1234]:
            tables = tskit.TableCollection(sequence_length=sequence_length)
            self.assertEqual(tables.sequence_length, sequence_length)
github tskit-dev / tsinfer / tests / test_evaluation.py View on Github external
def test_empty(self):
        tables = tskit.TableCollection(1)
        tsinfer.check_ancestors_ts(tables.tree_sequence())
github tskit-dev / tsinfer / tests / test_evaluation.py View on Github external
def test_zero_has_no_children(self):
        tables = tskit.TableCollection(1)
        tables.nodes.add_row(time=1, flags=0)
        tables.nodes.add_row(time=2, flags=0)
        tables.nodes.add_row(time=3, flags=0)
        tables.edges.add_row(0, 1, 2, 1)
        with self.assertRaises(ValueError):
            tsinfer.check_ancestors_ts(tables.tree_sequence())
github tskit-dev / msprime / tskit_tests / test_file_format.py View on Github external
def test_zero_edges(self):
        tables = tskit.TableCollection(sequence_length=3)
        tables.nodes.add_row(time=0)
        self.verify_round_trip(tables.tree_sequence(), 10)
github molpopgen / fwdpy11 / fwdpy11 / _tables_to_tskit.py View on Github external
def dump_tables_to_tskit(pop):
    """
    Converts fwdpy11.TableCollection to an
    tskit.TreeSequence
    """
    node_view = np.array(pop.tables.nodes, copy=True)
    node_view['time'] -= node_view['time'].max()
    node_view['time'][np.where(node_view['time'] != 0.0)[0]] *= -1.0
    edge_view = np.array(pop.tables.edges, copy=False)
    mut_view = np.array(pop.tables.mutations, copy=False)

    tc = tskit.TableCollection(pop.tables.genome_length)

    # We must initialize population and individual
    # tables before we can do anything else.
    # Attempting to set population to anything
    # other than -1 in an tskit.NodeTable will
    # raise an exception if the PopulationTable
    # isn't set up.
    _initializePopulationTable(node_view, tc)
    node_to_individual = _initializeIndividualTable(pop, tc)

    individual = [-1 for i in range(len(node_view))]
    for k, v in node_to_individual.items():
        individual[k] = v
    flags = [1]*2*pop.N + [0]*(len(node_view) - 2*pop.N)
    # Bug fixed in 0.3.1: add preserved nodes to samples list
    for i in pop.tables.preserved_nodes: