Skip to content

Commit 7e973e5

Browse files
committed
Add taxon, area params to plot_frequencies_time_series()
1 parent 33b8535 commit 7e973e5

File tree

3 files changed

+52
-14
lines changed

3 files changed

+52
-14
lines changed

malariagen_data/anoph/plotly_params.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,13 @@
215215
],
216216
"Scope of the map.",
217217
]
218+
219+
taxon: TypeAlias = Annotated[
220+
Optional[str],
221+
"The taxon to restrict the dataset to.",
222+
]
223+
224+
area: TypeAlias = Annotated[
225+
Optional[str],
226+
"The area to restrict the dataset to.",
227+
]

malariagen_data/anoph/snp_frq.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,8 @@ def plot_frequencies_time_series(
936936
legend_sizing: plotly_params.legend_sizing = "constant",
937937
show: plotly_params.show = True,
938938
renderer: plotly_params.renderer = None,
939+
taxon: plotly_params.taxon = None,
940+
area: plotly_params.area = None,
939941
**kwargs,
940942
) -> plotly_params.figure:
941943
# Handle title.
@@ -947,6 +949,14 @@ def plot_frequencies_time_series(
947949
df_cohorts = ds[cohort_vars].to_dataframe()
948950
df_cohorts.columns = [c.split("cohort_")[1] for c in df_cohorts.columns] # type: ignore
949951

952+
# If specified, restrict the dataframe by taxon.
953+
if taxon:
954+
df_cohorts = df_cohorts[df_cohorts["taxon"] == taxon]
955+
956+
# If specified, restrict the dataframe by area.
957+
if area:
958+
df_cohorts = df_cohorts[df_cohorts["area"] == area]
959+
950960
# Extract variant labels.
951961
variant_labels = ds["variant_label"].values
952962

notebooks/plot_frequencies_space_time.ipynb

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "47f669f3",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"import malariagen_data"
11+
]
12+
},
313
{
414
"cell_type": "code",
515
"execution_count": null,
616
"id": "f820bc66-2fb2-4ca2-9b54-824e50d61a0a",
717
"metadata": {},
818
"outputs": [],
919
"source": [
10-
"import malariagen_data\n",
11-
"\n",
1220
"ag3 = malariagen_data.Ag3(\n",
1321
" \"simplecache::gs://vo_agam_release_master_us_central1\",\n",
1422
" simplecache=dict(cache_storage=\"../gcs_cache\"),\n",
@@ -23,8 +31,6 @@
2331
"metadata": {},
2432
"outputs": [],
2533
"source": [
26-
"import malariagen_data\n",
27-
"\n",
2834
"af1 = malariagen_data.Af1(\n",
2935
" \"simplecache::gs://vo_afun_release_master_us_central1\",\n",
3036
" simplecache=dict(cache_storage=\"../gcs_cache\"),\n",
@@ -69,6 +75,16 @@
6975
"ag3.plot_frequencies_time_series(ds, height=500, width=1000)"
7076
]
7177
},
78+
{
79+
"cell_type": "code",
80+
"execution_count": null,
81+
"id": "790c99e8",
82+
"metadata": {},
83+
"outputs": [],
84+
"source": [
85+
"ag3.plot_frequencies_time_series(ds, taxon=\"gambiae\", height=500, width=1000)"
86+
]
87+
},
7288
{
7389
"cell_type": "code",
7490
"execution_count": null,
@@ -252,6 +268,16 @@
252268
"ag3.plot_frequencies_time_series(ds, height=900, width=900)"
253269
]
254270
},
271+
{
272+
"cell_type": "code",
273+
"execution_count": null,
274+
"id": "e16ab3fe",
275+
"metadata": {},
276+
"outputs": [],
277+
"source": [
278+
"ag3.plot_frequencies_time_series(ds, area=\"BF-09\", height=400, width=900)"
279+
]
280+
},
255281
{
256282
"cell_type": "code",
257283
"execution_count": null,
@@ -336,19 +362,11 @@
336362
"source": [
337363
"af1.plot_frequencies_interactive_map(ds)"
338364
]
339-
},
340-
{
341-
"cell_type": "code",
342-
"execution_count": null,
343-
"id": "a512b459",
344-
"metadata": {},
345-
"outputs": [],
346-
"source": []
347365
}
348366
],
349367
"metadata": {
350368
"kernelspec": {
351-
"display_name": "Python 3 (ipykernel)",
369+
"display_name": "mgen_data_py3.11",
352370
"language": "python",
353371
"name": "python3"
354372
},
@@ -362,7 +380,7 @@
362380
"name": "python",
363381
"nbconvert_exporter": "python",
364382
"pygments_lexer": "ipython3",
365-
"version": "3.10.12"
383+
"version": "3.11.5"
366384
},
367385
"widgets": {
368386
"application/vnd.jupyter.widget-state+json": {

0 commit comments

Comments
 (0)