Skip to content

Commit 1d8e33c

Browse files
committed
fix: document metric parameter and add unique/absolute test coverage
1 parent ead68bd commit 1d8e33c

2 files changed

Lines changed: 34 additions & 14 deletions

File tree

malariagen_data/anoph/hapclust.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,6 +881,14 @@ def _compute_haplotype_sharing(
881881
summary="""
882882
Plot an arc diagram showing haplotype sharing between cohorts.
883883
""",
884+
parameters=dict(
885+
metric="""
886+
The metric to use for measuring haplotype sharing. If 'unique'
887+
(default), counts the number of highly identical distinct shared
888+
haplotypes. If 'absolute', counts the absolute number of original
889+
haplotypes shared between the cohorts.
890+
""",
891+
),
884892
)
885893
def plot_haplotype_sharing_arc(
886894
self,
@@ -1018,6 +1026,14 @@ def plot_haplotype_sharing_arc(
10181026
summary="""
10191027
Plot a chord diagram showing haplotype sharing between cohorts.
10201028
""",
1029+
parameters=dict(
1030+
metric="""
1031+
The metric to use for measuring haplotype sharing. If 'unique'
1032+
(default), counts the number of highly identical distinct shared
1033+
haplotypes. If 'absolute', counts the absolute number of original
1034+
haplotypes shared between the cohorts.
1035+
""",
1036+
),
10211037
)
10221038
def plot_haplotype_sharing_chord(
10231039
self,

tests/anoph/test_hapclust.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,26 @@ def test_plot_haplotype_clustering(fixture, api: AnophelesHapClustAnalysis):
101101
@parametrize_with_cases("fixture,api", cases=".")
102102
def test_plot_haplotype_sharing_arc(fixture, api: AnophelesHapClustAnalysis):
103103
all_sample_sets = api.sample_sets()["sample_set"].to_list()
104-
fig = api.plot_haplotype_sharing_arc(
105-
region=fixture.random_region_str(region_size=5000),
106-
cohort_col="country",
107-
sample_sets=[random.choice(all_sample_sets)],
108-
show=False,
109-
)
110-
assert fig is not None
104+
for metric in ["unique", "absolute"]:
105+
fig = api.plot_haplotype_sharing_arc(
106+
region=fixture.random_region_str(region_size=5000),
107+
cohort_col="country",
108+
sample_sets=[random.choice(all_sample_sets)],
109+
metric=metric,
110+
show=False,
111+
)
112+
assert fig is not None
111113

112114

113115
@parametrize_with_cases("fixture,api", cases=".")
114116
def test_plot_haplotype_sharing_chord(fixture, api: AnophelesHapClustAnalysis):
115117
all_sample_sets = api.sample_sets()["sample_set"].to_list()
116-
fig = api.plot_haplotype_sharing_chord(
117-
region=fixture.random_region_str(region_size=5000),
118-
cohort_col="country",
119-
sample_sets=[random.choice(all_sample_sets)],
120-
show=False,
121-
)
122-
assert fig is not None
118+
for metric in ["unique", "absolute"]:
119+
fig = api.plot_haplotype_sharing_chord(
120+
region=fixture.random_region_str(region_size=5000),
121+
cohort_col="country",
122+
sample_sets=[random.choice(all_sample_sets)],
123+
metric=metric,
124+
show=False,
125+
)
126+
assert fig is not None

0 commit comments

Comments
 (0)