Skip to content

Commit 8545ce1

Browse files
authored
Merge pull request #969 from AswaniSahoo/feat/fst-lower-triangle-820
feat: add "lower triangle" annotation option to plot_pairwise_average_fst (#820)
2 parents 7b9fcaf + 2c01634 commit 8545ce1

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
@@ -536,7 +536,7 @@ def plot_pairwise_average_fst(
536536

537537
# Set up plot title.
538538
title = "<i>F</i><sub>ST</sub>"
539-
if annotation is not None:
539+
if annotation is not None and annotation != "lower triangle":
540540
title += " ⧅ " + annotation
541541

542542
# Fill the figure dataframe from the Fst dataframe.
@@ -549,12 +549,15 @@ def plot_pairwise_average_fst(
549549
fig_df.loc[cohort1, cohort2] = np.nan
550550
else:
551551
fig_df.loc[cohort1, cohort2] = fst / se
552+
elif annotation == "lower triangle":
553+
# Leave the upper triangle as NaN (empty).
554+
pass
552555
else:
553556
fig_df.loc[cohort1, cohort2] = fst
554557

555558
# Don't colour the plot if the upper triangle is SE or Z score,
556559
# as the colouring doesn't really make sense.
557-
if annotation is not None and zmax is None:
560+
if annotation is not None and annotation != "lower triangle" and zmax is None:
558561
zmax = 1e9
559562

560563
# 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
@@ -257,6 +257,10 @@ def check_pairwise_average_fst(api: AnophelesFstAnalysis, fst_params):
257257
assert isinstance(fig, go.Figure)
258258
fig = api.plot_pairwise_average_fst(fst_df, annotation="Z score", show=False)
259259
assert isinstance(fig, go.Figure)
260+
fig = api.plot_pairwise_average_fst(
261+
fst_df, annotation="lower triangle", show=False
262+
)
263+
assert isinstance(fig, go.Figure)
260264

261265

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

0 commit comments

Comments
 (0)