jfaustin commited on
Commit
9213ba3
·
1 Parent(s): 9976695

wip: scatter plots

Browse files
Files changed (2) hide show
  1. app.py +23 -5
  2. pyproject.toml +2 -0
app.py CHANGED
@@ -192,6 +192,7 @@ def fake_predict_and_correlate(spr_data_with_scores: pd.DataFrame, score_cols: l
192
  """Fake predict structures of all complexes and correlate the results."""
193
  corr_data = []
194
  for score_col in score_cols:
 
195
  res = spearmanr(spr_data_with_scores["KD (nM)"], spr_data_with_scores[score_col])
196
  corr_data.append({"score": score_col, "correlation": res.statistic, "p-value": res.pvalue})
197
 
@@ -200,7 +201,7 @@ def fake_predict_and_correlate(spr_data_with_scores: pd.DataFrame, score_cols: l
200
  corr_data = corr_data.sort_values('correlation', ascending=True)
201
 
202
  # Create bar plot of correlations
203
- corr_plot = go.Figure(data=[
204
  go.Bar(
205
  x=corr_data["correlation"],
206
  y=corr_data["score"],
@@ -209,7 +210,7 @@ def fake_predict_and_correlate(spr_data_with_scores: pd.DataFrame, score_cols: l
209
  hovertemplate="<i>Score:</i> %{y}<br><i>Correlation:</i> %{x:.3f}<br>"
210
  )
211
  ])
212
- corr_plot.update_layout(
213
  title="Correlation with Binding Affinity",
214
  yaxis_title="Score Type",
215
  xaxis_title="Spearman Correlation",
@@ -217,9 +218,24 @@ def fake_predict_and_correlate(spr_data_with_scores: pd.DataFrame, score_cols: l
217
  showlegend=False
218
  )
219
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
220
  cols_to_show = ["KD (nM)"]
221
  cols_to_show.extend(score_cols)
222
- return spr_data_with_scores[cols_to_show], corr_plot
 
223
 
224
  demo = gr.Blocks(title="Folding Studio: structure prediction with Boltz-1")
225
 
@@ -261,7 +277,9 @@ with demo:
261
  with gr.Row():
262
  prediction_dataframe = gr.Dataframe(label="Predicted Structures Data")
263
  with gr.Column():
264
- correlation_plot = gr.Plot(label="Correlation")
 
 
265
 
266
 
267
  cols = [
@@ -297,7 +315,7 @@ with demo:
297
  fake_predict_btn.click(
298
  fn=lambda x: fake_predict_and_correlate(spr_data_with_scores, cols),
299
  inputs=None,
300
- outputs=[prediction_dataframe, correlation_plot]
301
  )
302
 
303
 
 
192
  """Fake predict structures of all complexes and correlate the results."""
193
  corr_data = []
194
  for score_col in score_cols:
195
+ logging.info("Computing correlation between %s and KD (nM)", score_col)
196
  res = spearmanr(spr_data_with_scores["KD (nM)"], spr_data_with_scores[score_col])
197
  corr_data.append({"score": score_col, "correlation": res.statistic, "p-value": res.pvalue})
198
 
 
201
  corr_data = corr_data.sort_values('correlation', ascending=True)
202
 
203
  # Create bar plot of correlations
204
+ corr_ranking_plot = go.Figure(data=[
205
  go.Bar(
206
  x=corr_data["correlation"],
207
  y=corr_data["score"],
 
210
  hovertemplate="<i>Score:</i> %{y}<br><i>Correlation:</i> %{x:.3f}<br>"
211
  )
212
  ])
213
+ corr_ranking_plot.update_layout(
214
  title="Correlation with Binding Affinity",
215
  yaxis_title="Score Type",
216
  xaxis_title="Spearman Correlation",
 
218
  showlegend=False
219
  )
220
 
221
+ # corr_plot is a scatter plot of the correlation between the binding affinity and each of the scores
222
+ scatters = []
223
+ for score_col in score_cols:
224
+ scatters.append(
225
+ go.Scatter(
226
+ x=spr_data_with_scores["KD (nM)"],
227
+ y=spr_data_with_scores[score_col],
228
+ name=f"KD (nM) vs {score_col}",
229
+ mode='markers', # Only show markers/dots, no lines
230
+ hovertemplate="<i>Score:</i> %{y}<br><i>KD (nM):</i> %{x:.2f}<br>"
231
+ )
232
+ )
233
+ corr_plot = go.Figure(data=scatters)
234
+
235
  cols_to_show = ["KD (nM)"]
236
  cols_to_show.extend(score_cols)
237
+
238
+ return spr_data_with_scores[cols_to_show], corr_ranking_plot, corr_plot
239
 
240
  demo = gr.Blocks(title="Folding Studio: structure prediction with Boltz-1")
241
 
 
277
  with gr.Row():
278
  prediction_dataframe = gr.Dataframe(label="Predicted Structures Data")
279
  with gr.Column():
280
+ correlation_ranking_plot = gr.Plot(label="Correlation ranking")
281
+ correlation_plot = gr.Plot(label="Correlation with binding affinity")
282
+
283
 
284
 
285
  cols = [
 
315
  fake_predict_btn.click(
316
  fn=lambda x: fake_predict_and_correlate(spr_data_with_scores, cols),
317
  inputs=None,
318
+ outputs=[prediction_dataframe, correlation_ranking_plot, correlation_plot]
319
  )
320
 
321
 
pyproject.toml CHANGED
@@ -7,6 +7,8 @@ requires-python = ">=3.11"
7
  dependencies = [
8
  "gradio==5.30.0",
9
  "ipython>=9.2.0",
 
10
  "numpy>=2.2.6",
11
  "plotly>=6.1.1",
 
12
  ]
 
7
  dependencies = [
8
  "gradio==5.30.0",
9
  "ipython>=9.2.0",
10
+ "jupyter>=1.1.1",
11
  "numpy>=2.2.6",
12
  "plotly>=6.1.1",
13
+ "scipy>=1.15.3",
14
  ]