libokj commited on
Commit
5702a81
·
verified ·
1 Parent(s): d819893

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -13
app.py CHANGED
@@ -164,10 +164,10 @@ class View3DmolCell(py3Dmol.view):
164
  def __init__(self, width=640, height=480):
165
  divid = "3dmolviewer_UNIQUEID"
166
  self.uniqueid = None
167
- if type(width) == int:
168
- width = '%dpx'%width
169
- if type(height) == int:
170
- height = '%dpx'%height
171
  self.startjs = '''<div id="%s" style="position: relative; width: %s; height: %s;">
172
  </div>\n''' % (divid, width, height)
173
  self.startjs += '<script>\n'
@@ -192,15 +192,14 @@ def rgb_to_hex(rgb):
192
  def mol_to_pharm3d(mol, mode='html'):
193
  AllChem.Compute2DCoords(mol)
194
 
195
- feat_factory = AllChem.BuildFeatureFactory(os.path.join(RDConfig.RDDataDir, 'BaseFeatures.fdef'))
196
- feats = feat_factory.GetFeaturesForMol(mol)
197
 
198
  view = View3DmolCell(width=400, height=400)
199
  for feat in feats:
200
  pos = feat.GetPos()
201
  color = _featColors.get(feat.GetFamily(), (.5, .5, .5))
202
  view.addSphere({
203
- 'center': {'x': pos.x,'y': pos.y,'z': pos.z},
204
  'radius': 0.5,
205
  'color': rgb_to_hex(color)
206
  })
@@ -210,9 +209,8 @@ def mol_to_pharm3d(mol, mode='html'):
210
  view.setStyle({'stick': {}})
211
  view.zoomTo()
212
 
213
- match mode:
214
- case 'html':
215
- return view.write_html()
216
  # case 'png':
217
  # return view.png()
218
 
