Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
| 2 |
import py3Dmol
|
| 3 |
import requests
|
| 4 |
import biotite.structure.io as bsio
|
|
@@ -12,7 +13,6 @@ import time
|
|
| 12 |
import urllib.parse
|
| 13 |
import base64
|
| 14 |
|
| 15 |
-
|
| 16 |
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
| 17 |
|
| 18 |
st.set_page_config(layout='wide')
|
|
@@ -26,14 +26,21 @@ def generate_sequence_from_words(words, length):
|
|
| 26 |
return ''.join(random.choice(amino_acids) for _ in range(length))
|
| 27 |
|
| 28 |
def render_mol(pdb):
|
| 29 |
-
pdbview = py3Dmol.view()
|
| 30 |
-
pdbview.addModel(pdb,'pdb')
|
| 31 |
-
pdbview.setStyle({'cartoon':{'color':'spectrum'}})
|
| 32 |
pdbview.setBackgroundColor('white')
|
| 33 |
pdbview.zoomTo()
|
| 34 |
pdbview.zoom(2, 800)
|
| 35 |
pdbview.spin(True)
|
| 36 |
-
showmol(pdbview, height
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
def perform_blast_analysis(sequence):
|
| 39 |
st.subheader('Protein Analysis')
|
|
@@ -113,6 +120,11 @@ def update(sequence, word1, word2, word3, sequence_length):
|
|
| 113 |
st.error(f"An error occurred while calling the API: {str(e)}")
|
| 114 |
st.write("Please try again later or contact support if the issue persists.")
|
| 115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
# Initialize session state variables
|
| 117 |
if 'sequence' not in st.session_state:
|
| 118 |
st.session_state.sequence = None
|
|
@@ -142,45 +154,6 @@ if st.sidebar.button('Generate and Predict'):
|
|
| 142 |
st.sidebar.warning("Please enter all three words to generate a sequence.")
|
| 143 |
|
| 144 |
# Display structure information if available
|
| 145 |
-
if st.session_state.structure_info:
|
| 146 |
-
info = st.session_state.structure_info
|
| 147 |
-
st.subheader(f'Predicted protein structure using seed: {info["word1"]}, {info["word2"]}, and {info["word3"]} + length {info["sequence_length"]}')
|
| 148 |
-
render_mol(info['pdb_string'])
|
| 149 |
-
|
| 150 |
-
st.subheader('plDDT Score')
|
| 151 |
-
st.write('plDDT is a per-residue estimate of the confidence in prediction on a scale from 0-100%.')
|
| 152 |
-
st.info(f'Average plDDT: {int(info["b_value"] * 100)}%')
|
| 153 |
-
|
| 154 |
-
st.download_button(
|
| 155 |
-
label="Download PDB",
|
| 156 |
-
data=info['pdb_string'],
|
| 157 |
-
file_name='predicted.pdb',
|
| 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"]}')
|
|
@@ -221,7 +194,6 @@ if st.session_state.structure_info:
|
|
| 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:
|
|
@@ -229,13 +201,8 @@ if st.session_state.structure_info:
|
|
| 229 |
2. Visit the [Protein Data Bank (PDB)](https://www.rcsb.org/) for known protein structures.
|
| 230 |
3. Compare your folded structure with known functional proteins by downloading your results.
|
| 231 |
4. Read about similar proteins to gain insights into potential functions.
|
| 232 |
-
5. Click the "Analyze Protein" button
|
| 233 |
|
| 234 |
**Remember, this folding is based on randomly generated sequences. Interpret the results with caution.
|
| 235 |
Enjoy exploring the world of protein sequences! Share your high-confidence protein images with us on X [*@WandsAI*](https://x.com/wandsai)!
|
| 236 |
-
""")
|
| 237 |
-
|
| 238 |
-
# Show the Analyze Protein button if a sequence has been generated
|
| 239 |
-
if st.session_state.show_analyze_button:
|
| 240 |
-
if st.button('Analyze Protein'):
|
| 241 |
-
perform_blast_analysis(st.session_state.sequence)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from stmol import showmol
|
| 3 |
import py3Dmol
|
| 4 |
import requests
|
| 5 |
import biotite.structure.io as bsio
|
|
|
|
| 13 |
import urllib.parse
|
| 14 |
import base64
|
| 15 |
|
|
|
|
| 16 |
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
| 17 |
|
| 18 |
st.set_page_config(layout='wide')
|
|
|
|
| 26 |
return ''.join(random.choice(amino_acids) for _ in range(length))
|
| 27 |
|
| 28 |
def render_mol(pdb):
|
| 29 |
+
pdbview = py3Dmol.view(width=800, height=500)
|
| 30 |
+
pdbview.addModel(pdb, 'pdb')
|
| 31 |
+
pdbview.setStyle({'cartoon': {'color': 'spectrum'}})
|
| 32 |
pdbview.setBackgroundColor('white')
|
| 33 |
pdbview.zoomTo()
|
| 34 |
pdbview.zoom(2, 800)
|
| 35 |
pdbview.spin(True)
|
| 36 |
+
showmol(pdbview, height=500, width=800)
|
| 37 |
+
return pdbview
|
| 38 |
+
|
| 39 |
+
def get_protein_image(pdbview):
|
| 40 |
+
pdbview.zoom(0.8)
|
| 41 |
+
pdbview.render()
|
| 42 |
+
png = pdbview.pngImage()
|
| 43 |
+
return base64.b64encode(png).decode('utf-8')
|
| 44 |
|
| 45 |
def perform_blast_analysis(sequence):
|
| 46 |
st.subheader('Protein Analysis')
|
|
|
|
| 120 |
st.error(f"An error occurred while calling the API: {str(e)}")
|
| 121 |
st.write("Please try again later or contact support if the issue persists.")
|
| 122 |
|
| 123 |
+
def share_on_twitter(word1, word2, word3, length, plddt):
|
| 124 |
+
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"
|
| 125 |
+
tweet_url = f"https://twitter.com/intent/tweet?text={urllib.parse.quote(tweet_text)}"
|
| 126 |
+
return tweet_url
|
| 127 |
+
|
| 128 |
# Initialize session state variables
|
| 129 |
if 'sequence' not in st.session_state:
|
| 130 |
st.session_state.sequence = None
|
|
|
|
| 154 |
st.sidebar.warning("Please enter all three words to generate a sequence.")
|
| 155 |
|
| 156 |
# Display structure information if available
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
if st.session_state.structure_info:
|
| 158 |
info = st.session_state.structure_info
|
| 159 |
st.subheader(f'Predicted protein structure using seed: {info["word1"]}, {info["word2"]}, and {info["word3"]} + length {info["sequence_length"]}')
|
|
|
|
| 194 |
tweet_url = share_on_twitter(info["word1"], info["word2"], info["word3"], info["sequence_length"], plddt_score)
|
| 195 |
st.markdown(f"[Share Results]({tweet_url})")
|
| 196 |
|
|
|
|
| 197 |
st.markdown("""
|
| 198 |
## What to do next:
|
| 199 |
If you find interesting results from the sequence folding, you can explore further:
|
|
|
|
| 201 |
2. Visit the [Protein Data Bank (PDB)](https://www.rcsb.org/) for known protein structures.
|
| 202 |
3. Compare your folded structure with known functional proteins by downloading your results.
|
| 203 |
4. Read about similar proteins to gain insights into potential functions.
|
| 204 |
+
5. Click the "Analyze Protein" button to get more information about your generated protein.
|
| 205 |
|
| 206 |
**Remember, this folding is based on randomly generated sequences. Interpret the results with caution.
|
| 207 |
Enjoy exploring the world of protein sequences! Share your high-confidence protein images with us on X [*@WandsAI*](https://x.com/wandsai)!
|
| 208 |
+
""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|