@@ -1515,6 +1515,26 @@ def test_random_data(self):
1515
1515
ancestor_data = tsinfer .generate_ancestors (sample_data )
1516
1516
self .verify_ancestors (sample_data , ancestor_data )
1517
1517
1518
+ def test_oldest_ancestors (self ):
1519
+ m = 50
1520
+ G , positions = get_random_data_example (20 , m )
1521
+ sample_data = tsinfer .SampleData (sequence_length = m )
1522
+ for genotypes , position in zip (G , positions ):
1523
+ sample_data .add_site (position , genotypes )
1524
+ sample_data .finalise ()
1525
+ ancestor_data = tsinfer .generate_ancestors (sample_data )
1526
+ assert ancestor_data .num_ancestors > 2
1527
+ times = ancestor_data .ancestors_time [:]
1528
+ unique_times = np .unique (times )
1529
+ ultimate_root_time = unique_times [- 1 ]
1530
+ root_time = unique_times [- 2 ]
1531
+ oldest_non_root = unique_times [- 3 ]
1532
+ assert np .sum (times == root_time ) == 1 # root ancestor at unique time
1533
+ assert np .sum (times == ultimate_root_time ) == 1 # ultimate anc at unique time
1534
+ expected_time_diff = oldest_non_root / len (unique_times [:- 2 ])
1535
+ assert np .isclose (ultimate_root_time - root_time , expected_time_diff )
1536
+ assert np .isclose (root_time - oldest_non_root , expected_time_diff )
1537
+
1518
1538
1519
1539
class TestAncestorsTreeSequence :
1520
1540
"""
0 commit comments