Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,6 @@ import primer3
|
|
| 4 |
from Bio import SeqIO
|
| 5 |
import os
|
| 6 |
from io import StringIO
|
| 7 |
-
import matplotlib.pyplot as plt
|
| 8 |
|
| 9 |
# Ensure the 'temp' directory exists for saving temporary files
|
| 10 |
temp_dir = "temp"
|
|
@@ -46,38 +45,6 @@ def design_primers_for_region(sequence, product_size_range, num_to_return=5):
|
|
| 46 |
}
|
| 47 |
)
|
| 48 |
|
| 49 |
-
def plot_pcr_product_with_df(feature_sequence, primer_df, feature_length):
|
| 50 |
-
"""Visualize the PCR product based on primer information in a DataFrame."""
|
| 51 |
-
|
| 52 |
-
plt.figure(figsize=(10, 3))
|
| 53 |
-
|
| 54 |
-
# Plot the selected feature
|
| 55 |
-
plt.plot([0, feature_length], [1, 1], 'b-', lw=2, label='Selected Feature')
|
| 56 |
-
|
| 57 |
-
# Assuming primer positions are not directly available and using the index for demonstration
|
| 58 |
-
for index, row in primer_df.iterrows():
|
| 59 |
-
# Determine if it's a left or right primer and set the position accordingly
|
| 60 |
-
if 'Left' in row['Primer']:
|
| 61 |
-
# Position the left primer slightly above the feature line
|
| 62 |
-
y_pos = [1.05, 1.10]
|
| 63 |
-
plt.text(index * feature_length // len(primer_df), 1.15, f"L{index+1}", horizontalalignment='center')
|
| 64 |
-
else:
|
| 65 |
-
# Position the right primer slightly below the feature line
|
| 66 |
-
y_pos = [0.90, 0.95]
|
| 67 |
-
plt.text(index * feature_length // len(primer_df), 0.85, f"R{index+1}", horizontalalignment='center')
|
| 68 |
-
|
| 69 |
-
plt.plot([index * feature_length // len(primer_df)]*2, y_pos, 'r-')
|
| 70 |
-
|
| 71 |
-
plt.ylim(0.8, 1.2)
|
| 72 |
-
plt.xlim(0, feature_length)
|
| 73 |
-
plt.title('Feature and Primer Positions')
|
| 74 |
-
plt.xlabel('Nucleotide position')
|
| 75 |
-
plt.legend()
|
| 76 |
-
plt.grid(True)
|
| 77 |
-
|
| 78 |
-
st.pyplot(plt)
|
| 79 |
-
|
| 80 |
-
|
| 81 |
if uploaded_file is not None:
|
| 82 |
genbank_content = StringIO(uploaded_file.getvalue().decode("utf-8"))
|
| 83 |
features, record = extract_features_from_genbank(genbank_content)
|
|
@@ -98,32 +65,20 @@ if uploaded_file is not None:
|
|
| 98 |
|
| 99 |
primer_data = []
|
| 100 |
for i in range(5): # Collect data for 5 primer pairs
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
'Right Sequence': primers.get(f'PRIMER_RIGHT_{i}_SEQUENCE', 'N/A'),
|
| 105 |
-
'Left TM (°C)': primers.get(f'PRIMER_LEFT_{i}_TM', 'N/A'),
|
| 106 |
-
'Right TM (°C)': primers.get(f'PRIMER_RIGHT_{i}_TM', 'N/A'),
|
| 107 |
-
'Left Length': primers.get(f'PRIMER_LEFT_{i}_SIZE', 'N/A'),
|
| 108 |
-
'Right Length': primers.get(f'PRIMER_RIGHT_{i}_SIZE', 'N/A'),
|
| 109 |
-
'PCR Product Size (bp)': primers.get(f'PRIMER_PAIR_{i}_PRODUCT_SIZE', 'N/A')
|
| 110 |
-
}
|
| 111 |
-
if primer_info['Left Sequence'] != 'N/A' and primer_info['Right Sequence'] != 'N/A':
|
| 112 |
-
primer_info['Primer'] = f"Left {i+1}"
|
| 113 |
-
primer_data.append(primer_info)
|
| 114 |
primer_info = {
|
| 115 |
'Primer Pair': i + 1,
|
| 116 |
-
'Left Sequence':
|
| 117 |
-
'Right Sequence':
|
| 118 |
'Left TM (°C)': primers.get(f'PRIMER_LEFT_{i}_TM', 'N/A'),
|
| 119 |
'Right TM (°C)': primers.get(f'PRIMER_RIGHT_{i}_TM', 'N/A'),
|
| 120 |
'Left Length': primers.get(f'PRIMER_LEFT_{i}_SIZE', 'N/A'),
|
| 121 |
'Right Length': primers.get(f'PRIMER_RIGHT_{i}_SIZE', 'N/A'),
|
| 122 |
'PCR Product Size (bp)': primers.get(f'PRIMER_PAIR_{i}_PRODUCT_SIZE', 'N/A')
|
| 123 |
}
|
| 124 |
-
|
| 125 |
-
primer_info['Primer'] = f"Right {i+1}"
|
| 126 |
-
primer_data.append(primer_info)
|
| 127 |
|
| 128 |
if primer_data:
|
| 129 |
primer_df = pd.DataFrame(primer_data)
|
|
@@ -137,10 +92,5 @@ if uploaded_file is not None:
|
|
| 137 |
"text/csv",
|
| 138 |
key='download-csv'
|
| 139 |
)
|
| 140 |
-
# Plotting PCR products
|
| 141 |
-
st.write("### Visualization of PCR Products")
|
| 142 |
-
# Your primer design logic and data preparation
|
| 143 |
-
feature_length = len(feature_sequence) # Obtain the length of the selected feature
|
| 144 |
-
plot_pcr_product_with_df(feature_sequence, primer_df, feature_length)
|
| 145 |
else:
|
| 146 |
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 |
|
| 8 |
# Ensure the 'temp' directory exists for saving temporary files
|
| 9 |
temp_dir = "temp"
|
|
|
|
| 45 |
}
|
| 46 |
)
|
| 47 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
if uploaded_file is not None:
|
| 49 |
genbank_content = StringIO(uploaded_file.getvalue().decode("utf-8"))
|
| 50 |
features, record = extract_features_from_genbank(genbank_content)
|
|
|
|
| 65 |
|
| 66 |
primer_data = []
|
| 67 |
for i in range(5): # Collect data for 5 primer pairs
|
| 68 |
+
left_sequence = primers.get(f'PRIMER_LEFT_{i}_SEQUENCE', 'N/A')
|
| 69 |
+
right_sequence = primers.get(f'PRIMER_RIGHT_{i}_SEQUENCE', 'N/A')
|
| 70 |
+
if left_sequence != 'N/A' and right_sequence != 'N/A':
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
primer_info = {
|
| 72 |
'Primer Pair': i + 1,
|
| 73 |
+
'Left Sequence': left_sequence,
|
| 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': primers.get(f'PRIMER_LEFT_{i}_SIZE', 'N/A'),
|
| 78 |
'Right Length': primers.get(f'PRIMER_RIGHT_{i}_SIZE', 'N/A'),
|
| 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)
|
|
|
|
| 92 |
"text/csv",
|
| 93 |
key='download-csv'
|
| 94 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
else:
|
| 96 |
st.error('No primers were found. Please adjust your parameters and try again.')
|