Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -28,7 +28,7 @@ import requests
|
|
28 |
from rdkit.DataStructs import BulkTanimotoSimilarity
|
29 |
from requests.adapters import HTTPAdapter, Retry
|
30 |
from markdown import markdown
|
31 |
-
from rdkit import Chem
|
32 |
from rdkit.Chem import AllChem, Draw, RDConfig, PandasTools, Descriptors, rdMolDescriptors, rdmolops, Lipinski, Crippen
|
33 |
from rdkit.Chem.Scaffolds import MurckoScaffold
|
34 |
import seaborn as sns
|
@@ -833,7 +833,8 @@ def submit_predict(predict_filepath, task, preset, target_family, opts, job_info
|
|
833 |
predictions, _ = predict(cfg)
|
834 |
predictions = pd.concat([pd.DataFrame(prediction) for prediction in predictions], ignore_index=True)
|
835 |
predictions['Source'] = f'Predicted ({preset} {target_family})'
|
836 |
-
|
|
|
837 |
|
838 |
else:
|
839 |
predictions_file = f'{SERVER_DATA_DIR}/{job_id}_{task_file_abbr[task]}_family-recommended_predictions.csv'
|
@@ -885,10 +886,12 @@ def submit_predict(predict_filepath, task, preset, target_family, opts, job_info
|
|
885 |
predictions = pd.concat([pd.DataFrame(prediction) for prediction in predictions], ignore_index=True)
|
886 |
predictions['Source'] = (f'Predicted ({row["Model"]} '
|
887 |
f'{family.title() if row["Type"] == "Family" else "General"})')
|
888 |
-
|
|
|
889 |
|
890 |
prediction_df = prediction_df.merge(orig_df, on=['X1', 'X2'], how='left', indicator=False)
|
891 |
-
|
|
|
892 |
|
893 |
if "Include Compound Max. Tanimoto Similarity to Training Compounds" in opts:
|
894 |
for family in prediction_df['Target Family'].unique():
|
@@ -1020,6 +1023,7 @@ def update_df(file, progress=gr.Progress(track_tqdm=True)):
|
|
1020 |
|
1021 |
def create_html_report(df, file=None, task=None, opts=(), progress=gr.Progress(track_tqdm=True)):
|
1022 |
df_html = df.copy(deep=True)
|
|
|
1023 |
column_aliases = COLUMN_ALIASES.copy()
|
1024 |
cols_left = list(pd.Index(
|
1025 |
['ID1', 'X1', 'Scaffold SMILES', 'Compound', 'Scaffold', 'ID2', 'X2', 'Y^']).intersection(df_html.columns))
|
@@ -1110,27 +1114,31 @@ def create_html_report(df, file=None, task=None, opts=(), progress=gr.Progress(t
|
|
1110 |
styled_df = df_html.fillna('').style.format(precision=3)
|
1111 |
|
1112 |
for i, col in enumerate(num_cols):
|
|
|
1113 |
if col in df_html.columns:
|
1114 |
if col not in ['Binding Affinity (IC50 [nM])']:
|
|
|
1115 |
styled_df = styled_df.background_gradient(
|
1116 |
-
subset=[col], cmap=
|
1117 |
else:
|
|
|
|
|
1118 |
styled_df = styled_df.background_gradient(
|
1119 |
-
subset=[col], cmap=
|
1120 |
|
1121 |
if any(df_html.columns.isin(bool_cols)):
|
1122 |
-
styled_df.
|
1123 |
|
1124 |
-
table_html = styled_df.to_html(
|
1125 |
unique_html = ''
|
1126 |
if unique_df is not None:
|
1127 |
if 'Target FASTA' in unique_df.columns:
|
1128 |
unique_df['Target FASTA'] = unique_df['Target FASTA'].str.replace('\n', '<br>')
|
1129 |
if any(unique_df.columns.isin(bool_cols)):
|
1130 |
-
unique_df = unique_df.style.
|
1131 |
lambda val: f"background-color: {bool_col_colors[val]}", subset=bool_cols)
|
1132 |
unique_html = (f'<div style="font-family: Courier !important;">'
|
1133 |
-
f'{unique_df.to_html(escape=False, index=False
|
1134 |
|
1135 |
return (f'<div style="font-size: 16px; font-weight: bold;">{job} Report Preview (Top 30 Records)</div>'
|
1136 |
f'<div style="overflow-x:auto; font-family: Courier !important;">{unique_html}</div>'
|
@@ -1176,15 +1184,19 @@ def create_html_report(df, file=None, task=None, opts=(), progress=gr.Progress(t
|
|
1176 |
disabled=True, sizing_mode='stretch_both', pagination='local', page_size=30)
|
1177 |
|
1178 |
for i, col in enumerate(num_cols):
|
|
|
1179 |
if col not in ['Binding Affinity (IC50 [nM])']:
|
1180 |
if col not in ['Interaction Probability']:
|
|
|
1181 |
report_table.style.background_gradient(
|
1182 |
-
subset=df_html.columns == col, cmap=
|
1183 |
else:
|
1184 |
continue
|
1185 |
else:
|
|
|
|
|
1186 |
report_table.style.background_gradient(
|
1187 |
-
subset=df_html.columns == col, cmap=
|
1188 |
|
1189 |
pie_charts = {}
|
1190 |
for y in df_html.columns.intersection(['Interaction Probability', 'Binding Affinity (IC50 [nM])']):
|
|
|
28 |
from rdkit.DataStructs import BulkTanimotoSimilarity
|
29 |
from requests.adapters import HTTPAdapter, Retry
|
30 |
from markdown import markdown
|
31 |
+
from rdkit import Chem
|
32 |
from rdkit.Chem import AllChem, Draw, RDConfig, PandasTools, Descriptors, rdMolDescriptors, rdmolops, Lipinski, Crippen
|
33 |
from rdkit.Chem.Scaffolds import MurckoScaffold
|
34 |
import seaborn as sns
|
|
|
833 |
predictions, _ = predict(cfg)
|
834 |
predictions = pd.concat([pd.DataFrame(prediction) for prediction in predictions], ignore_index=True)
|
835 |
predictions['Source'] = f'Predicted ({preset} {target_family})'
|
836 |
+
df_list = [prediction_df, predictions]
|
837 |
+
prediction_df = pd.concat([df for df in df_list if not df.empty])
|
838 |
|
839 |
else:
|
840 |
predictions_file = f'{SERVER_DATA_DIR}/{job_id}_{task_file_abbr[task]}_family-recommended_predictions.csv'
|
|
|
886 |
predictions = pd.concat([pd.DataFrame(prediction) for prediction in predictions], ignore_index=True)
|
887 |
predictions['Source'] = (f'Predicted ({row["Model"]} '
|
888 |
f'{family.title() if row["Type"] == "Family" else "General"})')
|
889 |
+
df_list = [prediction_df, predictions]
|
890 |
+
prediction_df = pd.concat([df for df in df_list if not df.empty])
|
891 |
|
892 |
prediction_df = prediction_df.merge(orig_df, on=['X1', 'X2'], how='left', indicator=False)
|
893 |
+
df_list = [prediction_df, annotated_df]
|
894 |
+
prediction_df = pd.concat([df for df in df_list if not df.empty], ignore_index=True)
|
895 |
|
896 |
if "Include Compound Max. Tanimoto Similarity to Training Compounds" in opts:
|
897 |
for family in prediction_df['Target Family'].unique():
|
|
|
1023 |
|
1024 |
def create_html_report(df, file=None, task=None, opts=(), progress=gr.Progress(track_tqdm=True)):
|
1025 |
df_html = df.copy(deep=True)
|
1026 |
+
df_html.dropna(how='all', axis=1, inplace=True)
|
1027 |
column_aliases = COLUMN_ALIASES.copy()
|
1028 |
cols_left = list(pd.Index(
|
1029 |
['ID1', 'X1', 'Scaffold SMILES', 'Compound', 'Scaffold', 'ID2', 'X2', 'Y^']).intersection(df_html.columns))
|
|
|
1114 |
styled_df = df_html.fillna('').style.format(precision=3)
|
1115 |
|
1116 |
for i, col in enumerate(num_cols):
|
1117 |
+
cmap = sns.light_palette(num_col_colors[i], as_cmap=True)
|
1118 |
if col in df_html.columns:
|
1119 |
if col not in ['Binding Affinity (IC50 [nM])']:
|
1120 |
+
cmap.set_bad('white')
|
1121 |
styled_df = styled_df.background_gradient(
|
1122 |
+
subset=[col], cmap=cmap)
|
1123 |
else:
|
1124 |
+
cmap = cmap.reversed()
|
1125 |
+
cmap.set_bad('white')
|
1126 |
styled_df = styled_df.background_gradient(
|
1127 |
+
subset=[col], cmap=cmap)
|
1128 |
|
1129 |
if any(df_html.columns.isin(bool_cols)):
|
1130 |
+
styled_df.map(lambda val: f'background-color: {bool_col_colors[val]}', subset=bool_cols)
|
1131 |
|
1132 |
+
table_html = styled_df.to_html()
|
1133 |
unique_html = ''
|
1134 |
if unique_df is not None:
|
1135 |
if 'Target FASTA' in unique_df.columns:
|
1136 |
unique_df['Target FASTA'] = unique_df['Target FASTA'].str.replace('\n', '<br>')
|
1137 |
if any(unique_df.columns.isin(bool_cols)):
|
1138 |
+
unique_df = unique_df.style.map(
|
1139 |
lambda val: f"background-color: {bool_col_colors[val]}", subset=bool_cols)
|
1140 |
unique_html = (f'<div style="font-family: Courier !important;">'
|
1141 |
+
f'{unique_df.to_html(escape=False, index=False)}</div>')
|
1142 |
|
1143 |
return (f'<div style="font-size: 16px; font-weight: bold;">{job} Report Preview (Top 30 Records)</div>'
|
1144 |
f'<div style="overflow-x:auto; font-family: Courier !important;">{unique_html}</div>'
|
|
|
1184 |
disabled=True, sizing_mode='stretch_both', pagination='local', page_size=30)
|
1185 |
|
1186 |
for i, col in enumerate(num_cols):
|
1187 |
+
cmap = sns.light_palette(num_col_colors[i], as_cmap=True)
|
1188 |
if col not in ['Binding Affinity (IC50 [nM])']:
|
1189 |
if col not in ['Interaction Probability']:
|
1190 |
+
cmap.set_bad(color='white')
|
1191 |
report_table.style.background_gradient(
|
1192 |
+
subset=df_html.columns == col, cmap=cmap)
|
1193 |
else:
|
1194 |
continue
|
1195 |
else:
|
1196 |
+
cmap = cmap.reversed()
|
1197 |
+
cmap.set_bad(color='white')
|
1198 |
report_table.style.background_gradient(
|
1199 |
+
subset=df_html.columns == col, cmap=cmap)
|
1200 |
|
1201 |
pie_charts = {}
|
1202 |
for y in df_html.columns.intersection(['Interaction Probability', 'Binding Affinity (IC50 [nM])']):
|