Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,10 @@ import primer3
|
|
| 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
|
|
@@ -27,7 +31,36 @@ h1, h2, h3 {
|
|
| 27 |
</style>
|
| 28 |
""", unsafe_allow_html=True)
|
| 29 |
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
if uploaded_file is not None:
|
| 33 |
genbank_content = StringIO(uploaded_file.getvalue().decode("utf-8"))
|
|
|
|
| 4 |
from Bio import SeqIO
|
| 5 |
import os
|
| 6 |
from io import StringIO
|
| 7 |
+
|
| 8 |
+
# Install required libraries
|
| 9 |
+
import subprocess
|
| 10 |
+
subprocess.run(["pip", "install", "st_aggrid"])
|
| 11 |
from st_aggrid import AgGridUpdated, GridUpdateMode, DataReturnMode
|
| 12 |
|
| 13 |
# Ensure the 'temp' directory exists for saving temporary files
|
|
|
|
| 31 |
</style>
|
| 32 |
""", unsafe_allow_html=True)
|
| 33 |
|
| 34 |
+
def extract_features_from_genbank(genbank_content, feature_types=['CDS', 'tRNA', 'gene']):
|
| 35 |
+
"""Extracts specified features from GenBank content."""
|
| 36 |
+
text_stream = StringIO(genbank_content.decode("utf-8")) if isinstance(genbank_content, bytes) else genbank_content
|
| 37 |
+
record = SeqIO.read(text_stream, "genbank")
|
| 38 |
+
features = {ftype: [] for ftype in feature_types}
|
| 39 |
+
for feature in record.features:
|
| 40 |
+
if feature.type in feature_types:
|
| 41 |
+
features[feature.type].append(feature)
|
| 42 |
+
return features, record
|
| 43 |
+
|
| 44 |
+
def design_primers_for_region(sequence, product_size_range, num_to_return=10):
|
| 45 |
+
"""Design primers for a specific sequence."""
|
| 46 |
+
size_min, size_max = map(int, product_size_range.split('-'))
|
| 47 |
+
return primer3.bindings.designPrimers(
|
| 48 |
+
{
|
| 49 |
+
'SEQUENCE_TEMPLATE': str(sequence),
|
| 50 |
+
'PRIMER_PRODUCT_SIZE_RANGE': [[size_min, size_max]]
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
'PRIMER_OPT_SIZE': 20,
|
| 54 |
+
'PRIMER_MIN_SIZE': 18,
|
| 55 |
+
'PRIMER_MAX_SIZE': 23,
|
| 56 |
+
'PRIMER_OPT_TM': 60.0,
|
| 57 |
+
'PRIMER_MIN_TM': 57.0,
|
| 58 |
+
'PRIMER_MAX_TM': 63.0,
|
| 59 |
+
'PRIMER_MIN_GC': 20.0,
|
| 60 |
+
'PRIMER_MAX_GC': 80.0,
|
| 61 |
+
'PRIMER_NUM_RETURN': num_to_return,
|
| 62 |
+
}
|
| 63 |
+
)
|
| 64 |
|
| 65 |
if uploaded_file is not None:
|
| 66 |
genbank_content = StringIO(uploaded_file.getvalue().decode("utf-8"))
|