From a148af3124c10f7a2fb538cf0354a2644ef77cdd Mon Sep 17 00:00:00 2001 From: Shing Zhan Date: Wed, 13 Sep 2023 12:36:19 +0100 Subject: [PATCH] Fix bug --- python/tests/beagle_numba.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/python/tests/beagle_numba.py b/python/tests/beagle_numba.py index 1f7e40e0b9..4fccaea87c 100644 --- a/python/tests/beagle_numba.py +++ b/python/tests/beagle_numba.py @@ -59,7 +59,7 @@ def get_weights(genotyped_pos, imputed_pos): assert ( imputed_cm[idx_x] != genotyped_cm[idx_m] ), "Genotyped markers and imputed markers overlap." - if imputed_cm[idx_x] < genotyped_cm[idx_m]: + while imputed_cm[idx_x] < genotyped_cm[idx_m] and idx_m > -1: idx_m = max(idx_m - 1, -1) if idx_m == m - 1: # Right of the last genotyped marker @@ -70,10 +70,12 @@ def get_weights(genotyped_pos, imputed_pos): else: # Between two genotyped markers cm_mP1_x = genotyped_cm[idx_m + 1] - imputed_cm[idx_x] + cm_mP1_m = genotyped_cm[idx_m + 1] - genotyped_cm[idx_m] # Set min genetic distance to avoid division by zero. - cm_mP1_m = np.max([genotyped_cm[idx_m + 1] - genotyped_cm[idx_m], 0.005]) + cm_mP1_m = cm_mP1_m if cm_mP1_m > 0.005 else 0.005 weights[idx_x] = cm_mP1_x / cm_mP1_m - assert 0 <= np.min(weights) and np.max(weights) <= 1, "Weights are not in [0, 1]." + assert 0 <= np.min(weights), "Some weights are negative." + assert np.max(weights) <= 1, "Some weights are greater than 1." return weights