@@ -3725,19 +3725,21 @@ def branch_allele_frequency_spectrum(
3725
3725
tree_index = 0
3726
3726
3727
3727
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
3741
3743
last_update [u ] = right
3742
3744
3743
3745
for (t_left , t_right ), edges_out , edges_in in ts .edge_diffs ():
@@ -3755,12 +3757,12 @@ def update_result(window_index, u, right):
3755
3757
for edge in edges_in :
3756
3758
u = edge .child
3757
3759
v = edge .parent
3758
- parent [u ] = v
3759
3760
# branch_length[u] = time[v] - time[u]
3760
3761
while v != - 1 :
3761
3762
update_result (window_index , v , t_left )
3762
3763
count [v ] += count [u ]
3763
3764
v = parent [v ]
3765
+ parent [u ] = edge .parent
3764
3766
3765
3767
# Update the windows
3766
3768
while window_index < num_windows and windows [window_index + 1 ] <= t_right :
0 commit comments