Skip to content

Commit ff5c5c8

Browse files
committed
add subset and button generation
1 parent 21496b4 commit ff5c5c8

File tree

4 files changed

+46
-25
lines changed

4 files changed

+46
-25
lines changed

dgea/dgea_scvi.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ def dgea_ui():
2020
def dgea_server(input, output, session, _adata: reactive.Value[ad.AnnData], _model: reactive.Value[str]):
2121
_counts = reactive.value(None)
2222
_uniques = reactive.value([])
23+
_sub_uniques = reactive.value([])
2324

2425
_contrast = reactive.value(None)
2526
_reference = reactive.value(None)
2627
_alternative = reactive.value(None)
28+
_sub_category = reactive.value(None)
29+
_chosen_values = reactive.value([])
2730
_log10_p = reactive.value(0.05)
2831
_lfc = reactive.value(1)
2932

@@ -32,9 +35,9 @@ def dgea_server(input, output, session, _adata: reactive.Value[ad.AnnData], _mod
3235
_filtered_genes = reactive.value(None)
3336
_filtered_counts = reactive.value(None)
3437

35-
run_dgea_server("run_dgea", _adata, _result, _counts, _reference, _alternative, _model, _uniques, _contrast)
38+
run_dgea_server("run_dgea", _adata, _result, _counts, _reference, _alternative, _model, _uniques, _contrast, _sub_category, _chosen_values, _sub_uniques)
3639
filter_dgea_server("filter_dgea", _adata, _counts, _uniques,
3740
_result, _filtered_result, _filtered_genes,
38-
_filtered_counts, _reference, _alternative, _contrast, _model, _log10_p, _lfc)
41+
_filtered_counts, _reference, _alternative, _contrast, _sub_category, _sub_uniques, _chosen_values, _model, _log10_p, _lfc)
3942
plot_dgea_server("plot_dgea", _filtered_counts, _contrast, _reference, _alternative,
4043
_result, _log10_p, _lfc)

dgea/filter_dgea_scvi.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
@module.ui
77
def filter_dgea_ui():
88
return ui.div(
9+
ui.output_ui("select_values"),
910
ui.output_ui("select_reference"),
1011
ui.output_ui("select_alternative"),
1112
ui.input_slider("log10_pscore", "Ropability in Reference (significance threshold)", min=0, max=20, step=0.01, value=3),
@@ -17,10 +18,17 @@ def filter_dgea_ui():
1718
def filter_dgea_server(input, output, session,
1819
_adata, _counts, _uniques,
1920
_result, _filtered_result, _filtered_genes, _filtered_counts,
20-
_reference, _alternative, _contrast, _model,
21+
_reference, _alternative, _contrast, _sub_category, _sub_uniques, _chosen_values, _model,
2122
_log10_p, _lfc
2223
):
2324

25+
@output
26+
@render.ui
27+
def select_values():
28+
sub_uniques = _sub_uniques.get()
29+
30+
return ui.input_select("value", "Choose values:", choices=sub_uniques, selectize=True, multiple=True, selected=sub_uniques)
31+
2432
@output
2533
@render.ui
2634
def select_reference():
@@ -46,27 +54,12 @@ def select_alternative():
4654

4755
@reactive.effect
4856
def update_filters():
57+
_chosen_values.set(input["value"].get())
4958
_reference.set(input["reference"].get())
5059
_alternative.set(input["alternative"].get())
5160
_log10_p.set(input["log10_pscore"].get())
5261
_lfc.set(input["lfc"].get())
5362

54-
@reactive.effect
55-
def update_result():
56-
adata = _adata.get()
57-
reference = _reference.get()
58-
alternative = _alternative.get()
59-
contrast = _contrast.get()
60-
model = _model.get()
61-
62-
if None in (reference, alternative, contrast):
63-
return
64-
65-
res_df = scanvi_dgea(adata, contrast, reference, alternative, model)
66-
res_counts = get_normalized_counts(adata)
67-
_result.set(res_df)
68-
_counts.set(res_counts)
69-
7063
@reactive.effect
7164
def filter_result():
7265
result = _result.get()

dgea/plot_dgea_scvi.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ def plot_dgea_server(input, output, session,
3838
@render.plot
3939
def plot_heatmap():
4040
counts_df = _filtered_counts.get()
41-
contrast = _contrast.get()
42-
reference = _reference.get()
43-
alternative = _alternative.get()
4441

4542
if counts_df is None:
4643
return None

dgea/run_dgea_scvi.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
@module.ui
99
def run_dgea_ui():
1010
return ui.div(ui.output_ui("contrast_selector"),
11-
ui.input_task_button("run", "Run analysis"))
11+
ui.output_ui("subset_selector"),
12+
ui.input_task_button("run", "Run analysis"))
1213

1314
@module.server
1415
def run_dgea_server(input, output, session,
@@ -19,7 +20,10 @@ def run_dgea_server(input, output, session,
1920
_alternative: reactive.Value[str],
2021
_model: reactive.Value[str],
2122
_uniques: reactive.Value[list],
22-
_contrast: reactive.Value[str]):
23+
_contrast: reactive.Value[str],
24+
_sub_category: reactive.Value[str],
25+
_chosen_values: reactive.Value[list],
26+
_sub_uniques: reactive.Value[list]):
2327
_category_columns = reactive.value([])
2428
_numeric_columns = reactive.value([])
2529

@@ -38,10 +42,22 @@ def contrast_selector():
3842

3943
return ui.input_select("contrast", "Contrast", choices=columns, selected=columns[0])
4044

45+
@output
46+
@render.ui
47+
def subset_selector():
48+
columns = _category_columns.get()
49+
50+
return ui.input_select("sub_category", "Category to subset", choices=columns, selected=columns[0])
51+
4152
@reactive.effect
4253
def update_contrast():
4354
contrast = input["contrast"].get()
4455
_contrast.set(contrast)
56+
57+
@reactive.effect
58+
def update_subset():
59+
sub_category = input["sub_category"].get()
60+
_sub_category.set(sub_category)
4561

4662
@reactive.effect
4763
@reactive.event(input["run"])
@@ -51,7 +67,10 @@ def handle_run():
5167
referece = _reference.get()
5268
alternative = _alternative.get()
5369
model = _model.get()
54-
run_scanvi(adata, contrast, referece, alternative, model)
70+
sub_category = _sub_category.get()
71+
chosen_values = _chosen_values.get()
72+
adata_subset = adata[adata.obs[sub_category].isin(chosen_values)].copy()
73+
run_scanvi(adata_subset, contrast, referece, alternative, model)
5574

5675
@reactive.effect
5776
def update_scanvi_result():
@@ -75,3 +94,12 @@ def update_uniques():
7594
return
7695
uniques = adata.obs[contrast].unique().tolist()
7796
_uniques.set(uniques)
97+
98+
@reactive.effect
99+
def update_sub_uniques():
100+
adata = _adata.get()
101+
sub_category = _sub_category.get()
102+
if adata is None or sub_category is None:
103+
return
104+
sub_uniques = adata.obs[sub_category].unique().tolist()
105+
_sub_uniques.set(sub_uniques)

0 commit comments

Comments
 (0)