make log a global option
Browse files- folding_studio_demo/app.py +25 -26
- folding_studio_demo/correlate.py +26 -27
folding_studio_demo/app.py
CHANGED
@@ -321,13 +321,18 @@ def create_correlation_tab():
|
|
321 |
outputs=[prediction_dataframe],
|
322 |
)
|
323 |
with gr.Row():
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
|
|
|
|
|
|
|
|
|
|
331 |
correlation_ranking_plot = gr.Plot(label="Correlation ranking")
|
332 |
with gr.Row():
|
333 |
with gr.Column(scale=0):
|
@@ -338,10 +343,6 @@ def create_correlation_tab():
|
|
338 |
multiselect=False,
|
339 |
value=SCORE_COLUMNS[0],
|
340 |
)
|
341 |
-
# Add checkbox for log scale and update plot when either input changes
|
342 |
-
log_scale = gr.Checkbox(
|
343 |
-
label="Display x-axis on logarithmic scale", value=False
|
344 |
-
)
|
345 |
score_description = gr.Markdown(
|
346 |
get_score_description(correlation_column.value)
|
347 |
)
|
@@ -361,31 +362,29 @@ def create_correlation_tab():
|
|
361 |
outputs=[prediction_dataframe, correlation_ranking_plot, regression_plot],
|
362 |
)
|
363 |
|
364 |
-
def
|
365 |
-
return make_regression_plot(spr_data_with_scores, score, use_log)
|
366 |
-
|
367 |
-
def update_correlation_plot(correlation_type):
|
368 |
logger.info(f"Updating correlation plot for {correlation_type}")
|
369 |
corr_data = compute_correlation_data(spr_data_with_scores, SCORE_COLUMNS)
|
370 |
logger.info(f"Correlation data: {corr_data}")
|
371 |
-
|
|
|
|
|
372 |
|
373 |
correlation_column.change(
|
374 |
-
fn=
|
375 |
-
inputs=[correlation_column, log_scale],
|
376 |
-
outputs=regression_plot,
|
377 |
)
|
378 |
|
379 |
correlation_type.change(
|
380 |
-
fn=
|
381 |
-
inputs=[correlation_type],
|
382 |
-
outputs=correlation_ranking_plot,
|
383 |
)
|
384 |
-
|
385 |
log_scale.change(
|
386 |
-
fn=
|
387 |
-
inputs=[correlation_column, log_scale],
|
388 |
-
outputs=regression_plot,
|
389 |
)
|
390 |
|
391 |
|
|
|
321 |
outputs=[prediction_dataframe],
|
322 |
)
|
323 |
with gr.Row():
|
324 |
+
with gr.Row():
|
325 |
+
correlation_type = gr.Radio(
|
326 |
+
choices=["Spearman", "Pearson"],
|
327 |
+
value="Spearman",
|
328 |
+
label="Correlation Type",
|
329 |
+
interactive=True,
|
330 |
+
scale=0,
|
331 |
+
)
|
332 |
+
with gr.Row():
|
333 |
+
log_scale = gr.Checkbox(
|
334 |
+
label="Use log scale for KD", value=False
|
335 |
+
)
|
336 |
correlation_ranking_plot = gr.Plot(label="Correlation ranking")
|
337 |
with gr.Row():
|
338 |
with gr.Column(scale=0):
|
|
|
343 |
multiselect=False,
|
344 |
value=SCORE_COLUMNS[0],
|
345 |
)
|
|
|
|
|
|
|
|
|
346 |
score_description = gr.Markdown(
|
347 |
get_score_description(correlation_column.value)
|
348 |
)
|
|
|
362 |
outputs=[prediction_dataframe, correlation_ranking_plot, regression_plot],
|
363 |
)
|
364 |
|
365 |
+
def update_plots_with_log(correlation_type, score, use_log):
|
|
|
|
|
|
|
366 |
logger.info(f"Updating correlation plot for {correlation_type}")
|
367 |
corr_data = compute_correlation_data(spr_data_with_scores, SCORE_COLUMNS)
|
368 |
logger.info(f"Correlation data: {corr_data}")
|
369 |
+
corr_ranking_plot = plot_correlation_ranking(corr_data, correlation_type, kd_col="KD (nM)" if not use_log else "log_kd")
|
370 |
+
regression_plot = make_regression_plot(spr_data_with_scores, score, use_log)
|
371 |
+
return regression_plot, corr_ranking_plot
|
372 |
|
373 |
correlation_column.change(
|
374 |
+
fn=update_plots_with_log,
|
375 |
+
inputs=[correlation_type, correlation_column, log_scale],
|
376 |
+
outputs=[regression_plot, correlation_ranking_plot],
|
377 |
)
|
378 |
|
379 |
correlation_type.change(
|
380 |
+
fn=update_plots_with_log,
|
381 |
+
inputs=[correlation_type, correlation_column, log_scale],
|
382 |
+
outputs=[regression_plot, correlation_ranking_plot],
|
383 |
)
|
|
|
384 |
log_scale.change(
|
385 |
+
fn=update_plots_with_log,
|
386 |
+
inputs=[correlation_type, correlation_column, log_scale],
|
387 |
+
outputs=[regression_plot, correlation_ranking_plot],
|
388 |
)
|
389 |
|
390 |
|
folding_studio_demo/correlate.py
CHANGED
@@ -75,30 +75,26 @@ def compute_correlation_data(
|
|
75 |
corr_funcs = {}
|
76 |
corr_funcs["Spearman"] = spearmanr
|
77 |
corr_funcs["Pearson"] = pearsonr
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
)
|
99 |
-
logger.info(
|
100 |
-
f"Correlation {correlation_type} between {score_col} and KD (nM): {correlation_value}"
|
101 |
-
)
|
102 |
|
103 |
corr_data = pd.DataFrame(corr_data)
|
104 |
# Find the lines in corr_data with NaN values and remove them
|
@@ -112,10 +108,13 @@ def compute_correlation_data(
|
|
112 |
|
113 |
|
114 |
def plot_correlation_ranking(
|
115 |
-
corr_data: pd.DataFrame, correlation_type: str
|
116 |
) -> go.Figure:
|
117 |
# Create bar plot of correlations
|
118 |
-
data = corr_data[
|
|
|
|
|
|
|
119 |
corr_ranking_plot = go.Figure(
|
120 |
data=[
|
121 |
go.Bar(
|
@@ -144,7 +143,7 @@ def fake_predict_and_correlate(
|
|
144 |
"""Fake predict structures of all complexes and correlate the results."""
|
145 |
|
146 |
corr_data = compute_correlation_data(spr_data_with_scores, score_cols)
|
147 |
-
corr_ranking_plot = plot_correlation_ranking(corr_data, "Spearman")
|
148 |
|
149 |
cols_to_show = main_cols[:]
|
150 |
cols_to_show.extend(score_cols)
|
|
|
75 |
corr_funcs = {}
|
76 |
corr_funcs["Spearman"] = spearmanr
|
77 |
corr_funcs["Pearson"] = pearsonr
|
78 |
+
for kd_col in ["KD (nM)", "log_kd"]:
|
79 |
+
for correlation_type, corr_func in corr_funcs.items():
|
80 |
+
for score_col in score_cols:
|
81 |
+
logger.info(
|
82 |
+
f"Computing {correlation_type} correlation between {score_col} and {kd_col}"
|
83 |
+
)
|
84 |
+
res = corr_func(
|
85 |
+
spr_data_with_scores[kd_col], spr_data_with_scores[score_col]
|
86 |
+
)
|
87 |
+
logger.info(f"Correlation function: {corr_func}")
|
88 |
+
correlation_value = res.statistic
|
89 |
+
corr_data.append(
|
90 |
+
{
|
91 |
+
"correlation_type": correlation_type,
|
92 |
+
"kd_col": kd_col,
|
93 |
+
"score": score_col,
|
94 |
+
"correlation": correlation_value,
|
95 |
+
"p-value": res.pvalue,
|
96 |
+
}
|
97 |
+
)
|
|
|
|
|
|
|
|
|
98 |
|
99 |
corr_data = pd.DataFrame(corr_data)
|
100 |
# Find the lines in corr_data with NaN values and remove them
|
|
|
108 |
|
109 |
|
110 |
def plot_correlation_ranking(
|
111 |
+
corr_data: pd.DataFrame, correlation_type: str, kd_col: str
|
112 |
) -> go.Figure:
|
113 |
# Create bar plot of correlations
|
114 |
+
data = corr_data[
|
115 |
+
(corr_data["correlation_type"] == correlation_type)
|
116 |
+
& (corr_data["kd_col"] == kd_col)
|
117 |
+
]
|
118 |
corr_ranking_plot = go.Figure(
|
119 |
data=[
|
120 |
go.Bar(
|
|
|
143 |
"""Fake predict structures of all complexes and correlate the results."""
|
144 |
|
145 |
corr_data = compute_correlation_data(spr_data_with_scores, score_cols)
|
146 |
+
corr_ranking_plot = plot_correlation_ranking(corr_data, "Spearman", kd_col="KD (nM)")
|
147 |
|
148 |
cols_to_show = main_cols[:]
|
149 |
cols_to_show.extend(score_cols)
|