@@ -277,6 +277,7 @@ def norm_hap_weighted_ij(
277
277
wAB_i = hap_weights [0 , i ]
278
278
wAB_j = hap_weights [0 , j ]
279
279
result [k ] = (wAB_i + wAB_j ) / (ni + nj )
280
+ # result[k] = (wAB_i / ni / 2) + (wAB_j / nj / 2)
280
281
281
282
282
283
def norm_total_weighted (
@@ -1034,26 +1035,26 @@ def r2_ij_summary_func(
1034
1035
for k in range (result_dim ):
1035
1036
i = set_indexes [k ][0 ]
1036
1037
j = set_indexes [k ][1 ]
1037
- ni = sample_set_sizes [i ]
1038
- w_AB_i = state [0 , i ]
1039
- w_Ab_i = state [1 , i ]
1040
- w_aB_i = state [2 , i ]
1041
- w_A_i = w_AB_i + w_Ab_i
1042
- w_B_i = w_AB_i + w_aB_i
1043
- D_i = (ni * w_AB_i - (w_A_i * w_B_i )) / (ni * ni )
1038
+ n = sample_set_sizes [i ]
1039
+ pAB = state [0 , i ] / n
1040
+ pAb = state [1 , i ] / n
1041
+ paB = state [2 , i ] / n
1042
+ pA = pAB + pAb
1043
+ pB = pAB + paB
1044
+ D_i = pAB - pA * pB
1045
+ denom_i = np .sqrt (pA * (1 - pA ) * pB * (1 - pB ))
1046
+
1047
+ n = sample_set_sizes [j ]
1048
+ pAB = state [0 , j ] / n
1049
+ pAb = state [1 , j ] / n
1050
+ paB = state [2 , j ] / n
1051
+ pA = pAB + pAb
1052
+ pB = pAB + paB
1053
+ D_j = pAB - pA * pB
1054
+ denom_j = np .sqrt (pA * (1 - pA ) * pB * (1 - pB ))
1044
1055
1045
- nj = sample_set_sizes [j ]
1046
- w_AB_j = state [0 , j ]
1047
- w_Ab_j = state [1 , j ]
1048
- w_aB_j = state [2 , j ]
1049
- w_A_j = w_AB_j + w_Ab_j
1050
- w_B_j = w_AB_j + w_aB_j
1051
- D_j = (nj * w_AB_j - (w_A_j * w_B_j )) / (nj * nj )
1052
-
1053
- p_A = (w_A_i + w_A_j ) / (ni + nj )
1054
- p_B = (w_B_i + w_B_j ) / (ni + nj )
1055
1056
with suppress_overflow_div0_warning ():
1056
- result [k ] = (D_i * D_j ) / (p_A * ( 1 - p_A ) * p_B * ( 1 - p_B ) )
1057
+ result [k ] = (D_i * D_j ) / (denom_i * denom_j )
1057
1058
1058
1059
1059
1060
def D_summary_func (
@@ -2317,12 +2318,12 @@ def test_two_way_site_ld_matrix(ts, stat):
2317
2318
(
2318
2319
correlated ,
2319
2320
(np .array ([0 , 1 , 2 , 3 , 4 , 5 ]), np .array ([6 , 7 , 8 , 9 , 10 ])),
2320
- np .float64 (0.9708352229780801 ),
2321
+ np .float64 (1.0 ),
2321
2322
),
2322
2323
(
2323
2324
correlated ,
2324
2325
(np .array ([0 , 1 , 2 , 3 , 4 , 5 ]), np .array ([6 , 7 , 8 , 9 ])),
2325
- np .float64 (0.9526958931720837 ),
2326
+ np .float64 (1.0 ),
2326
2327
),
2327
2328
(
2328
2329
correlated ,
@@ -2332,12 +2333,12 @@ def test_two_way_site_ld_matrix(ts, stat):
2332
2333
(
2333
2334
correlated ,
2334
2335
(np .array ([0 , 1 , 2 , 3 , 4 , 5 ]), np .array ([6 , 7 ])),
2335
- np .float64 (0.7585185185185186 ),
2336
+ np .float64 (np . nan ),
2336
2337
),
2337
2338
(
2338
2339
correlated ,
2339
2340
(np .array ([0 , 1 , 2 , 3 , 4 , 5 ]), np .array ([6 ])),
2340
- np .float64 (0.0 ),
2341
+ np .float64 (np . nan ),
2341
2342
),
2342
2343
(
2343
2344
anticorrelated := np .array (
@@ -2355,37 +2356,37 @@ def test_two_way_site_ld_matrix(ts, stat):
2355
2356
(
2356
2357
anticorrelated ,
2357
2358
(np .array ([0 , 2 , 4 , 6 , 8 , 10 , 12 , 14 ]), np .array ([1 , 3 , 5 , 7 , 9 , 11 , 13 ])),
2358
- np .float64 (0.9798566895766568 ),
2359
+ np .float64 (1.0 ),
2359
2360
),
2360
2361
(
2361
2362
anticorrelated ,
2362
2363
(np .array ([0 , 2 , 4 , 6 , 8 , 10 , 12 , 14 ]), np .array ([1 , 3 , 5 , 7 , 9 , 11 ])),
2363
- np .float64 (0.8574999999999999 ),
2364
+ np .float64 (np . nan ),
2364
2365
),
2365
2366
(
2366
2367
anticorrelated ,
2367
2368
(np .array ([0 , 2 , 4 , 6 , 8 , 10 , 12 , 14 ]), np .array ([1 , 3 , 5 , 7 , 9 ])),
2368
- np .float64 (0.8299777777777777 ),
2369
+ np .float64 (np . nan ),
2369
2370
),
2370
2371
(
2371
2372
anticorrelated ,
2372
2373
(np .array ([0 , 2 , 4 , 6 , 8 , 10 , 12 , 14 ]), np .array ([1 , 3 , 5 , 7 ])),
2373
- np .float64 (0.6328124999999999 ),
2374
+ np .float64 (np . nan ),
2374
2375
),
2375
2376
(
2376
2377
anticorrelated ,
2377
2378
(np .array ([0 , 2 , 4 , 6 , 8 , 10 , 12 , 14 ]), np .array ([1 , 3 , 5 ])),
2378
- np .float64 (0.57179616638322 ),
2379
+ np .float64 (np . nan ),
2379
2380
),
2380
2381
(
2381
2382
anticorrelated ,
2382
2383
(np .array ([0 , 2 , 4 , 6 , 8 , 10 , 12 , 14 ]), np .array ([1 , 3 ])),
2383
- np .float64 (0.0 ),
2384
+ np .float64 (np . nan ),
2384
2385
),
2385
2386
(
2386
2387
anticorrelated ,
2387
2388
(np .array ([0 , 2 , 4 , 6 , 8 , 10 , 12 , 14 ]), np .array ([1 ])),
2388
- np .float64 (0.0 ),
2389
+ np .float64 (np . nan ),
2389
2390
),
2390
2391
],
2391
2392
)
@@ -2404,4 +2405,4 @@ def test_multipopulation_r2_varying_unequal_set_sizes(genotypes, sample_sets, ex
2404
2405
r2_ij_summary_func (state_dim , state , 1 , result [i , j ], params )
2405
2406
norm_hap_weighted_ij (1 , state , max (a ) + 1 , max (b ) + 1 , norm [i , j ], params )
2406
2407
2407
- np .testing .assert_allclose (expected , (result * norm ).sum ())
2408
+ np .testing .assert_allclose ((result * norm ).sum (), expected )
0 commit comments