File tree Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Expand file tree Collapse file tree 2 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -142,3 +142,36 @@ def test_scaling(self, Ne):
142
142
dts = tsdate .date (ts , population_size = Ne , mutation_rate = None )
143
143
# Check the date is within 10% of the expected
144
144
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
Original file line number Diff line number Diff line change @@ -1032,11 +1032,16 @@ def date(
1032
1032
# Remove any times associated with mutations
1033
1033
tables .mutations .time = np .full (tree_sequence .num_mutations , tskit .UNKNOWN_TIME )
1034
1034
tables .sort ()
1035
+ population_size_provenance = (
1036
+ population_size .tolist ()
1037
+ if isinstance (population_size , np .ndarray )
1038
+ else population_size
1039
+ )
1035
1040
provenance .record_provenance (
1036
1041
tables ,
1037
1042
"date" ,
1038
1043
mutation_rate = mutation_rate ,
1039
- population_size = population_size ,
1044
+ population_size = population_size_provenance ,
1040
1045
recombination_rate = recombination_rate ,
1041
1046
progress = progress ,
1042
1047
** kwargs ,
You can’t perform that action at this time.
0 commit comments