yashm commited on
Commit
e7f5415
·
verified ·
1 Parent(s): 6816a9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -5
app.py CHANGED
@@ -48,19 +48,29 @@ def design_primers_for_region(sequence, product_size_range, num_to_return=5):
48
 
49
  def plot_pcr_product(sequence, primers, num_pairs=5):
50
  """Visualize the PCR product based on primer locations."""
 
 
51
  plt.figure(figsize=(10, 2))
52
  plt.plot([0, len(sequence)], [0, 0], 'k-') # Draw the sequence line
 
53
  for i in range(num_pairs):
54
- left_pos = primers.get(f'PRIMER_LEFT_{i}', {}).get('position', -1)
55
- right_pos = primers.get(f'PRIMER_RIGHT_{i}', {}).get('position', -1)
56
- if left_pos != -1 and right_pos != -1:
 
 
 
 
57
  plt.plot([left_pos, right_pos], [i, i], 'r-') # Draw the PCR product line
58
- plt.text(left_pos, i, f'{i+1}', va='bottom', ha='right')
 
59
  plt.yticks([])
60
- plt.title('PCR Products')
61
  plt.xlabel('Nucleotide position')
 
62
  plt.show()
63
 
 
64
  if uploaded_file is not None:
65
  genbank_content = StringIO(uploaded_file.getvalue().decode("utf-8"))
66
  features, record = extract_features_from_genbank(genbank_content)
 
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
58
+ right_key = f'PRIMER_RIGHT_{i}_POSITION' # Correct key for right primer position
59
+
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
  plt.show()
72
 
73
+
74
  if uploaded_file is not None:
75
  genbank_content = StringIO(uploaded_file.getvalue().decode("utf-8"))
76
  features, record = extract_features_from_genbank(genbank_content)