richiam commited on
Commit
da03289
·
verified ·
1 Parent(s): 4e2e836

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +37 -1
app.py CHANGED
@@ -76,6 +76,16 @@ PMID_GROUPS = {
76
  for pmid, entry in META.items()
77
  }
78
 
 
 
 
 
 
 
 
 
 
 
79
  # Column sets
80
  EXTRACTION_FIELDS = [
81
  "pmid", "enzyme_name", "organism_source", "strain", "expression_strain",
@@ -713,6 +723,19 @@ def clustering_tab():
713
  ),
714
  ], width=2),
715
  ], className="mb-2 align-items-end"),
 
 
 
 
 
 
 
 
 
 
 
 
 
716
  dbc.Row([dbc.Col(html.Div(id="plot-status", className="text-danger small mb-1"))]),
717
  dbc.Row([
718
  dbc.Col(
@@ -2124,8 +2147,9 @@ def populate_cross_filter_values(cross_field, model, min_val, threshold):
2124
  Input("cluster-group-filter", "value"),
2125
  Input("dd-cross-field", "value"),
2126
  Input("dd-cross-value", "value"),
 
2127
  )
2128
- def update_cluster_plot(model, min_val, threshold, field, plot_type, top_n, groups, cross_field, cross_value):
2129
  empty_fig = go.Figure()
2130
  empty_fig.update_layout(paper_bgcolor="#ffffff", plot_bgcolor="#f9fafc")
2131
  if not all([model, min_val, threshold, field, plot_type]):
@@ -2135,6 +2159,16 @@ def update_cluster_plot(model, min_val, threshold, field, plot_type, top_n, grou
2135
  if cdf is None:
2136
  return empty_fig, f"Data file not found for model={model} min={min_val} t={threshold}"
2137
 
 
 
 
 
 
 
 
 
 
 
2138
  # Apply cross-field filter: keep only (key, protein_index) in the selected cross-field cluster
2139
  if cross_field and cross_value:
2140
  keep = cdf[(cdf["field"] == cross_field) & (cdf["cluster_label"] == cross_value)][["key", "protein_index"]]
@@ -2159,6 +2193,8 @@ def update_cluster_plot(model, min_val, threshold, field, plot_type, top_n, grou
2159
 
2160
  n = top_n or 0
2161
  suffix_parts = []
 
 
2162
  if groups:
2163
  suffix_parts.append(", ".join(groups))
2164
  if cross_field and cross_value:
 
76
  for pmid, entry in META.items()
77
  }
78
 
79
+ PMID_ERA_BINS = [
80
+ ("pre-2001", 0, 10_000_000),
81
+ ("2001–2005", 10_000_000, 15_000_000),
82
+ ("2006–2009", 15_000_000, 20_000_000),
83
+ ("2010–2013", 20_000_000, 25_000_000),
84
+ ("2014–2017", 25_000_000, 30_000_000),
85
+ ("2018–2020", 30_000_000, 35_000_000),
86
+ ("2021–2023", 35_000_000, 40_000_000),
87
+ ]
88
+
89
  # Column sets
90
  EXTRACTION_FIELDS = [
91
  "pmid", "enzyme_name", "organism_source", "strain", "expression_strain",
 
723
  ),
724
  ], width=2),
725
  ], className="mb-2 align-items-end"),
726
+ dbc.Row([
727
+ dbc.Col([
728
+ html.Label("Filter by publication era", className="fw-semibold small mb-1"),
729
+ dcc.Dropdown(
730
+ id="dd-era-filter",
731
+ options=[{"label": label, "value": label}
732
+ for label, _, _ in PMID_ERA_BINS],
733
+ placeholder="All time periods",
734
+ clearable=True,
735
+ style={"fontSize": "13px"},
736
+ ),
737
+ ], width=4),
738
+ ], className="mb-2"),
739
  dbc.Row([dbc.Col(html.Div(id="plot-status", className="text-danger small mb-1"))]),
740
  dbc.Row([
741
  dbc.Col(
 
2147
  Input("cluster-group-filter", "value"),
2148
  Input("dd-cross-field", "value"),
2149
  Input("dd-cross-value", "value"),
2150
+ Input("dd-era-filter", "value"),
2151
  )
2152
+ def update_cluster_plot(model, min_val, threshold, field, plot_type, top_n, groups, cross_field, cross_value, era):
2153
  empty_fig = go.Figure()
2154
  empty_fig.update_layout(paper_bgcolor="#ffffff", plot_bgcolor="#f9fafc")
2155
  if not all([model, min_val, threshold, field, plot_type]):
 
2159
  if cdf is None:
2160
  return empty_fig, f"Data file not found for model={model} min={min_val} t={threshold}"
2161
 
2162
+ # Apply era filter based on PMID as publication year proxy
2163
+ if era:
2164
+ era_range = {label: (lo, hi) for label, lo, hi in PMID_ERA_BINS}
2165
+ if era in era_range:
2166
+ lo, hi = era_range[era]
2167
+ pmid_num = pd.to_numeric(cdf["key"], errors="coerce")
2168
+ cdf = cdf[(pmid_num >= lo) & (pmid_num < hi)]
2169
+ if cdf.empty:
2170
+ return empty_fig, f"No data found for era '{era}'."
2171
+
2172
  # Apply cross-field filter: keep only (key, protein_index) in the selected cross-field cluster
2173
  if cross_field and cross_value:
2174
  keep = cdf[(cdf["field"] == cross_field) & (cdf["cluster_label"] == cross_value)][["key", "protein_index"]]
 
2193
 
2194
  n = top_n or 0
2195
  suffix_parts = []
2196
+ if era:
2197
+ suffix_parts.append(era)
2198
  if groups:
2199
  suffix_parts.append(", ".join(groups))
2200
  if cross_field and cross_value: