Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -48,42 +48,36 @@ def design_primers_for_region(sequence, product_size_range, num_to_return=5):
|
|
| 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 |
-
import matplotlib.pyplot as plt
|
| 52 |
|
| 53 |
-
# Initialize the figure for plotting
|
| 54 |
plt.figure(figsize=(10, 3))
|
| 55 |
|
| 56 |
-
# Plot the selected feature
|
| 57 |
plt.plot([0, feature_length], [1, 1], 'b-', lw=2, label='Selected Feature')
|
| 58 |
-
|
| 59 |
-
#
|
| 60 |
for index, row in primer_df.iterrows():
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
|
| 71 |
-
plt.plot([
|
| 72 |
-
plt.text(position, label_y_position, f'{primer_type} {index + 1}', ha='center', color=color)
|
| 73 |
|
| 74 |
-
plt.ylim(0.
|
| 75 |
plt.xlim(0, feature_length)
|
| 76 |
plt.title('Feature and Primer Positions')
|
| 77 |
plt.xlabel('Nucleotide position')
|
| 78 |
-
plt.yticks([])
|
| 79 |
plt.legend()
|
| 80 |
-
plt.grid(
|
| 81 |
|
| 82 |
st.pyplot(plt)
|
| 83 |
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
| 87 |
if uploaded_file is not None:
|
| 88 |
genbank_content = StringIO(uploaded_file.getvalue().decode("utf-8"))
|
| 89 |
features, record = extract_features_from_genbank(genbank_content)
|
|
@@ -132,7 +126,7 @@ if uploaded_file is not None:
|
|
| 132 |
# Plotting PCR products
|
| 133 |
st.write("### Visualization of PCR Products")
|
| 134 |
# Your primer design logic and data preparation
|
| 135 |
-
feature_length = len(feature_sequence) #
|
| 136 |
plot_pcr_product_with_df(feature_sequence, primer_df, feature_length)
|
| 137 |
else:
|
| 138 |
st.error('No primers were found. Please adjust your parameters and try again.')
|
|
|
|
| 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)
|
|
|
|
| 126 |
# Plotting PCR products
|
| 127 |
st.write("### Visualization of PCR Products")
|
| 128 |
# Your primer design logic and data preparation
|
| 129 |
+
feature_length = len(feature_sequence) # Obtain the length of the selected feature
|
| 130 |
plot_pcr_product_with_df(feature_sequence, primer_df, feature_length)
|
| 131 |
else:
|
| 132 |
st.error('No primers were found. Please adjust your parameters and try again.')
|