Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import primer3
|
|
| 4 |
from Bio import SeqIO
|
| 5 |
import os
|
| 6 |
from io import StringIO
|
|
|
|
| 7 |
|
| 8 |
# Ensure the 'temp' directory exists for saving temporary files
|
| 9 |
temp_dir = "temp"
|
|
@@ -13,36 +14,20 @@ os.makedirs(temp_dir, exist_ok=True)
|
|
| 13 |
st.set_page_config(page_title="PCR Primer Design", page_icon="🧬", layout="wide")
|
| 14 |
uploaded_file = st.file_uploader("Upload a GenBank file", type=['gb', 'gbk'])
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
"""Design primers for a specific sequence."""
|
| 28 |
-
size_min, size_max = map(int, product_size_range.split('-'))
|
| 29 |
-
return primer3.bindings.designPrimers(
|
| 30 |
-
{
|
| 31 |
-
'SEQUENCE_TEMPLATE': str(sequence),
|
| 32 |
-
'PRIMER_PRODUCT_SIZE_RANGE': [[size_min, size_max]]
|
| 33 |
-
},
|
| 34 |
-
{
|
| 35 |
-
'PRIMER_OPT_SIZE': 20,
|
| 36 |
-
'PRIMER_MIN_SIZE': 18,
|
| 37 |
-
'PRIMER_MAX_SIZE': 23,
|
| 38 |
-
'PRIMER_OPT_TM': 60.0,
|
| 39 |
-
'PRIMER_MIN_TM': 57.0,
|
| 40 |
-
'PRIMER_MAX_TM': 63.0,
|
| 41 |
-
'PRIMER_MIN_GC': 20.0,
|
| 42 |
-
'PRIMER_MAX_GC': 80.0,
|
| 43 |
-
'PRIMER_NUM_RETURN': num_to_return,
|
| 44 |
-
}
|
| 45 |
-
)
|
| 46 |
|
| 47 |
if uploaded_file is not None:
|
| 48 |
genbank_content = StringIO(uploaded_file.getvalue().decode("utf-8"))
|
|
@@ -55,14 +40,15 @@ if uploaded_file is not None:
|
|
| 55 |
|
| 56 |
feature_sequence = selected_feature.extract(record.seq)
|
| 57 |
st.write(f"Selected {feature_type} sequence (length: {len(feature_sequence)} bp):")
|
| 58 |
-
st.
|
| 59 |
|
| 60 |
product_size_range = st.text_input("Enter desired PCR product size range (e.g., 150-500):", value="150-500")
|
| 61 |
min_num_primers = st.number_input("Enter minimum number of primer pairs to return:", min_value=5, value=5, step=1)
|
| 62 |
|
| 63 |
if st.button(f'Design Primers for selected {feature_type}'):
|
| 64 |
-
primers
|
| 65 |
-
|
|
|
|
| 66 |
primer_data = []
|
| 67 |
for i in range(min_num_primers):
|
| 68 |
left_sequence = primers.get(f'PRIMER_LEFT_{i}_SEQUENCE', 'N/A')
|
|
@@ -74,16 +60,17 @@ if uploaded_file is not None:
|
|
| 74 |
'Right Sequence': right_sequence,
|
| 75 |
'Left TM (°C)': primers.get(f'PRIMER_LEFT_{i}_TM', 'N/A'),
|
| 76 |
'Right TM (°C)': primers.get(f'PRIMER_RIGHT_{i}_TM', 'N/A'),
|
| 77 |
-
'Left Length': len(left_sequence),
|
| 78 |
-
'Right Length': len(right_sequence),
|
| 79 |
'PCR Product Size (bp)': primers.get(f'PRIMER_PAIR_{i}_PRODUCT_SIZE', 'N/A')
|
| 80 |
}
|
| 81 |
primer_data.append(primer_info)
|
| 82 |
|
| 83 |
if primer_data:
|
|
|
|
| 84 |
primer_df = pd.DataFrame(primer_data)
|
| 85 |
-
|
| 86 |
-
|
| 87 |
csv = primer_df.to_csv(index=False).encode('utf-8')
|
| 88 |
st.download_button(
|
| 89 |
"Download Primers as CSV",
|
|
@@ -93,4 +80,4 @@ if uploaded_file is not None:
|
|
| 93 |
key='download-csv'
|
| 94 |
)
|
| 95 |
else:
|
| 96 |
-
st.error('No primers were found. Please adjust your parameters and try again.')
|
|
|
|
| 4 |
from Bio import SeqIO
|
| 5 |
import os
|
| 6 |
from io import StringIO
|
| 7 |
+
from st_aggrid import AgGridUpdated, GridUpdateMode, DataReturnMode
|
| 8 |
|
| 9 |
# Ensure the 'temp' directory exists for saving temporary files
|
| 10 |
temp_dir = "temp"
|
|
|
|
| 14 |
st.set_page_config(page_title="PCR Primer Design", page_icon="🧬", layout="wide")
|
| 15 |
uploaded_file = st.file_uploader("Upload a GenBank file", type=['gb', 'gbk'])
|
| 16 |
|
| 17 |
+
# Custom CSS for styling
|
| 18 |
+
st.markdown("""
|
| 19 |
+
<style>
|
| 20 |
+
h1, h2, h3 {
|
| 21 |
+
color: #1f77b4;
|
| 22 |
+
font-weight: bold;
|
| 23 |
+
}
|
| 24 |
+
.stProgress {
|
| 25 |
+
margin-top: 20px;
|
| 26 |
+
}
|
| 27 |
+
</style>
|
| 28 |
+
""", unsafe_allow_html=True)
|
| 29 |
|
| 30 |
+
# Function definitions...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
if uploaded_file is not None:
|
| 33 |
genbank_content = StringIO(uploaded_file.getvalue().decode("utf-8"))
|
|
|
|
| 40 |
|
| 41 |
feature_sequence = selected_feature.extract(record.seq)
|
| 42 |
st.write(f"Selected {feature_type} sequence (length: {len(feature_sequence)} bp):")
|
| 43 |
+
st.code(str(feature_sequence), language="text") # Display sequence in code format
|
| 44 |
|
| 45 |
product_size_range = st.text_input("Enter desired PCR product size range (e.g., 150-500):", value="150-500")
|
| 46 |
min_num_primers = st.number_input("Enter minimum number of primer pairs to return:", min_value=5, value=5, step=1)
|
| 47 |
|
| 48 |
if st.button(f'Design Primers for selected {feature_type}'):
|
| 49 |
+
with st.spinner('Designing primers...'): # Show a spinner while primers are being designed
|
| 50 |
+
primers = design_primers_for_region(feature_sequence, product_size_range, num_to_return=min_num_primers)
|
| 51 |
+
|
| 52 |
primer_data = []
|
| 53 |
for i in range(min_num_primers):
|
| 54 |
left_sequence = primers.get(f'PRIMER_LEFT_{i}_SEQUENCE', 'N/A')
|
|
|
|
| 60 |
'Right Sequence': right_sequence,
|
| 61 |
'Left TM (°C)': primers.get(f'PRIMER_LEFT_{i}_TM', 'N/A'),
|
| 62 |
'Right TM (°C)': primers.get(f'PRIMER_RIGHT_{i}_TM', 'N/A'),
|
| 63 |
+
'Left Length': len(left_sequence),
|
| 64 |
+
'Right Length': len(right_sequence),
|
| 65 |
'PCR Product Size (bp)': primers.get(f'PRIMER_PAIR_{i}_PRODUCT_SIZE', 'N/A')
|
| 66 |
}
|
| 67 |
primer_data.append(primer_info)
|
| 68 |
|
| 69 |
if primer_data:
|
| 70 |
+
st.subheader('Designed Primers')
|
| 71 |
primer_df = pd.DataFrame(primer_data)
|
| 72 |
+
AgGridUpdated(primer_df, height=200) # Use AgGrid to display the primer data in a better-formatted table
|
| 73 |
+
|
| 74 |
csv = primer_df.to_csv(index=False).encode('utf-8')
|
| 75 |
st.download_button(
|
| 76 |
"Download Primers as CSV",
|
|
|
|
| 80 |
key='download-csv'
|
| 81 |
)
|
| 82 |
else:
|
| 83 |
+
st.error('No primers were found. Please adjust your parameters and try again.')
|