Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -190,8 +190,7 @@ def rgb_to_hex(rgb):
|
|
190 |
|
191 |
|
192 |
def mol_to_pharm3d(mol, mode='html'):
|
193 |
-
|
194 |
-
return
|
195 |
AllChem.Compute2DCoords(mol)
|
196 |
|
197 |
feats = FEAT_FACTORY.GetFeaturesForMol(mol)
|
@@ -1066,7 +1065,7 @@ def update_df(file, progress=gr.Progress(track_tqdm=True)):
|
|
1066 |
df['Compound'] = df['X1'].parallel_apply(
|
1067 |
lambda smiles: PandasTools._MolPlusFingerprint(Chem.MolFromSmiles(smiles)))
|
1068 |
df['Scaffold'] = df['Compound'].parallel_apply(MurckoScaffold.GetScaffoldForMol)
|
1069 |
-
df['Scaffold SMILES'] = df['Scaffold'].parallel_apply(Chem.MolToSmiles)
|
1070 |
|
1071 |
if task == 'Compound-Protein Binding Affinity':
|
1072 |
# Convert Y^ from pIC50 to IC50
|
@@ -1114,12 +1113,14 @@ def create_html_report(df, file=None, task=None, opts=(), progress=gr.Progress(t
|
|
1114 |
columns_unique = None
|
1115 |
|
1116 |
if 'Compound' in df_html.columns and 'Exclude Molecular Graph' not in opts:
|
1117 |
-
df_html['Compound'] = df_html['Compound'].parallel_apply(
|
|
|
1118 |
else:
|
1119 |
df_html.drop(['Compound'], axis=1, inplace=True)
|
1120 |
|
1121 |
if 'Scaffold' in df_html.columns and 'Exclude Scaffold Graph' not in opts:
|
1122 |
-
df_html['Scaffold'] = df_html['Scaffold'].parallel_apply(
|
|
|
1123 |
else:
|
1124 |
df_html.drop(['Scaffold'], axis=1, inplace=True)
|
1125 |
|
@@ -1148,7 +1149,8 @@ def create_html_report(df, file=None, task=None, opts=(), progress=gr.Progress(t
|
|
1148 |
df_html.rename(columns=column_aliases, inplace=True)
|
1149 |
df_html.index.name = 'Index'
|
1150 |
if 'Target FASTA' in df_html.columns:
|
1151 |
-
df_html['Target FASTA'] = df_html['Target FASTA'].parallel_apply(
|
|
|
1152 |
|
1153 |
num_cols = df_html.select_dtypes('number').columns
|
1154 |
num_col_colors = sns.color_palette('husl', len(num_cols))
|
@@ -1165,7 +1167,8 @@ def create_html_report(df, file=None, task=None, opts=(), progress=gr.Progress(t
|
|
1165 |
if 'Target ID' in df_html.columns:
|
1166 |
df_html.drop(['Target FASTA'], axis=1, inplace=True)
|
1167 |
if 'Target FASTA' in df_html.columns:
|
1168 |
-
df_html['Target FASTA'] = df_html['Target FASTA'].parallel_apply(
|
|
|
1169 |
if 'Scaffold SMILES' in df_html.columns:
|
1170 |
df_html.drop(['Scaffold SMILES'], axis=1, inplace=True)
|
1171 |
styled_df = df_html.fillna('').style.format(precision=3)
|
@@ -1203,7 +1206,8 @@ def create_html_report(df, file=None, task=None, opts=(), progress=gr.Progress(t
|
|
1203 |
|
1204 |
else:
|
1205 |
if 'Exclude Pharmacophore 3D' not in opts:
|
1206 |
-
df_html['Pharmacophore'] = df_html['Compound'].parallel_apply(
|
|
|
1207 |
|
1208 |
image_zoom_formatter = HTMLTemplateFormatter(template='<div class="image-zoom-viewer"><%= value %></div>')
|
1209 |
uniprot_id_formatter = HTMLTemplateFormatter(
|
@@ -1442,10 +1446,12 @@ def submit_report(df, score_list, filter_list, task, progress=gr.Progress(track_
|
|
1442 |
df_report = df.copy()
|
1443 |
try:
|
1444 |
for filter_name in filter_list:
|
1445 |
-
df_report[filter_name] = df_report['Compound'].parallel_apply(
|
|
|
1446 |
|
1447 |
for score_name in score_list:
|
1448 |
-
df_report[score_name] = df_report['Compound'].parallel_apply(
|
|
|
1449 |
|
1450 |
return (create_html_report(df_report, file=None, task=task), df_report,
|
1451 |
gr.File(visible=False), gr.File(visible=False))
|
|
|
190 |
|
191 |
|
192 |
def mol_to_pharm3d(mol, mode='html'):
|
193 |
+
print('pharmco')
|
|
|
194 |
AllChem.Compute2DCoords(mol)
|
195 |
|
196 |
feats = FEAT_FACTORY.GetFeaturesForMol(mol)
|
|
|
1065 |
df['Compound'] = df['X1'].parallel_apply(
|
1066 |
lambda smiles: PandasTools._MolPlusFingerprint(Chem.MolFromSmiles(smiles)))
|
1067 |
df['Scaffold'] = df['Compound'].parallel_apply(MurckoScaffold.GetScaffoldForMol)
|
1068 |
+
df['Scaffold SMILES'] = df['Scaffold'].parallel_apply(lambda x: Chem.MolToSmiles(x))
|
1069 |
|
1070 |
if task == 'Compound-Protein Binding Affinity':
|
1071 |
# Convert Y^ from pIC50 to IC50
|
|
|
1113 |
columns_unique = None
|
1114 |
|
1115 |
if 'Compound' in df_html.columns and 'Exclude Molecular Graph' not in opts:
|
1116 |
+
df_html['Compound'] = df_html['Compound'].parallel_apply(
|
1117 |
+
lambda x: PandasTools.PrintAsImageString(x) if not pd.isna(x) else x)
|
1118 |
else:
|
1119 |
df_html.drop(['Compound'], axis=1, inplace=True)
|
1120 |
|
1121 |
if 'Scaffold' in df_html.columns and 'Exclude Scaffold Graph' not in opts:
|
1122 |
+
df_html['Scaffold'] = df_html['Scaffold'].parallel_apply(
|
1123 |
+
lambda x: PandasTools.PrintAsImageString(x) if not pd.isna(x) else x)
|
1124 |
else:
|
1125 |
df_html.drop(['Scaffold'], axis=1, inplace=True)
|
1126 |
|
|
|
1149 |
df_html.rename(columns=column_aliases, inplace=True)
|
1150 |
df_html.index.name = 'Index'
|
1151 |
if 'Target FASTA' in df_html.columns:
|
1152 |
+
df_html['Target FASTA'] = df_html['Target FASTA'].parallel_apply(
|
1153 |
+
lambda x: wrap_text(x) if not pd.isna(x) else x)
|
1154 |
|
1155 |
num_cols = df_html.select_dtypes('number').columns
|
1156 |
num_col_colors = sns.color_palette('husl', len(num_cols))
|
|
|
1167 |
if 'Target ID' in df_html.columns:
|
1168 |
df_html.drop(['Target FASTA'], axis=1, inplace=True)
|
1169 |
if 'Target FASTA' in df_html.columns:
|
1170 |
+
df_html['Target FASTA'] = df_html['Target FASTA'].parallel_apply(
|
1171 |
+
lambda x: wrap_text(x) if not pd.isna(x) else x)
|
1172 |
if 'Scaffold SMILES' in df_html.columns:
|
1173 |
df_html.drop(['Scaffold SMILES'], axis=1, inplace=True)
|
1174 |
styled_df = df_html.fillna('').style.format(precision=3)
|
|
|
1206 |
|
1207 |
else:
|
1208 |
if 'Exclude Pharmacophore 3D' not in opts:
|
1209 |
+
df_html['Pharmacophore'] = df_html['Compound'].parallel_apply(
|
1210 |
+
lambda x: mol_to_pharm3d(x) if not pd.isna(x) else x)
|
1211 |
|
1212 |
image_zoom_formatter = HTMLTemplateFormatter(template='<div class="image-zoom-viewer"><%= value %></div>')
|
1213 |
uniprot_id_formatter = HTMLTemplateFormatter(
|
|
|
1446 |
df_report = df.copy()
|
1447 |
try:
|
1448 |
for filter_name in filter_list:
|
1449 |
+
df_report[filter_name] = df_report['Compound'].parallel_apply(
|
1450 |
+
lambda x: FILTER_MAP[filter_name](x) if not pd.isna(x) else x)
|
1451 |
|
1452 |
for score_name in score_list:
|
1453 |
+
df_report[score_name] = df_report['Compound'].parallel_apply(
|
1454 |
+
lambda x: SCORE_MAP[score_name](x) if not pd.isna(x) else x)
|
1455 |
|
1456 |
return (create_html_report(df_report, file=None, task=task), df_report,
|
1457 |
gr.File(visible=False), gr.File(visible=False))
|