emmas96 commited on
Commit
1753f35
·
1 Parent(s): 601b6c8

new attempt at displaying protein

Browse files
Files changed (1) hide show
  1. app.py +28 -35
app.py CHANGED
@@ -51,7 +51,7 @@ def about_page():
51
  def predict_dti():
52
  st.markdown('## Predict drug-target interaction')
53
 
54
- st.text('In the future this page can be used to predict interactions betweek a query drug compound and a query protein target by the HyperPCM mdoel.')
55
 
56
  col1, col2 = st.columns(2)
57
 
@@ -173,7 +173,7 @@ def predict_dti():
173
  my_bar.progress(100, text="HyperPCM predicts the interaction between the query drug compound toward the query protein target. Done.")
174
 
175
  st.markdown('### Interaction')
176
- st.text('HyperPCM predicts an activity of xxx pChEMBL.')
177
 
178
 
179
  def retrieval():
@@ -242,11 +242,11 @@ def display_protein():
242
  sequence = st.text_input('Enter the amino-acid sequence of the query protein target', value='HXHVWPVQDAKARFSEFLDACITEGPQIVSRRGAEEAVLVPIGEWRRLQAAA', placeholder='HXHVWPVQDAKARFSEFLDACITEGPQIVSRRGAEEAVLVPIGEWRRLQAAA')
243
 
244
  if sequence:
245
- model = esm.pretrained.esmfold_v1()
246
- model = model.eval().cuda()
247
 
248
- with torch.no_grad():
249
- output = model.infer_pdb(sequence)
250
 
251
  #with open("result.pdb", "w") as f:
252
  # f.write(output)
@@ -255,14 +255,11 @@ def display_protein():
255
  #struct = bsio.load_structure("result.pdb", extra_fields=["b_factor"])
256
  #print(struct.b_factor.mean())
257
 
258
- st.write(output)
259
-
260
- """
261
- sequence = st.text_input("Enter the amino-acid sequence of the query protein target", value="HXHVWPVQDAKARFSEFLDACITEGPQIVSRRGAEEAVLVPIGEWRRLQAAA", placeholder="HXHVWPVQDAKARFSEFLDACITEGPQIVSRRGAEEAVLVPIGEWRRLQAAA")
262
-
263
- if sequence:
264
- def esm_search(model, sequnce, batch_converter,top_k=5):
265
- batch_labels, batch_strs, batch_tokens = batch_converter([("protein1", sequnce),])
266
 
267
  # Extract per-residue representations (on CPU)
268
  with torch.no_grad():
@@ -284,9 +281,6 @@ def display_protein():
284
 
285
  result_temp_seq = list(set(result_temp_seq))
286
 
287
- result_temp_seq = esm_search(model, sequence, esm_search,top_k=5)
288
- st.text('search result: ')
289
- # tab1, tab2, tab3, tab4, = st.tabs(["Cat", "Dog", "Owl"])
290
  if st.button(result_temp_seq[0]):
291
  print(result_temp_seq[0])
292
  elif st.button(result_temp_seq[1]):
@@ -299,26 +293,25 @@ def display_protein():
299
  print(result_temp_seq[4])
300
 
301
  start[2] = st.pyplot(visualize_3D_Coordinates(result_temp_coords).figure)
302
- def show_protein_structure(sequence):
303
- headers = {
304
- 'Content-Type': 'application/x-www-form-urlencoded',
305
- }
306
- response = requests.post('https://api.esmatlas.com/foldSequence/v1/pdb/', headers=headers, data=sequence)
307
- name = sequence[:3] + sequence[-3:]
308
- pdb_string = response.content.decode('utf-8')
309
- with open('predicted.pdb', 'w') as f:
310
- f.write(pdb_string)
311
- struct = bsio.load_structure('predicted.pdb', extra_fields=["b_factor"])
312
- b_value = round(struct.b_factor.mean(), 4)
313
- render_mol(pdb_string)
314
- if residues_marker:
315
- start[3] = showmol(render_pdb_resn(viewer = render_pdb(id = id_PDB),resn_lst = [residues_marker]))
316
- else:
317
- start[3] = showmol(render_pdb(id = id_PDB))
318
- st.session_state['xq'] = st.session_state.model
319
 
320
  # example proteins ["HXHVWPVQDAKARFSEFLDACITEGPQIVSRRGAEEAVLVPIGEWRRLQAAA"], ["AHKLFIGGLPNYLNDDQVKELLTSFGPLKAFNLVKDSATGLSKGYAFCEYVDINVTDQAIAGLNGMQLGDKKLLVQRASVGAKNA"]
321
- """
322
 
