Skip to content

Commit d21807b

Browse files
committed
feat: add 'lower triangle' annotation option to plot_pairwise_average_fst (#820)
1 parent af991c9 commit d21807b

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

malariagen_data/anoph/fst.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ def plot_pairwise_average_fst(
530530

531531
# Set up plot title.
532532
title = "<i>F</i><sub>ST</sub>"
533-
if annotation is not None:
533+
if annotation is not None and annotation != "lower triangle":
534534
title += " ⧅ " + annotation
535535

536536
# Fill the figure dataframe from the Fst dataframe.
@@ -543,12 +543,15 @@ def plot_pairwise_average_fst(
543543
fig_df.loc[cohort1, cohort2] = np.nan
544544
else:
545545
fig_df.loc[cohort1, cohort2] = fst / se
546+
elif annotation == "lower triangle":
547+
# Leave the upper triangle as NaN (empty).
548+
pass
546549
else:
547550
fig_df.loc[cohort1, cohort2] = fst
548551

549552
# Don't colour the plot if the upper triangle is SE or Z score,
550553
# as the colouring doesn't really make sense.
551-
if annotation is not None and zmax is None:
554+
if annotation is not None and annotation != "lower triangle" and zmax is None:
552555
zmax = 1e9
553556

554557
# Dynamically size the figure based on number of cohorts.

malariagen_data/anoph/fst_params.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@
3535
]
3636

3737
annotation: TypeAlias = Annotated[
38-
Optional[Literal["standard error", "Z score"]],
38+
Optional[Literal["standard error", "Z score", "lower triangle"]],
3939
"""
40-
How to annotate the upper-right corner of the plot. Default behaviour (None) is using Fst, other options
41-
are using the standard error (if annotation is 'standard error') or the Z score of the two
42-
cohorts being the same (if annotation is 'Z score').
40+
How to annotate the upper-right corner of the plot. Default behaviour (None)
41+
is using Fst, other options are using the standard error (if annotation is
42+
'standard error'), the Z score of the two cohorts being the same (if
43+
annotation is 'Z score'), or leaving the upper triangle empty (if annotation
44+
is 'lower triangle').
4345
""",
4446
]

tests/anoph/test_fst.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ def check_pairwise_average_fst(api: AnophelesFstAnalysis, fst_params):
236236
assert isinstance(fig, go.Figure)
237237
fig = api.plot_pairwise_average_fst(fst_df, annotation="Z score", show=False)
238238
assert isinstance(fig, go.Figure)
239+
fig = api.plot_pairwise_average_fst(
240+
fst_df, annotation="lower triangle", show=False
241+
)
242+
assert isinstance(fig, go.Figure)
239243

240244

241245
@pytest.mark.parametrize("cohorts", ["country", "admin1_year", "cohort_admin2_month"])

0 commit comments

Comments
 (0)