Skip to content

Commit f7f679a

Browse files
committed
fix AFS tests
1 parent 6d73824 commit f7f679a

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

python/tests/test_tree_stats.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3725,19 +3725,21 @@ def branch_allele_frequency_spectrum(
37253725
tree_index = 0
37263726

37273727
def update_result(window_index, u, right):
3728-
for k_tw, _ in enumerate(time_windows[:-1]):
3729-
if 0 < count[u, -1] < ts.num_samples:
3730-
# t_v = branch_length[u] + time[u]
3731-
t_v = time[parent[u]]
3732-
tw_branch_length = min(time_windows[k_tw + 1], t_v) - max(
3733-
time_windows[0], time[u]
3734-
)
3735-
x = (right - last_update[u]) * tw_branch_length
3736-
c = count[u, :num_sample_sets]
3737-
if not polarised:
3738-
c = fold(c, out_dim)
3739-
index = tuple([window_index] + [k_tw] + list(c))
3740-
result[index] += x
3728+
if parent[u] != -1:
3729+
for k_tw, _ in enumerate(time_windows[:-1]):
3730+
if 0 < count[u, -1] < ts.num_samples:
3731+
# t_v = branch_length[u] + time[u]
3732+
assert parent[u] != -1
3733+
t_v = time[parent[u]]
3734+
tw_branch_length = min(time_windows[k_tw + 1], t_v) - max(
3735+
time_windows[0], time[u]
3736+
)
3737+
x = (right - last_update[u]) * tw_branch_length
3738+
c = count[u, :num_sample_sets]
3739+
if not polarised:
3740+
c = fold(c, out_dim)
3741+
index = tuple([window_index] + [k_tw] + list(c))
3742+
result[index] += x
37413743
last_update[u] = right
37423744

37433745
for (t_left, t_right), edges_out, edges_in in ts.edge_diffs():
@@ -3755,12 +3757,12 @@ def update_result(window_index, u, right):
37553757
for edge in edges_in:
37563758
u = edge.child
37573759
v = edge.parent
3758-
parent[u] = v
37593760
# branch_length[u] = time[v] - time[u]
37603761
while v != -1:
37613762
update_result(window_index, v, t_left)
37623763
count[v] += count[u]
37633764
v = parent[v]
3765+
parent[u] = edge.parent
37643766

37653767
# Update the windows
37663768
while window_index < num_windows and windows[window_index + 1] <= t_right:

0 commit comments

Comments
 (0)