Skip to content

Commit 9c7232d

Browse files
committed
Add accuracy test
1 parent dc2d3e0 commit 9c7232d

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

tests/test_accuracy.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,36 @@ def test_scaling(self, Ne):
142142
dts = tsdate.date(ts, population_size=Ne, mutation_rate=None)
143143
# Check the date is within 10% of the expected
144144
assert 0.9 < dts.node(dts.first().root).time / (2 * Ne) < 1.1
145+
146+
@pytest.mark.parametrize(
147+
"bkwd_rate, trio_tmrca",
148+
[ # calculated from simulations
149+
(-1.0, 0.76),
150+
(-0.9, 0.79),
151+
(-0.8, 0.82),
152+
(-0.7, 0.85),
153+
(-0.6, 0.89),
154+
(-0.5, 0.94),
155+
(-0.4, 0.99),
156+
(-0.3, 1.05),
157+
(-0.2, 1.12),
158+
(-0.1, 1.21),
159+
(0.0, 1.32),
160+
],
161+
)
162+
def test_piecewise_scaling(self, bkwd_rate, trio_tmrca):
163+
"""
164+
Test that we are in the right theoretical ballpark given known Ne,
165+
under exponential growth.
166+
167+
Check coalescence time of a trio instead of a pair, because of
168+
https://github.com/tskit-dev/tsdate/issues/230
169+
"""
170+
time = np.linspace(0, 10, 100)
171+
ne = 0.5 * np.exp(bkwd_rate * time)
172+
ts = tskit.Tree.generate_comb(3).tree_sequence
173+
dts = tsdate.date(
174+
ts, population_size=np.column_stack([time, ne]), mutation_rate=None
175+
)
176+
# Check the date is within 10% of the expected
177+
assert 0.9 < dts.node(dts.first().root).time / trio_tmrca < 1.1

tsdate/core.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,11 +1032,16 @@ def date(
10321032
# Remove any times associated with mutations
10331033
tables.mutations.time = np.full(tree_sequence.num_mutations, tskit.UNKNOWN_TIME)
10341034
tables.sort()
1035+
population_size_provenance = (
1036+
population_size.tolist()
1037+
if isinstance(population_size, np.ndarray)
1038+
else population_size
1039+
)
10351040
provenance.record_provenance(
10361041
tables,
10371042
"date",
10381043
mutation_rate=mutation_rate,
1039-
population_size=population_size,
1044+
population_size=population_size_provenance,
10401045
recombination_rate=recombination_rate,
10411046
progress=progress,
10421047
**kwargs,

0 commit comments

Comments
 (0)