Skip to content

Commit a62c4a5

Browse files
committed
add mibig bgc classes version-based control
1 parent a08f1b1 commit a62c4a5

File tree

3 files changed

+129
-39
lines changed

3 files changed

+129
-39
lines changed

app/callbacks.py

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
import dash_uploader as du
1313
import pandas as pd
1414
import plotly.graph_objects as go
15-
from config import GM_FILTER_DROPDOWN_BGC_CLASS_OPTIONS
15+
from config import GM_FILTER_DROPDOWN_BGC_CLASS_OPTIONS_PRE_V4
16+
from config import GM_FILTER_DROPDOWN_BGC_CLASS_OPTIONS_V4
1617
from config import GM_FILTER_DROPDOWN_MENU_OPTIONS
1718
from config import GM_RESULTS_TABLE_CHECKL_OPTIONAL_COLUMNS
1819
from config import GM_RESULTS_TABLE_MANDATORY_COLUMNS
@@ -528,7 +529,7 @@ def gm_filter_create_initial_block(block_id: str) -> dmc.Grid:
528529
),
529530
dcc.Dropdown(
530531
id={"type": "gm-filter-dropdown-bgc-class-dropdown", "index": block_id},
531-
options=GM_FILTER_DROPDOWN_BGC_CLASS_OPTIONS,
532+
options=GM_FILTER_DROPDOWN_BGC_CLASS_OPTIONS_PRE_V4,
532533
multi=True,
533534
style={"display": "none"},
534535
),
@@ -631,7 +632,7 @@ def gm_filter_display_blocks(
631632
"type": "gm-filter-dropdown-bgc-class-dropdown",
632633
"index": new_block_id,
633634
},
634-
options=GM_FILTER_DROPDOWN_BGC_CLASS_OPTIONS,
635+
options=GM_FILTER_DROPDOWN_BGC_CLASS_OPTIONS_PRE_V4,
635636
multi=True,
636637
style={"display": "none"},
637638
),
@@ -663,36 +664,64 @@ def gm_filter_display_blocks(
663664
Output({"type": "gm-filter-dropdown-bgc-class-dropdown", "index": MATCH}, "placeholder"),
664665
Output({"type": "gm-filter-dropdown-ids-text-input", "index": MATCH}, "value"),
665666
Output({"type": "gm-filter-dropdown-bgc-class-dropdown", "index": MATCH}, "value"),
667+
Output({"type": "gm-filter-dropdown-bgc-class-dropdown", "index": MATCH}, "options"),
666668
Input({"type": "gm-filter-dropdown-menu", "index": MATCH}, "value"),
669+
Input("mibig-version-selector", "value"),
670+
State({"type": "gm-filter-dropdown-bgc-class-dropdown", "index": MATCH}, "value"),
667671
)
668672
def gm_filter_update_placeholder(
669-
selected_value: str,
670-
) -> tuple[dict[str, str], dict[str, str], str, str, str, list[Any]]:
671-
"""Update the placeholder text and style of input fields based on the dropdown selection.
673+
selected_value: str, mibig_version: str, current_bgc_value: list
674+
) -> tuple[dict[str, str], dict[str, str], str, str, str, list[Any], list[dict]]:
675+
"""Update the placeholder text, style, and options of input fields based on the dropdown selection and MIBiG version.
672676
673677
Args:
674678
selected_value: The value selected in the dropdown menu.
679+
mibig_version: The selected MIBiG version.
680+
current_bgc_value: Currently selected BGC class values.
675681
676682
Returns:
677-
A tuple containing style, placeholder, and value updates for the input fields.
683+
A tuple containing style, placeholder, value, and options updates for the input fields.
678684
"""
679-
if not ctx.triggered:
680-
# Callback was not triggered by user interaction, don't change anything
681-
raise dash.exceptions.PreventUpdate
685+
# Determine which option set to use based on MIBiG version
686+
if mibig_version == "v4_plus":
687+
bgc_options = GM_FILTER_DROPDOWN_BGC_CLASS_OPTIONS_V4
688+
else:
689+
bgc_options = GM_FILTER_DROPDOWN_BGC_CLASS_OPTIONS_PRE_V4
690+
691+
# Check what triggered the callback
692+
triggered_id = ctx.triggered_id
693+
694+
# If MIBiG version changed, clear the BGC class selection
695+
if triggered_id == "mibig-version-selector":
696+
new_bgc_value = []
697+
else:
698+
# Otherwise keep the current selection
699+
new_bgc_value = current_bgc_value
700+
701+
# Update the styles and placeholders based on the dropdown selection
682702
if selected_value == "GCF_ID":
683-
return {"display": "block"}, {"display": "none"}, "1, 2, 3, ...", "", "", []
703+
return (
704+
{"display": "block"},
705+
{"display": "none"},
706+
"1, 2, 3, ...",
707+
"",
708+
"",
709+
new_bgc_value,
710+
bgc_options,
711+
)
684712
elif selected_value == "BGC_CLASS":
685713
return (
686714
{"display": "none"},
687715
{"display": "block"},
688716
"",
689717
"Select one or more BGC classes",
690718
"",
691-
[],
719+
new_bgc_value,
720+
bgc_options,
692721
)
693722
else:
694723
# This case should never occur due to the Literal type, but it satisfies mypy
695-
return {"display": "none"}, {"display": "none"}, "", "", "", []
724+
return {"display": "none"}, {"display": "none"}, "", "", "", new_bgc_value, bgc_options
696725

697726

698727
# ------------------ MG Filter functions ------------------ #

app/config.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,28 @@
44
{"label": "BGC Class", "value": "BGC_CLASS"},
55
]
66

7-
GM_FILTER_DROPDOWN_BGC_CLASS_OPTIONS = [
7+
# BGC class options for different MIBiG versions
8+
MIBIG_VERSIONS = [
9+
{"label": "MIBiG < 4.0", "value": "pre_v4"},
10+
{"label": "MIBiG ≥ 4.0", "value": "v4_plus"},
11+
]
12+
13+
GM_FILTER_DROPDOWN_BGC_CLASS_OPTIONS_PRE_V4 = [
814
{"label": "Alkaloid", "value": "ALKALOID"},
915
{"label": "NRP", "value": "NRP"},
1016
{"label": "Polyketide", "value": "POLYKETIDE"},
1117
{"label": "RiPP", "value": "RIPP"},
12-
{"label": "Saccharide", "value": "SAACCHARIDE"},
18+
{"label": "Saccharide", "value": "SACCHARIDE"},
19+
{"label": "Terpene", "value": "TERPENE"},
20+
{"label": "Other", "value": "OTHER"},
21+
{"label": "Unknown", "value": "UNKNOWN"},
22+
]
23+
24+
GM_FILTER_DROPDOWN_BGC_CLASS_OPTIONS_V4 = [
25+
{"label": "NRPS", "value": "NRPS"},
26+
{"label": "PKS", "value": "PKS"},
27+
{"label": "Ribosomal", "value": "RIBOSOMAL"},
28+
{"label": "Saccharide", "value": "SACCHARIDE"},
1329
{"label": "Terpene", "value": "TERPENE"},
1430
{"label": "Other", "value": "OTHER"},
1531
{"label": "Unknown", "value": "UNKNOWN"},

app/layouts.py

Lines changed: 69 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import dash_uploader as du
55
from config import GM_RESULTS_TABLE_CHECKL_OPTIONAL_COLUMNS
66
from config import MG_RESULTS_TABLE_CHECKL_OPTIONAL_COLUMNS
7+
from config import MIBIG_VERSIONS
78
from dash import dash_table
89
from dash import dcc
910
from dash import html
@@ -166,7 +167,12 @@ def create_results_table(table_id, no_sort_columns):
166167

167168

168169
def create_filter_accordion(
169-
title, control_id, blocks_store_id, blocks_container_id, apply_button_id
170+
title,
171+
control_id,
172+
blocks_store_id,
173+
blocks_container_id,
174+
apply_button_id,
175+
include_mibig_selector=False,
170176
):
171177
"""Create a common filter accordion component.
172178
@@ -176,10 +182,69 @@ def create_filter_accordion(
176182
blocks_store_id: The ID for blocks storage.
177183
blocks_container_id: The ID for blocks container.
178184
apply_button_id: The ID for the apply button.
185+
include_mibig_selector: Whether to include MIBiG version selector.
179186
180187
Returns:
181188
A dmc.Accordion component.
182189
"""
190+
panel_content = []
191+
192+
# Add MIBiG version selector if needed
193+
if include_mibig_selector:
194+
panel_content.append(
195+
dbc.Row(
196+
dbc.Col(
197+
html.Div(
198+
[
199+
dbc.Label(
200+
"MIBiG Version:",
201+
className="me-2",
202+
style={"verticalAlign": "middle"},
203+
),
204+
dcc.Dropdown(
205+
id="mibig-version-selector",
206+
options=MIBIG_VERSIONS,
207+
value="pre_v4", # Default to pre v4.0 for backward compatibility
208+
clearable=False,
209+
style={
210+
"width": "150px",
211+
"verticalAlign": "middle",
212+
"marginLeft": "5px",
213+
},
214+
),
215+
],
216+
className="d-flex align-items-center",
217+
style={"marginLeft": "0", "marginBottom": "70px"},
218+
),
219+
width=12,
220+
),
221+
className="mb-3",
222+
)
223+
)
224+
225+
panel_content.extend(
226+
[
227+
html.Div(
228+
[
229+
dcc.Store(id=blocks_store_id, data=[]),
230+
html.Div(
231+
id=blocks_container_id,
232+
children=[],
233+
),
234+
]
235+
),
236+
html.Div(
237+
dbc.Button(
238+
"Apply Filters",
239+
id=apply_button_id,
240+
color="primary",
241+
className="mt-3",
242+
),
243+
className="d-flex justify-content-center",
244+
),
245+
]
246+
)
247+
183248
return dmc.Accordion(
184249
[
185250
dmc.AccordionItem(
@@ -190,28 +255,7 @@ def create_filter_accordion(
190255
id=control_id,
191256
className="mt-5 mb-3",
192257
),
193-
dmc.AccordionPanel(
194-
[
195-
html.Div(
196-
[
197-
dcc.Store(id=blocks_store_id, data=[]),
198-
html.Div(
199-
id=blocks_container_id,
200-
children=[],
201-
),
202-
]
203-
),
204-
html.Div(
205-
dbc.Button(
206-
"Apply Filters",
207-
id=apply_button_id,
208-
color="primary",
209-
className="mt-3",
210-
),
211-
className="d-flex justify-content-center",
212-
),
213-
]
214-
),
258+
dmc.AccordionPanel(panel_content),
215259
],
216260
value=f"{control_id.split('-')[0]}-filter-accordion",
217261
),
@@ -448,13 +492,14 @@ def create_tab_content(prefix, filter_title, checkl_options, no_sort_columns):
448492
Returns:
449493
A dbc.Row component with all tab content.
450494
"""
451-
# Create filter accordion
495+
# Create filter accordion with MIBiG selector for GM tab
452496
filter_accordion = create_filter_accordion(
453497
filter_title,
454498
f"{prefix}-filter-accordion-control",
455499
f"{prefix}-filter-blocks-id",
456500
f"{prefix}-filter-blocks-container",
457501
f"{prefix}-filter-apply-button",
502+
include_mibig_selector=(prefix == "gm"),
458503
)
459504

460505
# Create data table

0 commit comments

Comments
 (0)