Update app.py
Browse files
app.py
CHANGED
@@ -36,43 +36,54 @@ def render_mol(pdb):
|
|
36 |
|
37 |
def perform_blast_analysis(sequence):
|
38 |
st.subheader('Protein Analysis')
|
39 |
-
with st.spinner("Analyzing generated protein... This may take
|
40 |
progress_bar = st.progress(0)
|
|
|
|
|
41 |
for i in range(100):
|
42 |
progress_bar.progress(i + 1)
|
43 |
-
time.sleep(0.
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
if blast_record.alignments:
|
52 |
-
alignment = blast_record.alignments[0] # Get the top hit
|
53 |
-
hsp = alignment.hsps[0] # Get the first (best) HSP
|
54 |
|
55 |
-
|
56 |
-
title_parts = alignment.title.split('|')
|
57 |
-
protein_name = title_parts[-1].strip()
|
58 |
-
organism = title_parts[-2].split('OS=')[-1].split('OX=')[0].strip()
|
59 |
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
st.
|
71 |
-
|
72 |
-
st.write("No significant matches found. This might be a unique protein sequence!")
|
73 |
-
except Exception as e:
|
74 |
-
st.error(f"An error occurred during protein analysis: {str(e)}")
|
75 |
-
st.write("Please try again later or contact support if the issue persists.")
|
76 |
|
77 |
def update(sequence, word1, word2, word3, sequence_length):
|
78 |
headers = {
|
|
|
36 |
|
37 |
def perform_blast_analysis(sequence):
|
38 |
st.subheader('Protein Analysis')
|
39 |
+
with st.spinner("Analyzing generated protein... This may take several minutes. Stay tuned!"):
|
40 |
progress_bar = st.progress(0)
|
41 |
+
|
42 |
+
# Slow down the progress bar
|
43 |
for i in range(100):
|
44 |
progress_bar.progress(i + 1)
|
45 |
+
time.sleep(0.3) # Increased sleep time to 0.3 seconds
|
46 |
|
47 |
+
max_retries = 3
|
48 |
+
for attempt in range(max_retries):
|
49 |
+
try:
|
50 |
+
Entrez.email = "[email protected]" # Replace with your email
|
51 |
+
record = SeqRecord(Seq(sequence), id='random_protein')
|
52 |
+
result_handle = NCBIWWW.qblast("blastp", "swissprot", record.seq, expect=10, hitlist_size=1)
|
|
|
|
|
|
|
53 |
|
54 |
+
blast_record = NCBIXML.read(result_handle)
|
|
|
|
|
|
|
55 |
|
56 |
+
if blast_record.alignments:
|
57 |
+
alignment = blast_record.alignments[0] # Get the top hit
|
58 |
+
hsp = alignment.hsps[0] # Get the first (best) HSP
|
59 |
+
|
60 |
+
# Extract protein name and organism
|
61 |
+
title_parts = alignment.title.split('|')
|
62 |
+
protein_name = title_parts[-1].strip()
|
63 |
+
organism = title_parts[-2].split('OS=')[-1].split('OX=')[0].strip()
|
64 |
+
|
65 |
+
# Calculate identity percentage
|
66 |
+
identity_percentage = (hsp.identities / alignment.length) * 100
|
67 |
+
|
68 |
+
st.write(f"**Top Match:** {protein_name}")
|
69 |
+
st.write(f"**Organism:** {organism}")
|
70 |
+
st.write(f"**Sequence Identity:** {identity_percentage:.2f}%")
|
71 |
+
|
72 |
+
# Fetch protein function (if available)
|
73 |
+
if hasattr(alignment, 'description') and alignment.description:
|
74 |
+
st.write(f"**Potential Function:** {alignment.description}")
|
75 |
+
else:
|
76 |
+
st.write("No significant matches found. This might be a unique protein sequence!")
|
77 |
|
78 |
+
break # If successful, exit the retry loop
|
79 |
+
|
80 |
+
except Exception as e:
|
81 |
+
if attempt < max_retries - 1:
|
82 |
+
st.warning(f"Attempt {attempt + 1} failed. Retrying...")
|
83 |
+
time.sleep(random.uniform(1, 3)) # Add a random delay between retries
|
84 |
+
else:
|
85 |
+
st.error(f"An error occurred during protein analysis after {max_retries} attempts: {str(e)}")
|
86 |
+
st.write("Please try again later BLAST could be experiencing server issues.")
|
|
|
|
|
|
|
|
|
87 |
|
88 |
def update(sequence, word1, word2, word3, sequence_length):
|
89 |
headers = {
|