45
45
46
46
np .random .seed (5 )
47
47
48
+ # Notes for refactoring:
49
+ #
50
+ # Things we need to test here are:
51
+ # 1. general_stat: correctly uses summary functions
52
+ # 2. general_stat: branch mode, correctness
53
+ # 3. general_stat: site mode, correctness
54
+ # 4. general_stat: node mode, correctness
55
+ # 5. sample sets: correctness
56
+ # 6. indexes: correctness
57
+ # 7. genome windowing: correctness
58
+ # 8. time windowing: correctness
59
+ # 9. dropping dimensions, output
60
+ # 10. span normalise
61
+ # 11. sample_count_stat: correctly uses summary functions
62
+ # 12. each statistic: a single tree sufficies, with edge cases
63
+ # a. agrees with naive version, polarised and not;
64
+ # b. agrees with python version, polarised and not;
65
+ # c. stat-specific options (eg centre)
48
66
49
67
def cached_np (func ):
50
68
"""
@@ -724,7 +742,9 @@ def ts_10_recomb_fixture():
724
742
@pytest .fixture (scope = "session" )
725
743
def ts_10_mut_fixture ():
726
744
"""10-sample tree sequence with mutations (used 10 times)."""
727
- return msprime .simulate (10 , mutation_rate = 1 , random_seed = 1 )
745
+ ts = msprime .simulate (10 , mutation_rate = 1 , random_seed = 1 )
746
+ assert ts .num_mutations > 0
747
+ return ts
728
748
729
749
730
750
@pytest .fixture (scope = "session" )
@@ -6810,36 +6830,31 @@ class TestOutputDimensions(StatsTestCase):
6810
6830
Tests for the dimension stripping behaviour of the stats functions.
6811
6831
"""
6812
6832
6813
- def get_example_ts (self , ts_10_mut_fixture ):
6814
- ts = ts_10_mut_fixture
6815
- assert ts .num_sites > 1
6816
- return ts
6817
-
6818
6833
def test_one_way_no_window_scalar_stat (self , ts_10_mut_fixture ):
6819
- ts = self . get_example_ts ( ts_10_mut_fixture )
6834
+ ts = ts_10_mut_fixture
6820
6835
x = ts .diversity ()
6821
6836
assert isinstance (x , np .floating )
6822
6837
6823
6838
def test_one_way_one_list_scalar_stat (self , ts_10_mut_fixture ):
6824
- ts = self . get_example_ts ( ts_10_mut_fixture )
6839
+ ts = ts_10_mut_fixture
6825
6840
x = ts .diversity (sample_sets = list (ts .samples ()))
6826
6841
assert isinstance (x , np .floating )
6827
6842
6828
6843
def test_one_way_nested_list_not_scalar_stat (self , ts_10_mut_fixture ):
6829
- ts = self . get_example_ts ( ts_10_mut_fixture )
6844
+ ts = ts_10_mut_fixture
6830
6845
x = ts .diversity (sample_sets = [list (ts .samples ())])
6831
6846
assert x .shape == (1 ,)
6832
6847
6833
6848
def test_one_way_one_window_scalar_stat (self , ts_10_mut_fixture ):
6834
- ts = self . get_example_ts ( ts_10_mut_fixture )
6849
+ ts = ts_10_mut_fixture
6835
6850
x = ts .diversity (windows = [0 , ts .sequence_length ])
6836
6851
assert x .shape == (1 ,)
6837
6852
for samples in (None , list (ts .samples ())):
6838
6853
x = ts .diversity (sample_sets = samples , windows = [0 , ts .sequence_length ])
6839
6854
assert x .shape == (1 ,)
6840
6855
6841
6856
def test_multi_way_no_window_scalar_stat (self , ts_10_mut_fixture ):
6842
- ts = self . get_example_ts ( ts_10_mut_fixture )
6857
+ ts = ts_10_mut_fixture
6843
6858
n = ts .num_samples
6844
6859
x = ts .f2 (
6845
6860
sample_sets = [
@@ -6850,7 +6865,7 @@ def test_multi_way_no_window_scalar_stat(self, ts_10_mut_fixture):
6850
6865
assert isinstance (x , np .floating )
6851
6866
6852
6867
def test_multi_way_one_window_not_scalar_stat (self , ts_10_mut_fixture ):
6853
- ts = self . get_example_ts ( ts_10_mut_fixture )
6868
+ ts = ts_10_mut_fixture
6854
6869
n = ts .num_samples
6855
6870
x = ts .f2 (
6856
6871
sample_sets = [
@@ -6862,7 +6877,7 @@ def test_multi_way_one_window_not_scalar_stat(self, ts_10_mut_fixture):
6862
6877
assert x .shape == (1 ,)
6863
6878
6864
6879
def test_multi_way_no_indexes_scalar_stat (self , ts_10_mut_fixture ):
6865
- ts = self . get_example_ts ( ts_10_mut_fixture )
6880
+ ts = ts_10_mut_fixture
6866
6881
n = ts .num_samples
6867
6882
x = ts .f2 (
6868
6883
sample_sets = [
@@ -6873,7 +6888,7 @@ def test_multi_way_no_indexes_scalar_stat(self, ts_10_mut_fixture):
6873
6888
assert isinstance (x , np .floating )
6874
6889
6875
6890
def test_multi_way_indexes_not_scalar_stat (self , ts_10_mut_fixture ):
6876
- ts = self . get_example_ts ( ts_10_mut_fixture )
6891
+ ts = ts_10_mut_fixture
6877
6892
n = ts .num_samples
6878
6893
x = ts .f2 (
6879
6894
sample_sets = [
@@ -6885,7 +6900,7 @@ def test_multi_way_indexes_not_scalar_stat(self, ts_10_mut_fixture):
6885
6900
assert x .shape == (1 ,)
6886
6901
6887
6902
def test_afs_default_windows (self , ts_10_mut_fixture ):
6888
- ts = self . get_example_ts ( ts_10_mut_fixture )
6903
+ ts = ts_10_mut_fixture
6889
6904
n = ts .num_samples
6890
6905
A = ts .samples ()[:4 ]
6891
6906
B = ts .samples ()[6 :]
@@ -6900,7 +6915,7 @@ def test_afs_default_windows(self, ts_10_mut_fixture):
6900
6915
assert x .shape == (len (A ) + 1 , len (B ) + 1 )
6901
6916
6902
6917
def test_afs_windows (self , ts_10_mut_fixture ):
6903
- ts = self . get_example_ts ( ts_10_mut_fixture )
6918
+ ts = ts_10_mut_fixture
6904
6919
L = ts .sequence_length
6905
6920
6906
6921
windows = [0 , L / 4 , L / 2 , L ]
@@ -6920,7 +6935,7 @@ def test_afs_windows(self, ts_10_mut_fixture):
6920
6935
self .assertArrayEqual (x , y )
6921
6936
6922
6937
def test_one_way_stat_default_windows (self , ts_10_mut_fixture ):
6923
- ts = self . get_example_ts ( ts_10_mut_fixture )
6938
+ ts = ts_10_mut_fixture
6924
6939
# Use diversity as the example one-way stat.
6925
6940
for mode in ["site" , "branch" ]:
6926
6941
x = ts .diversity (mode = mode )
@@ -6989,19 +7004,19 @@ def verify_one_way_stat_windows(self, ts, method):
6989
7004
self .assertArrayEqual (x [0 ], x [2 ])
6990
7005
6991
7006
def test_diversity_windows (self , ts_10_mut_fixture ):
6992
- ts = self . get_example_ts ( ts_10_mut_fixture )
7007
+ ts = ts_10_mut_fixture
6993
7008
self .verify_one_way_stat_windows (ts , ts .diversity )
6994
7009
6995
7010
def test_Tajimas_D_windows (self , ts_10_mut_fixture ):
6996
- ts = self . get_example_ts ( ts_10_mut_fixture )
7011
+ ts = ts_10_mut_fixture
6997
7012
self .verify_one_way_stat_windows (ts , ts .Tajimas_D )
6998
7013
6999
7014
def test_segregating_sites_windows (self , ts_10_mut_fixture ):
7000
- ts = self . get_example_ts ( ts_10_mut_fixture )
7015
+ ts = ts_10_mut_fixture
7001
7016
self .verify_one_way_stat_windows (ts , ts .segregating_sites )
7002
7017
7003
7018
def test_two_way_stat_default_windows (self , ts_10_mut_fixture ):
7004
- ts = self . get_example_ts ( ts_10_mut_fixture )
7019
+ ts = ts_10_mut_fixture
7005
7020
# Use divergence as the example one-way stat.
7006
7021
A = ts .samples ()[:6 ]
7007
7022
B = ts .samples ()[6 :]
@@ -7072,15 +7087,15 @@ def verify_two_way_stat_windows(self, ts, method):
7072
7087
self .assertArrayEqual (x [0 ], x [2 ])
7073
7088
7074
7089
def test_divergence_windows (self , ts_10_mut_fixture ):
7075
- ts = self . get_example_ts ( ts_10_mut_fixture )
7090
+ ts = ts_10_mut_fixture
7076
7091
self .verify_two_way_stat_windows (ts , ts .divergence )
7077
7092
7078
7093
def test_Fst_windows (self , ts_10_mut_fixture ):
7079
- ts = self . get_example_ts ( ts_10_mut_fixture )
7094
+ ts = ts_10_mut_fixture
7080
7095
self .verify_two_way_stat_windows (ts , ts .Fst )
7081
7096
7082
7097
def test_f2_windows (self , ts_10_mut_fixture ):
7083
- ts = self . get_example_ts ( ts_10_mut_fixture )
7098
+ ts = ts_10_mut_fixture
7084
7099
self .verify_two_way_stat_windows (ts , ts .f2 )
7085
7100
7086
7101
def verify_three_way_stat_windows (self , ts , method ):
@@ -7136,11 +7151,11 @@ def verify_three_way_stat_windows(self, ts, method):
7136
7151
self .assertArrayEqual (x [0 ], x [2 ])
7137
7152
7138
7153
def test_Y3_windows (self , ts_10_mut_fixture ):
7139
- ts = self . get_example_ts ( ts_10_mut_fixture )
7154
+ ts = ts_10_mut_fixture
7140
7155
self .verify_three_way_stat_windows (ts , ts .Y3 )
7141
7156
7142
7157
def test_f3_windows (self , ts_10_mut_fixture ):
7143
- ts = self . get_example_ts ( ts_10_mut_fixture )
7158
+ ts = ts_10_mut_fixture
7144
7159
self .verify_three_way_stat_windows (ts , ts .f3 )
7145
7160
7146
7161
0 commit comments