Files changed (1) hide show
  1. app.py +17 -11
app.py CHANGED
@@ -46,12 +46,13 @@ def design_primers_for_region(sequence, product_size_range, num_to_return=5):
46
  }
47
  )
48
 
49
- def plot_pcr_product(sequence, primers, num_pairs=5):
50
- """Visualize the PCR product based on primer locations."""
51
  import matplotlib.pyplot as plt # Ensure matplotlib is imported here if not already done
52
 
53
- plt.figure(figsize=(10, 2))
54
- plt.plot([0, len(sequence)], [0, 0], 'k-') # Draw the sequence line
 
55
 
56
  for i in range(num_pairs):
57
  left_key = f'PRIMER_LEFT_{i}_POSITION' # Correct key for left primer position
@@ -60,16 +61,20 @@ def plot_pcr_product(sequence, primers, num_pairs=5):
60
  # Check if keys exist before trying to access them
61
  if left_key in primers and right_key in primers:
62
  left_pos = primers[left_key]
63
- right_pos = primers[right_key] + primers.get(f'PRIMER_RIGHT_{i}_LENGTH', 0) # Adjust right position by length
64
- plt.plot([left_pos, right_pos], [i, i], 'r-') # Draw the PCR product line
65
- plt.text(left_pos, i, f'Pair {i+1}', va='center', ha='right')
 
 
 
66
 
67
- plt.yticks([])
68
- plt.title('PCR Products Visualization')
69
  plt.xlabel('Nucleotide position')
 
70
  plt.grid(True)
71
 
72
- # Instead of plt.show(), use st.pyplot() for Streamlit
73
  st.pyplot(plt)
74
 
75
 
@@ -120,6 +125,7 @@ if uploaded_file is not None:
120
  )
121
  # Plotting PCR products
122
  st.write("### Visualization of PCR Products")
123
- plot_pcr_product(feature_sequence, primers, num_pairs=5)
 
124
  else:
125
  st.error('No primers were found. Please adjust your parameters and try again.')
 
46
  }
47
  )
48
 
49
+ def plot_pcr_product(sequence, primers, feature_length, num_pairs=5):
50
+ """Visualize the PCR product based on primer locations relative to a feature."""
51
  import matplotlib.pyplot as plt # Ensure matplotlib is imported here if not already done
52
 
53
+ # Start the figure for plotting
54
+ plt.figure(figsize=(10, 3))
55
+ plt.plot([0, feature_length], [1, 1], 'b-', label='Selected Feature') # Blue line represents the selected feature
56
 
57
  for i in range(num_pairs):
58
  left_key = f'PRIMER_LEFT_{i}_POSITION' # Correct key for left primer position
 
61
  # Check if keys exist before trying to access them
62
  if left_key in primers and right_key in primers:
63
  left_pos = primers[left_key]
64
+ right_pos = primers[right_key]
65
+ # Draw lines for primers; left primer above (y=1.2) and right primer below (y=0.8) the feature line
66
+ plt.plot([left_pos, left_pos], [1.1, 1.3], 'r-', label='Left Primer' if i == 0 else "") # Red line represents left primer
67
+ plt.plot([right_pos, right_pos], [0.7, 0.9], 'g-', label='Right Primer' if i == 0 else "") # Green line represents right primer
68
+ plt.text(left_pos, 1.4, f'L{i+1}', ha='center') # Label for left primer
69
+ plt.text(right_pos, 0.6, f'R{i+1}', ha='center') # Label for right primer
70
 
71
+ plt.ylim(0, 2) # Set the limits of Y-axis to make the plot clearer
72
+ plt.title('Feature and Primer Positions')
73
  plt.xlabel('Nucleotide position')
74
+ plt.legend()
75
  plt.grid(True)
76
 
77
+ # Use st.pyplot() to display the plot in Streamlit
78
  st.pyplot(plt)
79
 
80
 
 
125
  )
126
  # Plotting PCR products
127
  st.write("### Visualization of PCR Products")
128
+ feature_length = len(feature_sequence) # Length of the selected feature
129
+ plot_pcr_product(feature_sequence, primers, feature_length, num_pairs=5)
130
  else:
131
  st.error('No primers were found. Please adjust your parameters and try again.')