How to use the tsinfer.check_ancestors_ts function in tsinfer

To help you get started, we’ve selected a few tsinfer 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 / tsinfer / tests / test_evaluation.py View on Github external
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)
github tskit-dev / tsinfer / tests / test_inference.py View on Github external
A = np.full(
            (ancestor_data.num_sites, ancestor_data.num_ancestors),
            tskit.MISSING_DATA,
            dtype=np.int8,
        )
        start = ancestor_data.ancestors_start[:]
        end = ancestor_data.ancestors_end[:]
        ancestors = ancestor_data.ancestors_haplotype[:]
        for j in range(ancestor_data.num_ancestors):
            A[start[j] : end[j], j] = ancestors[j]
        for engine in [tsinfer.PY_ENGINE, tsinfer.C_ENGINE]:
            ancestors_ts = tsinfer.match_ancestors(
                sample_data, ancestor_data, engine=engine
            )
            tsinfer.check_ancestors_ts(ancestors_ts)
            self.assertEqual(ancestor_data.num_sites, ancestors_ts.num_sites)
            self.assertEqual(ancestor_data.num_ancestors, ancestors_ts.num_samples)
            self.assertTrue(np.array_equal(ancestors_ts.genotype_matrix(), A))
            inferred_ts = tsinfer.match_samples(
                sample_data, ancestors_ts, engine=engine
            )
            self.assertTrue(
                np.array_equal(inferred_ts.genotype_matrix(), ts.genotype_matrix())
            )
github tskit-dev / tsinfer / tests / test_evaluation.py View on Github external
def test_many_mutations(self):
        tables = tskit.TableCollection(1)
        tables.nodes.add_row(time=2, flags=0)
        tables.nodes.add_row(time=1, flags=0)
        tables.edges.add_row(0, 1, 0, 1)
        tables.sites.add_row(position=0.5, ancestral_state="0")
        tables.mutations.add_row(site=0, node=0, derived_state="1")
        tables.mutations.add_row(site=0, node=1, derived_state="0")
        tsinfer.check_ancestors_ts(tables.tree_sequence())
github tskit-dev / tsinfer / tests / test_inference.py View on Github external
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)
github tskit-dev / tsinfer / tests / test_evaluation.py View on Github external
def test_tsinfer_output(self):
        ts = msprime.simulate(10, mutation_rate=1, random_seed=1)
        samples = tsinfer.SampleData.from_tree_sequence(ts)
        ts = tsinfer.infer(samples)
        with self.assertRaises(ValueError):
            tsinfer.check_ancestors_ts(ts)
github tskit-dev / tsinfer / tests / test_evaluation.py View on Github external
def test_zero_edges(self):
        tables = tskit.TableCollection(1)
        tables.nodes.add_row(time=1, flags=0)
        with self.assertRaises(ValueError):
            tsinfer.check_ancestors_ts(tables.tree_sequence())
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 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)