@@ -667,24 +667,11 @@ def test_short_sequence_length(self):
667
667
self .verify (ts )
668
668
669
669
@pytest .mark .slow
670
- def test_wright_fisher_unsimplified (self , wf_sim_fixture ):
671
- self .verify (wf_sim_fixture [ "unsimplified" ] )
670
+ def test_wright_fisher_slow (self , wf_fixture_slow ):
671
+ self .verify (wf_fixture_slow )
672
672
673
- @pytest .mark .slow
674
- def test_wright_fisher_initial_generation (self , wf_sim_fixture ):
675
- self .verify (wf_sim_fixture ["initial_generation" ])
676
-
677
- def test_wright_fisher_initial_generation_no_deep_history (self , wf_sim_fixture ):
678
- self .verify (wf_sim_fixture ["no_deep_history" ])
679
-
680
- def test_wright_fisher_unsimplified_multiple_roots (self , wf_sim_fixture ):
681
- self .verify (wf_sim_fixture ["unsimplified_multi_roots" ])
682
-
683
- def test_wright_fisher_simplified (self , wf_sim_fixture ):
684
- self .verify (wf_sim_fixture ["simplified" ])
685
-
686
- def test_wright_fisher_simplified_multiple_roots (self , wf_sim_fixture ):
687
- self .verify (wf_sim_fixture ["simplified_multi_roots" ])
673
+ def test_wright_fisher (self , wf_fixture ):
674
+ self .verify (wf_fixture )
688
675
689
676
def test_empty_ts (self ):
690
677
tables = tskit .TableCollection (1.0 )
@@ -782,7 +769,7 @@ def _make_ts(length):
782
769
783
770
# Wright-Fisher simulation fixtures
784
771
@pytest .fixture (scope = "session" )
785
- def wf_sim_fixture ():
772
+ def wf_fixture_sims ():
786
773
"""Common Wright-Fisher simulations used across test classes."""
787
774
# Pre-compute all common WF simulations
788
775
simulations = {}
@@ -829,51 +816,37 @@ def wf_sim_fixture():
829
816
return simulations
830
817
831
818
832
- @pytest .fixture (scope = "session" )
833
- def wf_mut_sim_fixture ():
834
- """Wright-Fisher simulations with mutations for MutatedTopologyExamplesMixin."""
835
- simulations = {}
836
-
837
- # With mutations for site-based tests
838
- tables = wf .wf_sim (
839
- 4 , 5 , seed = 1 , deep_history = True , initial_generation_samples = False , num_loci = 10
840
- )
841
- tables .sort ()
842
- ts = msprime .mutate (tables .tree_sequence (), rate = 0.05 , random_seed = 234 )
843
- simulations ["unsimplified" ] = ts
844
-
845
- tables = wf .wf_sim (
846
- 6 , 5 , seed = 3 , deep_history = True , initial_generation_samples = True , num_loci = 2
847
- )
848
- tables .sort ()
849
- tables .simplify ()
850
- ts = msprime .mutate (tables .tree_sequence (), rate = 0.08 , random_seed = 2 )
851
- simulations ["initial_generation" ] = ts
852
-
853
- tables = wf .wf_sim (
854
- 7 , 15 , seed = 202 , deep_history = False , initial_generation_samples = True , num_loci = 5
819
+ @pytest .fixture (
820
+ params = [
821
+ "no_deep_history" ,
822
+ "unsimplified_multi_roots" ,
823
+ "simplified" ,
824
+ "simplified_multi_roots" ,
825
+ ],
826
+ scope = "session" ,
827
+ )
828
+ def wf_fixture (wf_fixture_sims , request ):
829
+ """
830
+ A collection of small Wright-Fisher simulations.
831
+ """
832
+ ts = msprime .sim_mutations (
833
+ wf_fixture_sims [request .param ], rate = 0.05 , random_seed = 1234
855
834
)
856
- tables .sort ()
857
- tables .simplify ()
858
- ts = msprime .mutate (tables .tree_sequence (), rate = 0.1 , random_seed = 3 )
859
- simulations ["no_deep_history" ] = ts
835
+ assert ts .num_mutations > 0
836
+ return ts
860
837
861
- tables = wf .wf_sim (
862
- 8 , 15 , seed = 1 , deep_history = False , initial_generation_samples = False , num_loci = 20
863
- )
864
- tables .sort ()
865
- ts = msprime .mutate (tables .tree_sequence (), rate = 0.01 , random_seed = 2 )
866
- simulations ["unsimplified_multi_roots" ] = ts
867
838
868
- tables = wf .wf_sim (
869
- 9 , 10 , seed = 1 , deep_history = True , initial_generation_samples = False , num_loci = 5
839
+ @pytest .fixture (params = ["unsimplified" , "initial_generation" ], scope = "session" )
840
+ def wf_fixture_slow (wf_fixture_sims , request ):
841
+ """
842
+ A few more small Wright-Fisher simulations. Despite the name, in total
843
+ they take about the same time for tests together as wf_fixture.
844
+ """
845
+ ts = msprime .sim_mutations (
846
+ wf_fixture_sims [request .param ], rate = 0.05 , random_seed = 1234
870
847
)
871
- tables .sort ()
872
- ts = tables .tree_sequence ().simplify ()
873
- ts = tsutil .jukes_cantor (ts , 10 , 0.01 , seed = 1 )
874
- simulations ["simplified" ] = ts
875
-
876
- return simulations
848
+ assert ts .num_mutations > 0
849
+ return ts
877
850
878
851
879
852
@pytest .fixture (scope = "session" )
@@ -1133,28 +1106,13 @@ def test_many_trees_sequence_length_infinite_sites(
1133
1106
ts = ts_6_length_factory_fixture (L )
1134
1107
self .verify (ts )
1135
1108
1136
- def test_wright_fisher_unsimplified (self , wf_mut_sim_fixture ):
1137
- ts = wf_mut_sim_fixture [ "unsimplified" ]
1109
+ def test_wright_fisher (self , wf_fixture ):
1110
+ ts = wf_fixture
1138
1111
assert ts .num_sites > 0
1139
1112
self .verify (ts )
1140
1113
1141
- def test_wright_fisher_initial_generation (self , wf_mut_sim_fixture ):
1142
- ts = wf_mut_sim_fixture ["initial_generation" ]
1143
- assert ts .num_sites > 0
1144
- self .verify (ts )
1145
-
1146
- def test_wright_fisher_initial_generation_no_deep_history (self , wf_mut_sim_fixture ):
1147
- ts = wf_mut_sim_fixture ["no_deep_history" ]
1148
- assert ts .num_sites > 0
1149
- self .verify (ts )
1150
-
1151
- def test_wright_fisher_unsimplified_multiple_roots (self , wf_mut_sim_fixture ):
1152
- ts = wf_mut_sim_fixture ["unsimplified_multi_roots" ]
1153
- assert ts .num_sites > 0
1154
- self .verify (ts )
1155
-
1156
- def test_wright_fisher_simplified (self , wf_mut_sim_fixture ):
1157
- ts = wf_mut_sim_fixture ["simplified" ]
1114
+ def test_wright_fisher_slow (self , wf_fixture_slow ):
1115
+ ts = wf_fixture_slow
1158
1116
assert ts .num_sites > 0
1159
1117
self .verify (ts )
1160
1118
@@ -4310,13 +4268,14 @@ def update_result(window_index, u, right):
4310
4268
4311
4269
4312
4270
def site_allele_frequency_spectrum (
4313
- ts , sample_sets , windows , polarised = False , span_normalise = True
4271
+ ts , sample_sets , windows , time_windows = None , polarised = False , span_normalise = True
4314
4272
):
4315
4273
"""
4316
4274
Efficient implementation of the algorithm used as the basis for the
4317
4275
underlying C version.
4318
4276
"""
4319
4277
windows = ts .parse_windows (windows )
4278
+ assert time_windows is None
4320
4279
num_windows = windows .shape [0 ] - 1
4321
4280
out_dim = [1 + len (sample_set ) for sample_set in sample_sets ]
4322
4281
@@ -4622,8 +4581,7 @@ class TestSampleSets(StatsTestCase):
4622
4581
Tests that passing sample sets in various ways gets interpreted correctly.
4623
4582
"""
4624
4583
4625
- def get_example_ts (self , ts_10_mut_recomb_fixture ):
4626
- ts = ts_10_mut_recomb_fixture
4584
+ def get_example_ts (self , ts ):
4627
4585
assert ts .num_mutations > 0
4628
4586
return ts
4629
4587
@@ -7288,18 +7246,18 @@ def f(x):
7288
7246
x = naive_branch_general_stat (
7289
7247
ts , W , f , time_windows = [0 , 0.5 , 2.0 ], span_normalise = False
7290
7248
)
7291
- self . assertArrayAlmostEqual (x , true_x )
7249
+ np . testing . assert_allclose (x , true_x )
7292
7250
7293
7251
x0 = branch_general_stat (ts , W , f , time_windows = None , span_normalise = False )
7294
7252
x1 = naive_branch_general_stat (
7295
7253
ts , W , f , time_windows = None , span_normalise = False
7296
7254
)
7297
- self . assertArrayAlmostEqual (x0 , x1 )
7255
+ np . testing . assert_allclose (x0 , x1 )
7298
7256
x_tw = branch_general_stat (
7299
7257
ts , W , f , time_windows = [0 , 0.5 , 2.0 ], span_normalise = False
7300
7258
)
7301
7259
7302
- self . assertArrayAlmostEqual (x , x_tw )
7260
+ np . testing . assert_allclose (x , x_tw )
7303
7261
7304
7262
def test_bad_time_windows (self , four_taxa_test_case ):
7305
7263
ts = four_taxa_test_case
@@ -7372,58 +7330,8 @@ def test_drop_dimension(self, four_taxa_test_case, mode):
7372
7330
7373
7331
def test_four_taxon_example (self , four_taxa_test_case_afs ):
7374
7332
ts , examples = four_taxa_test_case_afs
7375
- for k , (params , afs ) in enumerate (examples ):
7376
- print (k )
7333
+ for params , afs in examples :
7377
7334
ts_afs = ts .allele_frequency_spectrum (** params )
7378
7335
py_afs = allele_frequency_spectrum (ts , ** params )
7379
7336
np .testing .assert_allclose (afs , ts_afs )
7380
7337
np .testing .assert_allclose (afs , py_afs )
7381
-
7382
- def test_decap_vs_tw (self ):
7383
- ns = 2
7384
- time_grid = np .append (np .logspace (2 , 5 , 11 ), np .inf )[0 :1 ]
7385
- ts = msprime .sim_ancestry (
7386
- ns ,
7387
- recombination_rate = 1e-8 ,
7388
- sequence_length = 1e6 ,
7389
- population_size = 1e4 ,
7390
- random_seed = 1 ,
7391
- )
7392
- ts = msprime .sim_mutations (ts , rate = 1e-8 , random_seed = 2 )
7393
- sample_sets = [np .arange (ns ), np .arange (ns , 2 * ns )]
7394
-
7395
- time_grid = np .append (0 , time_grid )
7396
- time_grid = np .append (time_grid , np .inf )
7397
-
7398
- windows = np .array ([0 , 0.5 , 1 ]) * ts .sequence_length
7399
- windows = None
7400
- test1 = ts .allele_frequency_spectrum (
7401
- sample_sets = sample_sets ,
7402
- time_windows = time_grid ,
7403
- mode = "branch" ,
7404
- polarised = True ,
7405
- span_normalise = True ,
7406
- windows = windows ,
7407
- ).cumsum (axis = 0 )
7408
-
7409
- test2 = branch_allele_frequency_spectrum (
7410
- ts ,
7411
- windows = windows ,
7412
- sample_sets = sample_sets ,
7413
- time_windows = time_grid ,
7414
- polarised = True ,
7415
- span_normalise = True ,
7416
- ).cumsum (axis = 0 )
7417
-
7418
- # manually calculate twAFS
7419
- twafs0 = np .zeros ((time_grid .size , ns + 1 , ns + 1 ))
7420
- for i , t in enumerate (time_grid ):
7421
- tsd = ts .decapitate (t ) if t < np .inf else ts
7422
- twafs0 [i ] = tsd .allele_frequency_spectrum (
7423
- sample_sets = sample_sets ,
7424
- mode = "branch" ,
7425
- polarised = True ,
7426
- span_normalise = True ,
7427
- ).squeeze ()
7428
- self .assertArrayAlmostEqual (test1 , test2 )
7429
- self .assertArrayAlmostEqual (test2 , twafs0 [1 :])
0 commit comments