@@ -2311,16 +2311,29 @@ def test_shapes(self, proportion):
2311
2311
class TestBranchGeneticRelatedness (TestGeneticRelatedness , TopologyExamplesMixin ):
2312
2312
mode = "branch"
2313
2313
2314
- def test_single_sample_set_self_comparison (self ):
2314
+ def test_single_sample_set_self_comparison (self , ts_12_highrecomb_fixture ):
2315
2315
# Test for issue #3055 - self-comparisons with single sample set
2316
- ts = msprime . simulate ( sample_size = 10 , Ne = 10000 , length = 1000 , random_seed = 42 )
2316
+ ts = ts_12_highrecomb_fixture
2317
2317
# Single sample set with self-comparison
2318
2318
result = ts .genetic_relatedness ([[0 ]], indexes = [(0 , 0 )], mode = "branch" )
2319
2319
assert result .shape == (1 ,)
2320
2320
# Should work for multiple samples in single set too
2321
2321
result = ts .genetic_relatedness ([[0 , 1 , 2 ]], indexes = [(0 , 0 )], mode = "branch" )
2322
2322
assert result .shape == (1 ,)
2323
2323
2324
+ def test_single_sample_set_invalid_indexes (self , ts_12_highrecomb_fixture ):
2325
+ # Test that invalid indexes raise ValueError with single sample set
2326
+ ts = ts_12_highrecomb_fixture
2327
+ # Index out of bounds (only have 1 sample set, but trying to access index 1)
2328
+ with pytest .raises (ValueError , match = "Index out of bounds" ):
2329
+ ts .genetic_relatedness ([[0 ]], indexes = [(0 , 1 )], mode = "branch" )
2330
+ # Negative index
2331
+ with pytest .raises (ValueError , match = "Index out of bounds" ):
2332
+ ts .genetic_relatedness ([[0 ]], indexes = [(- 1 , 0 )], mode = "branch" )
2333
+ # Both indexes out of bounds
2334
+ with pytest .raises (ValueError , match = "Index out of bounds" ):
2335
+ ts .genetic_relatedness ([[0 , 1 ]], indexes = [(2 , 2 )], mode = "branch" )
2336
+
2324
2337
@pytest .mark .parametrize ("polarised" , [True , False ])
2325
2338
def test_simple_tree_noncentred (self , polarised ):
2326
2339
# 2.00┊ 4 ┊
@@ -2385,6 +2398,19 @@ def test_single_sample_set_self_comparison(self, ts_12_highrecomb_fixture):
2385
2398
result = ts .genetic_relatedness ([[0 , 1 , 2 ]], indexes = [(0 , 0 )], mode = "node" )
2386
2399
assert result .shape == (ts .num_nodes , 1 )
2387
2400
2401
+ def test_single_sample_set_invalid_indexes (self , ts_12_highrecomb_fixture ):
2402
+ # Test that invalid indexes raise ValueError with single sample set
2403
+ ts = ts_12_highrecomb_fixture
2404
+ # Index out of bounds (only have 1 sample set, but trying to access index 1)
2405
+ with pytest .raises (ValueError , match = "Index out of bounds" ):
2406
+ ts .genetic_relatedness ([[0 ]], indexes = [(0 , 1 )], mode = "node" )
2407
+ # Negative index
2408
+ with pytest .raises (ValueError , match = "Index out of bounds" ):
2409
+ ts .genetic_relatedness ([[0 ]], indexes = [(- 1 , 0 )], mode = "node" )
2410
+ # Both indexes out of bounds
2411
+ with pytest .raises (ValueError , match = "Index out of bounds" ):
2412
+ ts .genetic_relatedness ([[0 , 1 ]], indexes = [(2 , 2 )], mode = "node" )
2413
+
2388
2414
2389
2415
class TestSiteGeneticRelatedness (TestGeneticRelatedness , MutatedTopologyExamplesMixin ):
2390
2416
mode = "site"
@@ -2404,6 +2430,19 @@ def test_single_sample_set_self_comparison(self, ts_12_highrecomb_fixture):
2404
2430
)
2405
2431
assert result .shape == (2 ,)
2406
2432
2433
+ def test_single_sample_set_invalid_indexes (self , ts_12_highrecomb_fixture ):
2434
+ # Test that invalid indexes raise ValueError with single sample set
2435
+ ts = ts_12_highrecomb_fixture
2436
+ # Index out of bounds (only have 1 sample set, but trying to access index 1)
2437
+ with pytest .raises (ValueError , match = "Index out of bounds" ):
2438
+ ts .genetic_relatedness ([[0 ]], indexes = [(0 , 1 )], mode = "site" )
2439
+ # Negative index
2440
+ with pytest .raises (ValueError , match = "Index out of bounds" ):
2441
+ ts .genetic_relatedness ([[0 ]], indexes = [(- 1 , 0 )], mode = "site" )
2442
+ # Both indexes out of bounds
2443
+ with pytest .raises (ValueError , match = "Index out of bounds" ):
2444
+ ts .genetic_relatedness ([[0 , 1 ]], indexes = [(2 , 2 )], mode = "site" )
2445
+
2407
2446
def test_match_K_c0 (self ):
2408
2447
# This test checks that ts.genetic_relatedness() matches K_c0
2409
2448
# from Speed & Balding (2014) https://www.nature.com/articles/nrg3821
0 commit comments