@@ -1208,7 +1206,7 @@ def create_html_report(df, file=None, task=None, opts=(), progress=gr.Progress(t
1208
  else:
1209
  if 'Exclude Pharmacophore 3D' not in opts:
1210
  df_html['Pharmacophore'] = df_html['Compound'].parallel_apply(
1211
- lambda x: mol_to_pharm3d(x, mode='html') if not pd.isna(x) else x)
1212
 
1213
  image_zoom_formatter = HTMLTemplateFormatter(template='<div class="image-zoom-viewer"><%= value %></div>')
1214
  uniprot_id_formatter = HTMLTemplateFormatter(
@@ -1931,7 +1929,11 @@ with gr.Blocks(theme=theme, title='DeepSEQreen', css=CSS, delete_cache=(3600, 48
1931
  csv_sep = gr.Radio(label='CSV Delimiter',
1932
  choices=['Comma', 'Tab'], value='Comma')
1933
  html_opts = gr.CheckboxGroup(label='HTML Report Options',
1934
- choices=['Exclude Molecular Graph', 'Exclude Scaffold Graph'])
 
 
 
 
1935
 
1936
  with gr.Row():
1937
  report_clr_btn = gr.ClearButton(size='lg')
@@ -2111,6 +2113,7 @@ with gr.Blocks(theme=theme, title='DeepSEQreen', css=CSS, delete_cache=(3600, 48
2111
  show_progress='hidden'
2112
  )
2113
 
 
2114
  def example_fill(input_type):
2115
  return {target_id: 'Q16539',
2116
  target_gene: 'MAPK14',
@@ -2537,6 +2540,7 @@ QALAHAYFAQYHDPDDEPVADPYDQSFESRDLLIDEWKSLTYDEVISFVPPPLDQEEMES
2537
  else:
2538
  return preset
2539
 
 
2540
  def update_family(family, preset):
2541
  if preset == 'Family-Specific Auto-Recommendation':
2542
  return 'Family-Specific Auto-Recommendation'
@@ -2545,6 +2549,7 @@ QALAHAYFAQYHDPDDEPVADPYDQSFESRDLLIDEWKSLTYDEVISFVPPPLDQEEMES
2545
  else:
2546
  return family
2547
 
 
2548
  target_identify_target_family.change(
2549
  fn=update_preset, inputs=[target_identify_target_family, target_identify_preset],
2550
  outputs=target_identify_preset, show_progress='hidden')
@@ -2727,7 +2732,6 @@ QALAHAYFAQYHDPDDEPVADPYDQSFESRDLLIDEWKSLTYDEVISFVPPPLDQEEMES
2727
  ).then(fn=create_html_report_file, inputs=[report_df, file_for_report, report_task, html_opts],
2728
  outputs=html_download_file, show_progress='full')
2729
 
2730
-
2731
  if __name__ == "__main__":
2732
  pandarallel.initialize()
2733
 
 
164
  def __init__(self, width=640, height=480):
165
  divid = "3dmolviewer_UNIQUEID"
166
  self.uniqueid = None
167
+ if isinstance(width, int):
168
+ width = '%dpx' % width
169
+ if isinstance(width, int):
170
+ height = '%dpx' % height
171
  self.startjs = '''<div id="%s" style="position: relative; width: %s; height: %s;">
172
  </div>\n''' % (divid, width, height)
173
  self.startjs += '<script>\n'
 
192
  def mol_to_pharm3d(mol, mode='html'):
193
  AllChem.Compute2DCoords(mol)
194
 
195
+ feats = FEAT_FACTORY.GetFeaturesForMol(mol)
 
196
 
197
  view = View3DmolCell(width=400, height=400)
198
  for feat in feats:
199
  pos = feat.GetPos()
200
  color = _featColors.get(feat.GetFamily(), (.5, .5, .5))
201
  view.addSphere({
202
+ 'center': {'x': pos.x, 'y': pos.y, 'z': pos.z},
203
  'radius': 0.5,
204
  'color': rgb_to_hex(color)
205
  })
 
209
  view.setStyle({'stick': {}})
210
  view.zoomTo()
211
 
212
+ if mode == 'html':
213
+ return view.write_html()
 
214
  # case 'png':
215
  # return view.png()
216
 
 
1206
  else:
1207
  if 'Exclude Pharmacophore 3D' not in opts:
1208
  df_html['Pharmacophore'] = df_html['Compound'].parallel_apply(
1209
+ lambda x: mol_to_pharm3d(x) if not pd.isna(x) else x)
1210
 
1211
  image_zoom_formatter = HTMLTemplateFormatter(template='<div class="image-zoom-viewer"><%= value %></div>')
1212
  uniprot_id_formatter = HTMLTemplateFormatter(
 
1929
  csv_sep = gr.Radio(label='CSV Delimiter',
1930
  choices=['Comma', 'Tab'], value='Comma')
1931
  html_opts = gr.CheckboxGroup(label='HTML Report Options',
1932
+ choices=[
1933
+ 'Exclude Molecular Graph',
1934
+ 'Exclude Scaffold Graph',
1935
+ 'Exclude Pharmacophore 3D'
1936
+ ])
1937
 
1938
  with gr.Row():
1939
  report_clr_btn = gr.ClearButton(size='lg')
 
2113
  show_progress='hidden'
2114
  )
2115
 
2116
+
2117
  def example_fill(input_type):
2118
  return {target_id: 'Q16539',
2119
  target_gene: 'MAPK14',
 
2540
  else:
2541
  return preset
2542
 
2543
+
2544
  def update_family(family, preset):
2545
  if preset == 'Family-Specific Auto-Recommendation':
2546
  return 'Family-Specific Auto-Recommendation'
 
2549
  else:
2550
  return family
2551
 
2552
+
2553
  target_identify_target_family.change(
2554
  fn=update_preset, inputs=[target_identify_target_family, target_identify_preset],
2555
  outputs=target_identify_preset, show_progress='hidden')
 
2732
  ).then(fn=create_html_report_file, inputs=[report_df, file_for_report, report_task, html_opts],
2733
  outputs=html_download_file, show_progress='full')
2734
 
 
2735
  if __name__ == "__main__":
2736
  pandarallel.initialize()
2737