Skip to content

Commit 2604b2e

Browse files
committed
Progress on haplotype frequencies
1 parent c8c4218 commit 2604b2e

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

malariagen_data/anoph/hap_frq.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def haplotypes_frequencies(
120120
df_haps_sorted["label"] = ["H" + str(i) for i in range(len(df_haps_sorted))]
121121

122122
# Reset index after filtering.
123-
df_haps_sorted.set_index(keys="label", drop=True)
123+
df_haps_sorted.set_index(keys="label", drop=True, inplace=True)
124124

125125
return df_haps_sorted
126126

tests/anoph/test_frq.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ def test_plot_frequencies_heatmap(api, frq_df):
1515

1616
# Test index parameter - if None, should use dataframe index.
1717
fig = api.plot_frequencies_heatmap(frq_df, show=False, index=None, max_len=None)
18-
# Not unique.
19-
with pytest.raises(ValueError):
20-
api.plot_frequencies_heatmap(frq_df, show=False, index="contig", max_len=None)
18+
19+
if "contig" in list(frq_df.columns):
20+
# Not unique.
21+
with pytest.raises(ValueError):
22+
api.plot_frequencies_heatmap(
23+
frq_df, show=False, index="contig", max_len=None
24+
)
2125

2226

2327
@pytest.mark.skip

tests/anoph/test_hap_frq.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88

99
from malariagen_data import ag3 as _ag3
1010
from malariagen_data.anoph.hap_frq import AnophelesHapFrequencyAnalysis
11+
from .test_frq import (
12+
test_plot_frequencies_heatmap,
13+
test_plot_frequencies_time_series,
14+
test_plot_frequencies_time_series_with_taxa,
15+
test_plot_frequencies_time_series_with_areas,
16+
)
1117

1218

1319
@pytest.fixture
@@ -70,9 +76,8 @@ def check_hap_frequencies(*, api, df, sample_sets, cohorts, min_cohort_size):
7076
cohort_counts = df_samples[cohort_column].value_counts()
7177
cohort_labels = cohort_counts[cohort_counts >= min_cohort_size].index.to_list()
7278

73-
universal_fields = ["label"]
7479
frq_fields = ["frq_" + s for s in cohort_labels] + ["max_af"]
75-
expected_fields = universal_fields + frq_fields
80+
expected_fields = frq_fields
7681
assert sorted(df.columns.tolist()) == sorted(expected_fields)
7782

7883

@@ -82,9 +87,9 @@ def check_hap_frequencies_advanced(
8287
ds,
8388
):
8489
assert isinstance(ds, xr.Dataset)
85-
# test_plot_frequencies_time_series(api, ds)
86-
# test_plot_frequencies_time_series_with_taxa(api, ds)
87-
# test_plot_frequencies_time_series_with_areas(api, ds)
90+
test_plot_frequencies_time_series(api, ds)
91+
test_plot_frequencies_time_series_with_taxa(api, ds)
92+
test_plot_frequencies_time_series_with_areas(api, ds)
8893
# test_plot_frequencies_interactive_map(api, ds)
8994
assert set(ds.dims) == {"cohorts", "variants"}
9095

@@ -158,7 +163,7 @@ def test_hap_frequencies_with_str_cohorts(
158163
# Run the function under test.
159164
df_hap = api.haplotypes_frequencies(**params)
160165

161-
# test_plot_frequencies_heatmap(api, df_hap)
166+
test_plot_frequencies_heatmap(api, df_hap)
162167

163168
# Standard checks.
164169
check_hap_frequencies(

0 commit comments

Comments
 (0)