Skip to content

Commit d05b851

Browse files
Victor Krim-Yeemergify[bot]
authored andcommitted
Added tests for the distribution of nodes and edges in tree sequences with or without record_unary=True.
The tests are grouped under the class UnaryRecordTest and have a similar format to ArgRecordTest. The expected results are that the distribution of nodes and edges is the same after simplifying unary nodes as it is when simulating without record_unary enabled.
1 parent d91bfc5 commit d05b851

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

verification.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3521,6 +3521,66 @@ def test_arg_dirac_n100_rho_2(self):
35213521
self._run(sample_size=100, recombination_rate=2, model=model)
35223522

35233523

3524+
class UnaryRecordTest(Test):
3525+
"""
3526+
Check that we get the same distributions of nodes and edges when
3527+
we simplify a graph with unary nodes as we get in a direct simulation.
3528+
"""
3529+
3530+
def _run(self, num_replicates=1000, **kwargs):
3531+
ts_node_counts = np.array([])
3532+
unary_node_counts = np.array([])
3533+
ts_tree_counts = np.array([])
3534+
unary_tree_counts = np.array([])
3535+
ts_edge_counts = np.array([])
3536+
unary_edge_counts = np.array([])
3537+
for ts in msprime.sim_ancestry(num_replicates=num_replicates, **kwargs):
3538+
ts_node_counts = np.append(ts_node_counts, ts.num_nodes)
3539+
ts_tree_counts = np.append(ts_tree_counts, ts.num_trees)
3540+
ts_edge_counts = np.append(ts_edge_counts, ts.num_edges)
3541+
3542+
reps = msprime.sim_ancestry(
3543+
num_replicates=num_replicates, record_unary=True, **kwargs
3544+
)
3545+
for unary_ts in reps:
3546+
unary_ts = unary_ts.simplify()
3547+
unary_node_counts = np.append(unary_node_counts, unary_ts.num_nodes)
3548+
unary_tree_counts = np.append(unary_tree_counts, unary_ts.num_trees)
3549+
unary_edge_counts = np.append(unary_edge_counts, unary_ts.num_edges)
3550+
3551+
pp_ts = sm.ProbPlot(ts_node_counts)
3552+
pp_arg = sm.ProbPlot(unary_node_counts)
3553+
sm.qqplot_2samples(pp_ts, pp_arg, line="45")
3554+
pyplot.savefig(self.output_dir / "nodes.png", dpi=72)
3555+
3556+
pp_ts = sm.ProbPlot(ts_tree_counts)
3557+
pp_arg = sm.ProbPlot(unary_tree_counts)
3558+
sm.qqplot_2samples(pp_ts, pp_arg, line="45")
3559+
pyplot.savefig(self.output_dir / "num_trees.png", dpi=72)
3560+
3561+
pp_ts = sm.ProbPlot(ts_edge_counts)
3562+
pp_arg = sm.ProbPlot(unary_edge_counts)
3563+
sm.qqplot_2samples(pp_ts, pp_arg, line="45")
3564+
pyplot.savefig(self.output_dir / "edges.png", dpi=72)
3565+
pyplot.close("all")
3566+
3567+
def test_unary_continuous_n10_rho_20(self):
3568+
self._run(
3569+
samples=10, recombination_rate=20, discrete_genome=False, sequence_length=1
3570+
)
3571+
3572+
def test_unary_hudson_n1000_rho_0_002(self):
3573+
self._run(samples=1000, recombination_rate=0.002, sequence_length=100)
3574+
3575+
def test_unary_beta_n100_rho_0_002(self):
3576+
model = msprime.BetaCoalescent(alpha=1.1)
3577+
self._run(samples=2, recombination_rate=0.002, model=model, sequence_length=100)
3578+
3579+
def test_unary_dirac_n100_rho_0_002(self):
3580+
model = msprime.DiracCoalescent(psi=0.9, c=1)
3581+
self._run(samples=10, recombination_rate=0.2, model=model, sequence_length=100)
3582+
3583+
35243584
class HudsonAnalytical(Test):
35253585
"""
35263586
Miscellaneous tests for the hudson model where we verify against

0 commit comments

Comments
 (0)