Recompute regression line in log scale (#11)
Browse files- prettify scores (368527a4c9b600e8c64388f23ce01c9809d31d93)
- wip: explain scores (d231574b738e094431572bacda94a121568520cb)
- recompute regression line with log scale (bf971abc373ed1566f30112474ff0dc32235a377)
folding_studio_demo/app.py
CHANGED
@@ -300,14 +300,14 @@ def create_correlation_tab():
|
|
300 |
outputs=score_description,
|
301 |
)
|
302 |
with gr.Column():
|
303 |
-
|
304 |
|
305 |
fake_predict_btn.click(
|
306 |
fn=lambda x: fake_predict_and_correlate(
|
307 |
spr_data_with_scores, SCORE_COLUMNS, ["Antibody Name", "KD (nM)"]
|
308 |
),
|
309 |
inputs=[correlation_type],
|
310 |
-
outputs=[prediction_dataframe, correlation_ranking_plot,
|
311 |
)
|
312 |
|
313 |
def update_regression_plot(score, use_log):
|
@@ -322,7 +322,7 @@ def create_correlation_tab():
|
|
322 |
correlation_column.change(
|
323 |
fn=update_regression_plot,
|
324 |
inputs=[correlation_column, log_scale],
|
325 |
-
outputs=
|
326 |
)
|
327 |
|
328 |
correlation_type.change(
|
@@ -333,8 +333,8 @@ def create_correlation_tab():
|
|
333 |
|
334 |
log_scale.change(
|
335 |
fn=update_regression_plot,
|
336 |
-
inputs=[correlation_column, log_scale],
|
337 |
-
outputs=
|
338 |
)
|
339 |
|
340 |
|
|
|
300 |
outputs=score_description,
|
301 |
)
|
302 |
with gr.Column():
|
303 |
+
regression_plot = gr.Plot(label="Correlation with binding affinity")
|
304 |
|
305 |
fake_predict_btn.click(
|
306 |
fn=lambda x: fake_predict_and_correlate(
|
307 |
spr_data_with_scores, SCORE_COLUMNS, ["Antibody Name", "KD (nM)"]
|
308 |
),
|
309 |
inputs=[correlation_type],
|
310 |
+
outputs=[prediction_dataframe, correlation_ranking_plot, regression_plot],
|
311 |
)
|
312 |
|
313 |
def update_regression_plot(score, use_log):
|
|
|
322 |
correlation_column.change(
|
323 |
fn=update_regression_plot,
|
324 |
inputs=[correlation_column, log_scale],
|
325 |
+
outputs=regression_plot,
|
326 |
)
|
327 |
|
328 |
correlation_type.change(
|
|
|
333 |
|
334 |
log_scale.change(
|
335 |
fn=update_regression_plot,
|
336 |
+
inputs=[correlation_column, log_scale],
|
337 |
+
outputs=regression_plot,
|
338 |
)
|
339 |
|
340 |
|
folding_studio_demo/correlate.py
CHANGED
@@ -157,9 +157,22 @@ def make_regression_plot(spr_data_with_scores: pd.DataFrame, score: str, use_log
|
|
157 |
xaxis_type="log" if use_log else "linear" # Set x-axis to logarithmic scale
|
158 |
)
|
159 |
# compute the regression line
|
160 |
-
|
161 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
162 |
corr_line_y = corr_line[0] * corr_line_x + corr_line[1]
|
|
|
|
|
|
|
|
|
163 |
# add the regression line to the plot
|
164 |
corr_plot.add_trace(go.Scatter(
|
165 |
x=corr_line_x,
|
|
|
157 |
xaxis_type="log" if use_log else "linear" # Set x-axis to logarithmic scale
|
158 |
)
|
159 |
# compute the regression line
|
160 |
+
if use_log:
|
161 |
+
# Take log of KD values for fitting
|
162 |
+
x_vals = np.log10(spr_data_with_scores["KD (nM)"])
|
163 |
+
else:
|
164 |
+
x_vals = spr_data_with_scores["KD (nM)"]
|
165 |
+
|
166 |
+
# Fit line to data
|
167 |
+
corr_line = np.polyfit(x_vals, spr_data_with_scores[score], 1)
|
168 |
+
|
169 |
+
# Generate x points for line
|
170 |
+
corr_line_x = np.linspace(min(x_vals), max(x_vals), 100)
|
171 |
corr_line_y = corr_line[0] * corr_line_x + corr_line[1]
|
172 |
+
|
173 |
+
# Convert back from log space if needed
|
174 |
+
if use_log:
|
175 |
+
corr_line_x = 10**corr_line_x
|
176 |
# add the regression line to the plot
|
177 |
corr_plot.add_trace(go.Scatter(
|
178 |
x=corr_line_x,
|