Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
import streamlit as st
|
2 |
-
from stmol import showmol
|
3 |
import py3Dmol
|
4 |
import requests
|
5 |
import biotite.structure.io as bsio
|
@@ -10,6 +9,9 @@ from Bio.Blast import NCBIWWW, NCBIXML
|
|
10 |
from Bio.Seq import Seq
|
11 |
from Bio.SeqRecord import SeqRecord
|
12 |
import time
|
|
|
|
|
|
|
13 |
|
14 |
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
15 |
|
@@ -156,6 +158,70 @@ if st.session_state.structure_info:
|
|
156 |
mime='text/plain',
|
157 |
)
|
158 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
159 |
st.markdown("""
|
160 |
## What to do next:
|
161 |
If you find interesting results from the sequence folding, you can explore further:
|
|
|
1 |
import streamlit as st
|
|
|
2 |
import py3Dmol
|
3 |
import requests
|
4 |
import biotite.structure.io as bsio
|
|
|
9 |
from Bio.Seq import Seq
|
10 |
from Bio.SeqRecord import SeqRecord
|
11 |
import time
|
12 |
+
import urllib.parse
|
13 |
+
import base64
|
14 |
+
|
15 |
|
16 |
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
17 |
|
|
|
158 |
mime='text/plain',
|
159 |
)
|
160 |
|
161 |
+
def render_mol(pdb):
|
162 |
+
pdbview = py3Dmol.view(width=800, height=500)
|
163 |
+
pdbview.addModel(pdb, 'pdb')
|
164 |
+
pdbview.setStyle({'cartoon': {'color': 'spectrum'}})
|
165 |
+
pdbview.setBackgroundColor('white')
|
166 |
+
pdbview.zoomTo()
|
167 |
+
pdbview.zoom(2, 800)
|
168 |
+
pdbview.spin(True)
|
169 |
+
showmol(pdbview, height=500, width=800)
|
170 |
+
return pdbview
|
171 |
+
|
172 |
+
def get_protein_image(pdbview):
|
173 |
+
pdbview.zoom(0.8)
|
174 |
+
pdbview.render()
|
175 |
+
png = pdbview.pngImage()
|
176 |
+
return base64.b64encode(png).decode('utf-8')
|
177 |
+
|
178 |
+
def share_on_twitter(word1, word2, word3, length, plddt):
|
179 |
+
tweet_text = f"I generated a unique protein structure from the words '{word1}', '{word2}', and '{word3}' with length {length}! plDDT Score: {plddt}% Try it yourself at [Your App URL] #GenPro2 #ProteinFolding"
|
180 |
+
tweet_url = f"https://twitter.com/intent/tweet?text={urllib.parse.quote(tweet_text)}"
|
181 |
+
return tweet_url
|
182 |
+
|
183 |
+
# In the main app code, modify the structure display section:
|
184 |
+
if st.session_state.structure_info:
|
185 |
+
info = st.session_state.structure_info
|
186 |
+
st.subheader(f'Predicted protein structure using seed: {info["word1"]}, {info["word2"]}, and {info["word3"]} + length {info["sequence_length"]}')
|
187 |
+
pdbview = render_mol(info['pdb_string'])
|
188 |
+
|
189 |
+
st.subheader('plDDT Score')
|
190 |
+
st.write('plDDT is a per-residue estimate of the confidence in prediction on a scale from 0-100%.')
|
191 |
+
plddt_score = int(info["b_value"] * 100)
|
192 |
+
st.info(f'Average plDDT: {plddt_score}%')
|
193 |
+
|
194 |
+
col1, col2, col3 = st.columns(3)
|
195 |
+
with col1:
|
196 |
+
if st.button('Analyze Protein'):
|
197 |
+
perform_blast_analysis(st.session_state.sequence)
|
198 |
+
|
199 |
+
with col2:
|
200 |
+
st.download_button(
|
201 |
+
label="Download PDB",
|
202 |
+
data=info['pdb_string'],
|
203 |
+
file_name='predicted.pdb',
|
204 |
+
mime='text/plain',
|
205 |
+
)
|
206 |
+
|
207 |
+
with col3:
|
208 |
+
protein_image = get_protein_image(pdbview)
|
209 |
+
st.download_button(
|
210 |
+
label="Download Image",
|
211 |
+
data=base64.b64decode(protein_image),
|
212 |
+
file_name="protein_structure.png",
|
213 |
+
mime="image/png"
|
214 |
+
)
|
215 |
+
|
216 |
+
st.subheader("Share your unique protein on X")
|
217 |
+
st.write("1. Download the protein image using the 'Download Image' button above.")
|
218 |
+
st.write("2. Click the 'Share Results' button below to open a pre-filled tweet.")
|
219 |
+
st.write("3. Attach the downloaded image to your tweet before posting.")
|
220 |
+
|
221 |
+
tweet_url = share_on_twitter(info["word1"], info["word2"], info["word3"], info["sequence_length"], plddt_score)
|
222 |
+
st.markdown(f"[Share Results]({tweet_url})")
|
223 |
+
|
224 |
+
|
225 |
st.markdown("""
|
226 |
## What to do next:
|
227 |
If you find interesting results from the sequence folding, you can explore further:
|