Skip to content

Commit

Permalink
Rename variables
Browse files Browse the repository at this point in the history
  • Loading branch information
szhan committed Jan 14, 2024
1 parent 8de5b05 commit d04a3b8
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions python/tests/beagle_numba.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def convert_to_genetic_map_positions(pos, genetic_map=None):


@njit
def get_weights(genotyped_pos, ungenotyped_pos, genotyped_cm, ungenotyped_cm):
def get_weights(typed_pos, untyped_pos, typed_cm, untyped_cm):
"""
Get weights for ungenotyped markers in the query haplotype, which are used in
linear interpolation of HMM state probabilities at the ungenotyped markers.
Expand All @@ -93,8 +93,8 @@ def get_weights(genotyped_pos, ungenotyped_pos, genotyped_cm, ungenotyped_cm):
:rtype: tuple(numpy.ndarray, numpy.ndarray)
"""
MIN_CM_DIST = 1e-7 # Avoid division by zero.
m = len(genotyped_pos)
x = len(ungenotyped_pos)
m = len(typed_pos)
x = len(untyped_pos)
# Calculate weights for ungenotyped markers.
weights = np.zeros(x, dtype=np.float32)
# Identify genotype markers m and m+1 bounding ungenotyped marker i.
Expand All @@ -103,19 +103,19 @@ def get_weights(genotyped_pos, ungenotyped_pos, genotyped_cm, ungenotyped_cm):
# TODO: Refactor using np.searchsorted().
idx_m = m - 1
for idx_x in range(x - 1, -1, -1):
while idx_m > 0 and ungenotyped_pos[idx_x] < genotyped_pos[idx_m]:
while idx_m > 0 and untyped_pos[idx_x] < typed_pos[idx_m]:
idx_m = max(idx_m - 1, 0)
if idx_m == m - 1:
# Right of the last genotyped marker.
weights[idx_x] = 0.0
elif idx_m == 0 and ungenotyped_pos[idx_x] < genotyped_pos[idx_m]:
elif idx_m == 0 and untyped_pos[idx_x] < typed_pos[idx_m]:
# Left of the first genotyped marker.
weights[idx_x] = 1.0
else:
# Between two genotyped markers.
cm_mP1_x = genotyped_cm[idx_m + 1] - ungenotyped_cm[idx_x]
cm_mP1_x = typed_cm[idx_m + 1] - untyped_cm[idx_x]
# TODO: Check if this a subtle source of numerical error.
cm_mP1_m = max(genotyped_cm[idx_m + 1] - genotyped_cm[idx_m], MIN_CM_DIST)
cm_mP1_m = max(typed_cm[idx_m + 1] - typed_cm[idx_m], MIN_CM_DIST)
weights[idx_x] = cm_mP1_x / cm_mP1_m
left_idx[idx_x] = idx_m
return (weights, left_idx)
Expand Down

0 comments on commit d04a3b8

Please sign in to comment.