Accelernate commited on
Commit
651cc8d
·
verified ·
1 Parent(s): cd55a80

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -2
app.py CHANGED
@@ -6,6 +6,10 @@ import biotite.structure.io as bsio
6
  import random
7
  import hashlib
8
  import urllib3
 
 
 
 
9
 
10
  urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
11
 
@@ -31,6 +35,52 @@ def render_mol(pdb):
31
  pdbview.spin(True)
32
  showmol(pdbview, height = 500,width=800)
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  # ESMfold
35
  def update(sequence, word1, word2, word3, sequence_length):
36
  headers = {
@@ -66,6 +116,9 @@ def update(sequence, word1, word2, word3, sequence_length):
66
  file_name='predicted.pdb',
67
  mime='text/plain',
68
  )
 
 
 
69
  except requests.exceptions.RequestException as e:
70
  st.error(f"An error occurred while calling the API: {str(e)}")
71
  st.write("Please try again later or contact support if the issue persists.")
@@ -100,8 +153,6 @@ If you find interesting results from the sequence folding, you can explore furth
100
  2. Visit the [Protein Data Bank (PDB)](https://www.rcsb.org/) for known protein structures.
101
  3. Compare your folded structure with known functional proteins by downloading your results.
102
  4. Read about similar proteins to gain insights into potential functions.
103
-
104
-
105
  **Remember, this folding is based on randomly generated sequences. Interpret the results with caution.
106
  Enjoy exploring the world of protein sequences! Share your high-confidence protein images with us on X [*@WandsAI*](https://x.com/wandsai)!
107
  """)
 
6
  import random
7
  import hashlib
8
  import urllib3
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
 
 
35
  pdbview.spin(True)
36
  showmol(pdbview, height = 500,width=800)
37
 
38
+ # BLAST analysis function
39
+ def perform_blast_analysis(sequence):
40
+ st.subheader('BLAST Analysis')
41
+ with st.spinner("Analyzing generated protein... This may take a few minutes."):
42
+ progress_bar = st.progress(0)
43
+ for i in range(100):
44
+ progress_bar.progress(i + 1)
45
+ if i == 99: # Simulate longer process at the end
46
+ time.sleep(2)
47
+
48
+ try:
49
+ record = SeqRecord(Seq(sequence), id='random_protein')
50
+ result_handle = NCBIWWW.qblast("blastp", "swissprot", record.seq)
51
+
52
+ blast_record = NCBIXML.read(result_handle)
53
+
54
+ st.write('Top BLAST Match:')
55
+ if blast_record.alignments:
56
+ alignment = blast_record.alignments[0] # Get the top hit
57
+ hsp = alignment.hsps[0] # Get the first (best) HSP
58
+
59
+ # Extract protein name and organism
60
+ title_parts = alignment.title.split('|')
61
+ protein_name = title_parts[-1].strip()
62
+ organism = title_parts[-2].split('OS=')[-1].split('OX=')[0].strip()
63
+
64
+ # Calculate identity percentage
65
+ identity_percentage = (hsp.identities / alignment.length) * 100
66
+
67
+ st.write(f"**Protein:** {protein_name}")
68
+ st.write(f"**Organism:** {organism}")
69
+ st.write(f"**Sequence Identity:** {identity_percentage:.2f}%")
70
+
71
+ # Fetch protein function (if available)
72
+ if hasattr(alignment, 'description') and alignment.description:
73
+ st.write(f"**Possible Function:** {alignment.description}")
74
+
75
+ # Link to BLAST
76
+ blast_link = f"https://blast.ncbi.nlm.nih.gov/Blast.cgi?PROGRAM=blastp&PAGE_TYPE=BlastSearch&LINK_LOC=blasthome"
77
+ st.markdown(f"[View full BLAST results]({blast_link})")
78
+ else:
79
+ st.write("No significant matches found.")
80
+ except Exception as e:
81
+ st.error(f"An error occurred during BLAST analysis: {str(e)}")
82
+ st.write("Please try again later or contact support if the issue persists.")
83
+
84
  # ESMfold
85
  def update(sequence, word1, word2, word3, sequence_length):
86
  headers = {
 
116
  file_name='predicted.pdb',
117
  mime='text/plain',
118
  )
119
+
120
+ # Perform BLAST analysis
121
+ perform_blast_analysis(sequence)
122
  except requests.exceptions.RequestException as e:
123
  st.error(f"An error occurred while calling the API: {str(e)}")
124
  st.write("Please try again later or contact support if the issue persists.")
 
153
  2. Visit the [Protein Data Bank (PDB)](https://www.rcsb.org/) for known protein structures.
154
  3. Compare your folded structure with known functional proteins by downloading your results.
155
  4. Read about similar proteins to gain insights into potential functions.
 
 
156
  **Remember, this folding is based on randomly generated sequences. Interpret the results with caution.
157
  Enjoy exploring the world of protein sequences! Share your high-confidence protein images with us on X [*@WandsAI*](https://x.com/wandsai)!
158
  """)