323
  def display_context():
324
  st.markdown('## Display context')
 
51
  def predict_dti():
52
  st.markdown('## Predict drug-target interaction')
53
 
54
+ st.write('In the future this page can be used to predict interactions betweek a query drug compound and a query protein target by the HyperPCM mdoel.')
55
 
56
  col1, col2 = st.columns(2)
57
 
 
173
  my_bar.progress(100, text="HyperPCM predicts the interaction between the query drug compound toward the query protein target. Done.")
174
 
175
  st.markdown('### Interaction')
176
+ st.write('HyperPCM predicts an activity of xxx pChEMBL.')
177
 
178
 
179
  def retrieval():
 
242
  sequence = st.text_input('Enter the amino-acid sequence of the query protein target', value='HXHVWPVQDAKARFSEFLDACITEGPQIVSRRGAEEAVLVPIGEWRRLQAAA', placeholder='HXHVWPVQDAKARFSEFLDACITEGPQIVSRRGAEEAVLVPIGEWRRLQAAA')
243
 
244
  if sequence:
245
+ #model = esm.pretrained.esmfold_v1()
246
+ #model = model.eval().cuda()
247
 
248
+ #with torch.no_grad():
249
+ # output = model.infer_pdb(sequence)
250
 
251
  #with open("result.pdb", "w") as f:
252
  # f.write(output)
 
255
  #struct = bsio.load_structure("result.pdb", extra_fields=["b_factor"])
256
  #print(struct.b_factor.mean())
257
 
258
+ #st.write(output)
259
+
260
+ model, alphabet = esm.pretrained.esm2_t33_650M_UR50D()
261
+ batch_converter = alphabet.get_batch_converter()
262
+ batch_labels, batch_strs, batch_tokens = batch_converter([("protein1", sequence),])
 
 
 
263
 
264
  # Extract per-residue representations (on CPU)
265
  with torch.no_grad():
 
281
 
282
  result_temp_seq = list(set(result_temp_seq))
283
 
 
 
 
284
  if st.button(result_temp_seq[0]):
285
  print(result_temp_seq[0])
286
  elif st.button(result_temp_seq[1]):
 
293
  print(result_temp_seq[4])
294
 
295
  start[2] = st.pyplot(visualize_3D_Coordinates(result_temp_coords).figure)
296
+
297
+ headers = {
298
+ 'Content-Type': 'application/x-www-form-urlencoded',
299
+ }
300
+ response = requests.post('https://api.esmatlas.com/foldSequence/v1/pdb/', headers=headers, data=sequence)
301
+ name = sequence[:3] + sequence[-3:]
302
+ pdb_string = response.content.decode('utf-8')
303
+ with open('predicted.pdb', 'w') as f:
304
+ f.write(pdb_string)
305
+ struct = bsio.load_structure('predicted.pdb', extra_fields=["b_factor"])
306
+ b_value = round(struct.b_factor.mean(), 4)
307
+ render_mol(pdb_string)
308
+ if residues_marker:
309
+ start[3] = showmol(render_pdb_resn(viewer = render_pdb(id = id_PDB),resn_lst = [residues_marker]))
310
+ else:
311
+ start[3] = showmol(render_pdb(id = id_PDB))
312
+ st.session_state['xq'] = st.session_state.model
313
 
314
  # example proteins ["HXHVWPVQDAKARFSEFLDACITEGPQIVSRRGAEEAVLVPIGEWRRLQAAA"], ["AHKLFIGGLPNYLNDDQVKELLTSFGPLKAFNLVKDSATGLSKGYAFCEYVDINVTDQAIAGLNGMQLGDKKLLVQRASVGAKNA"]
 
315
 
316
  def display_context():
317
  st.markdown('## Display context')