Skip to content

Commit

Permalink
Remove minimum denominator for weight calculations
Browse files Browse the repository at this point in the history
  • Loading branch information
szhan committed Dec 18, 2023
1 parent 3c6a546 commit 017edd2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
5 changes: 2 additions & 3 deletions python/tests/beagle.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ def get_weights(genotyped_pos, ungenotyped_pos, genetic_map=None):
m = len(genotyped_pos)
x = len(ungenotyped_pos)
assert len(np.union1d(genotyped_pos, ungenotyped_pos)) == m + x
# Set min genetic distance.
MIN_CM_DIST = 0.005
if genetic_map is None:
genotyped_cm = convert_to_genetic_map_position(genotyped_pos)
ungenotyped_cm = convert_to_genetic_map_position(ungenotyped_pos)
Expand All @@ -105,7 +103,8 @@ def get_weights(genotyped_pos, ungenotyped_pos, genetic_map=None):
# Ungenotyped marker is between genotyped markers k and k + 1.
k = np.max(np.where(ungenotyped_pos[i] > genotyped_pos)[0]) # Inefficient
cm_mP1_x = genotyped_cm[k + 1] - ungenotyped_cm[i]
cm_mP1_m = np.max([genotyped_cm[k + 1] - genotyped_cm[k], MIN_CM_DIST])
cm_mP1_m = genotyped_cm[k + 1] - genotyped_cm[k]
assert cm_mP1_m > 0, "Division by zero in weight calculation."
weights[i] = cm_mP1_x / cm_mP1_m
marker_interval_start[i] = k
assert 0 <= np.min(weights)
Expand Down
5 changes: 1 addition & 4 deletions python/tests/beagle_numba.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def get_weights(genotyped_pos, ungenotyped_pos, genotyped_cm, ungenotyped_cm):
:return: Weights and marker interval start indices.
:rtype: tuple(numpy.ndarray, numpy.ndarray)
"""
_MIN_CM = 0.005
m = len(genotyped_pos)
x = len(ungenotyped_pos)
# Calculate weights for ungenotyped markers.
Expand All @@ -67,9 +66,7 @@ def get_weights(genotyped_pos, ungenotyped_pos, genotyped_cm, ungenotyped_cm):
else:
# Between two genotyped markers.
cm_mP1_x = genotyped_cm[idx_m + 1] - ungenotyped_cm[idx_x]
cm_mP1_m = max(
genotyped_cm[idx_m + 1] - genotyped_cm[idx_m], _MIN_CM
) # Set min.
cm_mP1_m = genotyped_cm[idx_m + 1] - genotyped_cm[idx_m]
weights[idx_x] = cm_mP1_x / cm_mP1_m
marker_interval_start[idx_x] = idx_m
return (weights, marker_interval_start)
Expand Down

0 comments on commit 017edd2

Please sign in to comment.