Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
szhan committed Sep 13, 2023
1 parent 11c285a commit a148af3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions python/tests/beagle_numba.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down

0 comments on commit a148af3

Please sign in to comment.