ThorbenF commited on
Commit
50f1c9f
·
1 Parent(s): aae512c

Updated .js and HTML files to dynamically pass sequence to Hugging Face and display scores

Browse files
Files changed (2) hide show
  1. .ipynb_checkpoints/app-checkpoint.py +43 -5
  2. app.py +43 -5
.ipynb_checkpoints/app-checkpoint.py CHANGED
@@ -116,16 +116,54 @@ def predict_protein_sequence(test_one_letter_sequence):
116
 
117
  result_str = "\n".join([f"{aa}: {score:.2f}" for aa, score in zip(test_one_letter_sequence, normalized_scores)])
118
 
 
119
  return result_str
120
 
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  interface = gr.Interface(
123
  fn=predict_protein_sequence,
124
- inputs=gr.Textbox(lines=2, placeholder="Enter protein sequence here..."),
125
- outputs=gr.Textbox(), #gr.JSON(), # Use gr.JSON() for list or array-like outputs
126
- title="Protein sequence - Binding site prediction",
127
- description="Enter a protein sequence to predict its possible binding sites.",
 
 
 
 
 
 
128
  )
129
 
130
- # Launch the app
131
  interface.launch()
 
116
 
117
  result_str = "\n".join([f"{aa}: {score:.2f}" for aa, score in zip(test_one_letter_sequence, normalized_scores)])
118
 
119
+
120
  return result_str
121
 
122
 
123
+ #interface = gr.Interface(
124
+ # fn=predict_protein_sequence,
125
+ # inputs=gr.Textbox(lines=2, placeholder="Enter protein sequence here..."),
126
+ # outputs=gr.Textbox(), #gr.JSON(), # Use gr.JSON() for list or array-like outputs
127
+ # title="Protein sequence - Binding site prediction",
128
+ # description="Enter a protein sequence to predict its possible binding sites.",
129
+ #)
130
+
131
+ # Launch the app
132
+ #interface.launch()
133
+
134
+ # Function to fetch and visualize the PDB structure using py3Dmol
135
+ def fetch_and_display_pdb(pdb_id):
136
+ # Fetch the PDB structure from the RCSB
137
+ pdb_url = f'https://files.rcsb.org/download/{pdb_id}.pdb'
138
+ response = requests.get(pdb_url)
139
+
140
+ if response.status_code == 200:
141
+ pdb_structure = response.text
142
+ else:
143
+ return "Failed to load PDB structure. Please check the PDB ID."
144
+
145
+ # Initialize the viewer
146
+ viewer = py3Dmol.view(width=800, height=400)
147
+ viewer.addModel(pdb_structure, "pdb")
148
+ viewer.setStyle({}, {"cartoon": {"color": "spectrum"}})
149
+ viewer.zoomTo()
150
+
151
+ return viewer._make_html()
152
+
153
+ # Define the Gradio interface
154
  interface = gr.Interface(
155
  fn=predict_protein_sequence,
156
+ inputs=[
157
+ gr.Textbox(lines=2, placeholder="Enter protein sequence here...", label="Protein Sequence"),
158
+ gr.Textbox(lines=1, placeholder="Enter PDB ID here...", label="PDB ID for 3D Visualization")
159
+ ],
160
+ outputs=[
161
+ gr.Textbox(label="Binding Site Predictions"),
162
+ gr.HTML(label="3Dmol Viewer") # HTML output to render the 3Dmol viewer
163
+ ],
164
+ title="Protein Binding Site Prediction and 3D Structure Viewer",
165
+ description="Input a protein sequence to predict binding sites and view the protein structure in 3D using its PDB ID.",
166
  )
167
 
168
+ # Launch the Gradio app
169
  interface.launch()
app.py CHANGED
@@ -116,16 +116,54 @@ def predict_protein_sequence(test_one_letter_sequence):
116
 
117
  result_str = "\n".join([f"{aa}: {score:.2f}" for aa, score in zip(test_one_letter_sequence, normalized_scores)])
118
 
 
119
  return result_str
120
 
121
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  interface = gr.Interface(
123
  fn=predict_protein_sequence,
124
- inputs=gr.Textbox(lines=2, placeholder="Enter protein sequence here..."),
125
- outputs=gr.Textbox(), #gr.JSON(), # Use gr.JSON() for list or array-like outputs
126
- title="Protein sequence - Binding site prediction",
127
- description="Enter a protein sequence to predict its possible binding sites.",
 
 
 
 
 
 
128
  )
129
 
130
- # Launch the app
131
  interface.launch()
 
116
 
117
  result_str = "\n".join([f"{aa}: {score:.2f}" for aa, score in zip(test_one_letter_sequence, normalized_scores)])
118
 
119
+
120
  return result_str
121
 
122
 
123
+ #interface = gr.Interface(
124
+ # fn=predict_protein_sequence,
125
+ # inputs=gr.Textbox(lines=2, placeholder="Enter protein sequence here..."),
126
+ # outputs=gr.Textbox(), #gr.JSON(), # Use gr.JSON() for list or array-like outputs
127
+ # title="Protein sequence - Binding site prediction",
128
+ # description="Enter a protein sequence to predict its possible binding sites.",
129
+ #)
130
+
131
+ # Launch the app
132
+ #interface.launch()
133
+
134
+ # Function to fetch and visualize the PDB structure using py3Dmol
135
+ def fetch_and_display_pdb(pdb_id):
136
+ # Fetch the PDB structure from the RCSB
137
+ pdb_url = f'https://files.rcsb.org/download/{pdb_id}.pdb'
138
+ response = requests.get(pdb_url)
139
+
140
+ if response.status_code == 200:
141
+ pdb_structure = response.text
142
+ else:
143
+ return "Failed to load PDB structure. Please check the PDB ID."
144
+
145
+ # Initialize the viewer
146
+ viewer = py3Dmol.view(width=800, height=400)
147
+ viewer.addModel(pdb_structure, "pdb")
148
+ viewer.setStyle({}, {"cartoon": {"color": "spectrum"}})
149
+ viewer.zoomTo()
150
+
151
+ return viewer._make_html()
152
+
153
+ # Define the Gradio interface
154
  interface = gr.Interface(
155
  fn=predict_protein_sequence,
156
+ inputs=[
157
+ gr.Textbox(lines=2, placeholder="Enter protein sequence here...", label="Protein Sequence"),
158
+ gr.Textbox(lines=1, placeholder="Enter PDB ID here...", label="PDB ID for 3D Visualization")
159
+ ],
160
+ outputs=[
161
+ gr.Textbox(label="Binding Site Predictions"),
162
+ gr.HTML(label="3Dmol Viewer") # HTML output to render the 3Dmol viewer
163
+ ],
164
+ title="Protein Binding Site Prediction and 3D Structure Viewer",
165
+ description="Input a protein sequence to predict binding sites and view the protein structure in 3D using its PDB ID.",
166
  )
167
 
168
+ # Launch the Gradio app
169
  interface.launch()