@@ -2307,32 +2307,49 @@ def test_shapes(self, proportion):
2307
2307
else :
2308
2308
assert x .shape == (2 ,)
2309
2309
2310
-
2311
- class TestBranchGeneticRelatedness (TestGeneticRelatedness , TopologyExamplesMixin ):
2312
- mode = "branch"
2313
-
2314
2310
def test_single_sample_set_self_comparison (self , ts_12_highrecomb_fixture ):
2311
+ if self .mode is None :
2312
+ return
2315
2313
# Test for issue #3055 - self-comparisons with single sample set
2316
2314
ts = ts_12_highrecomb_fixture
2317
2315
# Single sample set with self-comparison
2318
- result = ts .genetic_relatedness ([[0 ]], indexes = [(0 , 0 )], mode = "branch" )
2319
- assert result .shape == (1 ,)
2316
+ result = ts .genetic_relatedness ([[0 ]], indexes = [(0 , 0 )], mode = self .mode )
2317
+ result_shape = (ts .num_nodes , 1 ) if self .mode == "node" else (1 ,)
2318
+ assert result .shape == result_shape
2320
2319
# Should work for multiple samples in single set too
2321
- result = ts .genetic_relatedness ([[0 , 1 , 2 ]], indexes = [(0 , 0 )], mode = "branch" )
2322
- assert result .shape == (1 ,)
2320
+ result = ts .genetic_relatedness ([[0 , 1 , 2 ]], indexes = [(0 , 0 )], mode = self .mode )
2321
+ assert result .shape == result_shape
2322
+ # Test with multiple self-comparisons
2323
+ result = ts .genetic_relatedness (
2324
+ [[0 , 1 ], [2 , 3 ]], indexes = [(0 , 0 ), (1 , 1 )], mode = self .mode
2325
+ )
2326
+ result_shape = (ts .num_nodes , 2 ) if self .mode == "node" else (2 ,)
2327
+ assert result .shape == result_shape
2323
2328
2324
2329
def test_single_sample_set_invalid_indexes (self , ts_12_highrecomb_fixture ):
2330
+ if self .mode is None :
2331
+ return
2325
2332
# Test that invalid indexes raise ValueError with single sample set
2326
2333
ts = ts_12_highrecomb_fixture
2327
2334
# 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" )
2335
+ with pytest .raises (
2336
+ exceptions .LibraryError , match = "TSK_ERR_BAD_SAMPLE_SET_INDEX"
2337
+ ):
2338
+ ts .genetic_relatedness ([[0 ]], indexes = [(0 , 1 )], mode = self .mode )
2330
2339
# Negative index
2331
- with pytest .raises (ValueError , match = "Index out of bounds" ):
2332
- ts .genetic_relatedness ([[0 ]], indexes = [(- 1 , 0 )], mode = "branch" )
2340
+ with pytest .raises (
2341
+ exceptions .LibraryError , match = "TSK_ERR_BAD_SAMPLE_SET_INDEX"
2342
+ ):
2343
+ ts .genetic_relatedness ([[0 ]], indexes = [(- 1 , 0 )], mode = self .mode )
2333
2344
# 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" )
2345
+ with pytest .raises (
2346
+ exceptions .LibraryError , match = "TSK_ERR_BAD_SAMPLE_SET_INDEX"
2347
+ ):
2348
+ ts .genetic_relatedness ([[0 , 1 ]], indexes = [(2 , 2 )], mode = self .mode )
2349
+
2350
+
2351
+ class TestBranchGeneticRelatedness (TestGeneticRelatedness , TopologyExamplesMixin ):
2352
+ mode = "branch"
2336
2353
2337
2354
@pytest .mark .parametrize ("polarised" , [True , False ])
2338
2355
def test_simple_tree_noncentred (self , polarised ):
@@ -2388,61 +2405,10 @@ def test_simple_tree_noncentred(self, polarised):
2388
2405
class TestNodeGeneticRelatedness (TestGeneticRelatedness , TopologyExamplesMixin ):
2389
2406
mode = "node"
2390
2407
2391
- def test_single_sample_set_self_comparison (self , ts_12_highrecomb_fixture ):
2392
- # Test for issue #3055 - self-comparisons with single sample set
2393
- ts = ts_12_highrecomb_fixture
2394
- # Single sample set with self-comparison
2395
- result = ts .genetic_relatedness ([[0 ]], indexes = [(0 , 0 )], mode = "node" )
2396
- assert result .shape == (ts .num_nodes , 1 )
2397
- # Should work for multiple samples in single set too
2398
- result = ts .genetic_relatedness ([[0 , 1 , 2 ]], indexes = [(0 , 0 )], mode = "node" )
2399
- assert result .shape == (ts .num_nodes , 1 )
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
-
2414
2408
2415
2409
class TestSiteGeneticRelatedness (TestGeneticRelatedness , MutatedTopologyExamplesMixin ):
2416
2410
mode = "site"
2417
2411
2418
- def test_single_sample_set_self_comparison (self , ts_12_highrecomb_fixture ):
2419
- # Test for issue #3055 - self-comparisons with single sample set
2420
- ts = ts_12_highrecomb_fixture
2421
- # Single sample set with self-comparison
2422
- result = ts .genetic_relatedness ([[0 ]], indexes = [(0 , 0 )], mode = "site" )
2423
- assert result .shape == (1 ,)
2424
- # Should work for multiple samples in single set too
2425
- result = ts .genetic_relatedness ([[0 , 1 , 2 ]], indexes = [(0 , 0 )], mode = "site" )
2426
- assert result .shape == (1 ,)
2427
- # Test with multiple self-comparisons
2428
- result = ts .genetic_relatedness (
2429
- [[0 ], [1 ]], indexes = [(0 , 0 ), (1 , 1 )], mode = "site"
2430
- )
2431
- assert result .shape == (2 ,)
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
-
2446
2412
def test_match_K_c0 (self ):
2447
2413
# This test checks that ts.genetic_relatedness() matches K_c0
2448
2414
# from Speed & Balding (2014) https://www.nature.com/articles/nrg3821
0 commit comments