Skip to content

Commit 42fc048

Browse files
committed
fix(fst): avoid infinite Z-scores when standard error is zero
Prevent division by zero from producing infinite values in Fst heatmaps. Return NaN when SE is zero to avoid misleading visualization. Refs #947
1 parent 6d711b7 commit 42fc048

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

malariagen_data/anoph/fst.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -539,11 +539,10 @@ def plot_pairwise_average_fst(
539539
if annotation == "standard error":
540540
fig_df.loc[cohort1, cohort2] = se
541541
elif annotation == "Z score":
542-
try:
543-
zs = fst / se
544-
fig_df.loc[cohort1, cohort2] = zs
545-
except ZeroDivisionError:
542+
if se == 0:
546543
fig_df.loc[cohort1, cohort2] = np.nan
544+
else:
545+
fig_df.loc[cohort1, cohort2] = fst / se
547546
else:
548547
fig_df.loc[cohort1, cohort2] = fst
549548

0 commit comments

Comments
 (0)