Update app.py
Browse files
app.py
CHANGED
@@ -11,9 +11,6 @@ from Bio.Seq import Seq
|
|
11 |
from Bio.SeqRecord import SeqRecord
|
12 |
import time
|
13 |
import urllib.parse
|
14 |
-
import base64
|
15 |
-
from IPython.display import Image
|
16 |
-
import io
|
17 |
|
18 |
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
19 |
|
@@ -36,30 +33,7 @@ def render_mol(pdb):
|
|
36 |
pdbview.zoom(2, 800)
|
37 |
pdbview.spin(True)
|
38 |
showmol(pdbview, height=500, width=800)
|
39 |
-
return pdbview
|
40 |
|
41 |
-
def get_protein_image(pdbview):
|
42 |
-
pdbview.zoom(0.8)
|
43 |
-
pdbview.render()
|
44 |
-
|
45 |
-
# Use the JavaScript method to get the PNG data as a base64 encoded string
|
46 |
-
png_base64 = pdbview.js().png()
|
47 |
-
|
48 |
-
print(f"Type of png_base64: {type(png_base64)}")
|
49 |
-
print(f"Length of png_base64: {len(png_base64) if png_base64 else 'N/A'}")
|
50 |
-
|
51 |
-
if png_base64 is None:
|
52 |
-
raise ValueError("Failed to capture image data")
|
53 |
-
|
54 |
-
# If png_base64 is already a string, it's likely already base64 encoded
|
55 |
-
if isinstance(png_base64, str):
|
56 |
-
return png_base64
|
57 |
-
# If it's bytes, we need to encode it
|
58 |
-
elif isinstance(png_base64, bytes):
|
59 |
-
return base64.b64encode(png_base64).decode('utf-8')
|
60 |
-
else:
|
61 |
-
raise TypeError(f"Unexpected type for png_base64: {type(png_base64)}")
|
62 |
-
|
63 |
def perform_blast_analysis(sequence):
|
64 |
st.subheader('Protein Analysis')
|
65 |
with st.spinner("Analyzing generated protein... This may take a few minutes."):
|
@@ -175,14 +149,14 @@ if st.sidebar.button('Generate and Predict'):
|
|
175 |
if st.session_state.structure_info:
|
176 |
info = st.session_state.structure_info
|
177 |
st.subheader(f'Predicted protein structure using seed: {info["word1"]}, {info["word2"]}, and {info["word3"]} + length {info["sequence_length"]}')
|
178 |
-
|
179 |
|
180 |
st.subheader('plDDT Score')
|
181 |
st.write('plDDT is a per-residue estimate of the confidence in prediction on a scale from 0-100%.')
|
182 |
plddt_score = int(info["b_value"] * 100)
|
183 |
st.info(f'Average plDDT: {plddt_score}%')
|
184 |
|
185 |
-
col1, col2
|
186 |
with col1:
|
187 |
if st.button('Analyze Protein'):
|
188 |
perform_blast_analysis(st.session_state.sequence)
|
@@ -194,20 +168,11 @@ if st.session_state.structure_info:
|
|
194 |
file_name='predicted.pdb',
|
195 |
mime='text/plain',
|
196 |
)
|
197 |
-
|
198 |
-
with col3:
|
199 |
-
protein_image = get_protein_image(pdbview)
|
200 |
-
st.download_button(
|
201 |
-
label="Download Image",
|
202 |
-
data=base64.b64decode(protein_image),
|
203 |
-
file_name="protein_structure.png",
|
204 |
-
mime="image/png"
|
205 |
-
)
|
206 |
|
207 |
st.subheader("Share your unique protein on X")
|
208 |
-
st.write("1.
|
209 |
st.write("2. Click the 'Share Results' button below to open a pre-filled tweet.")
|
210 |
-
st.write("3. Attach
|
211 |
|
212 |
tweet_url = share_on_twitter(info["word1"], info["word2"], info["word3"], info["sequence_length"], plddt_score)
|
213 |
st.markdown(f"[Share Results]({tweet_url})")
|
@@ -220,7 +185,6 @@ if st.session_state.structure_info:
|
|
220 |
3. Compare your folded structure with known functional proteins by downloading your results.
|
221 |
4. Read about similar proteins to gain insights into potential functions.
|
222 |
5. Click the "Analyze Protein" button to get more information about your generated protein.
|
223 |
-
|
224 |
**Remember, this folding is based on randomly generated sequences. Interpret the results with caution.
|
225 |
Enjoy exploring the world of protein sequences! Share your high-confidence protein images with us on X [*@WandsAI*](https://x.com/wandsai)!
|
226 |
""")
|
|
|
11 |
from Bio.SeqRecord import SeqRecord
|
12 |
import time
|
13 |
import urllib.parse
|
|
|
|
|
|
|
14 |
|
15 |
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
16 |
|
|
|
33 |
pdbview.zoom(2, 800)
|
34 |
pdbview.spin(True)
|
35 |
showmol(pdbview, height=500, width=800)
|
|
|
36 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
def perform_blast_analysis(sequence):
|
38 |
st.subheader('Protein Analysis')
|
39 |
with st.spinner("Analyzing generated protein... This may take a few minutes."):
|
|
|
149 |
if st.session_state.structure_info:
|
150 |
info = st.session_state.structure_info
|
151 |
st.subheader(f'Predicted protein structure using seed: {info["word1"]}, {info["word2"]}, and {info["word3"]} + length {info["sequence_length"]}')
|
152 |
+
render_mol(info['pdb_string'])
|
153 |
|
154 |
st.subheader('plDDT Score')
|
155 |
st.write('plDDT is a per-residue estimate of the confidence in prediction on a scale from 0-100%.')
|
156 |
plddt_score = int(info["b_value"] * 100)
|
157 |
st.info(f'Average plDDT: {plddt_score}%')
|
158 |
|
159 |
+
col1, col2 = st.columns(2)
|
160 |
with col1:
|
161 |
if st.button('Analyze Protein'):
|
162 |
perform_blast_analysis(st.session_state.sequence)
|
|
|
168 |
file_name='predicted.pdb',
|
169 |
mime='text/plain',
|
170 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
171 |
|
172 |
st.subheader("Share your unique protein on X")
|
173 |
+
st.write("1. Take a screenshot of the protein structure above.")
|
174 |
st.write("2. Click the 'Share Results' button below to open a pre-filled tweet.")
|
175 |
+
st.write("3. Attach your screenshot to the tweet before posting.")
|
176 |
|
177 |
tweet_url = share_on_twitter(info["word1"], info["word2"], info["word3"], info["sequence_length"], plddt_score)
|
178 |
st.markdown(f"[Share Results]({tweet_url})")
|
|
|
185 |
3. Compare your folded structure with known functional proteins by downloading your results.
|
186 |
4. Read about similar proteins to gain insights into potential functions.
|
187 |
5. Click the "Analyze Protein" button to get more information about your generated protein.
|
|
|
188 |
**Remember, this folding is based on randomly generated sequences. Interpret the results with caution.
|
189 |
Enjoy exploring the world of protein sequences! Share your high-confidence protein images with us on X [*@WandsAI*](https://x.com/wandsai)!
|
190 |
""")
|