Dmtlant commited on
Commit
70faa9c
·
verified ·
1 Parent(s): 599d710

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -11
app.py CHANGED
@@ -7,14 +7,13 @@ import time
7
 
8
  st.set_page_config(layout="wide")
9
 
10
- # --- НАСТРОЙКИ ---
11
  seqlen = 60
12
- steps = 120
13
  min_run, max_run = 1, 2
14
  ANGLE_MAP = {'A': 60.0, 'C': 180.0, 'G': -60.0, 'T': -180.0, 'N': 0.0}
15
  bases = ['A', 'C', 'G', 'T']
16
 
17
- # --- БИО-ФУНКЦИИ ---
18
  def find_local_min_runs(profile, min_run=1, max_run=2):
19
  result = []
20
  N = len(profile)
@@ -75,21 +74,27 @@ def compute_entropy(profile):
75
  p = counts / counts.sum()
76
  return scipy_entropy(p, base=2)
77
 
78
- # --- ИНТЕРФЕЙС ---
79
- st.title("🧬 Эфир: Живой поток мутаций ДНК")
80
- st.markdown("Анализ биологических свойств последовательности в реальном времени.")
 
81
 
82
  plot_placeholder = st.empty()
83
 
84
- if st.button("▶️ Начать эфир"):
85
  seq = ''.join(random.choices(bases, k=seqlen))
86
  stat_bist_counts = []
87
  stat_entropy = []
88
- stat_autocorr = []
89
 
90
- for step in range(steps):
 
 
 
 
 
91
  if step != 0:
92
  seq = bio_mutate(seq)
 
93
  torsion_profile = np.array([ANGLE_MAP.get(nt, 0.0) for nt in seq])
94
  runs = find_local_min_runs(torsion_profile, min_run, max_run)
95
  stat_bist_counts.append(len(runs))
@@ -101,8 +106,8 @@ if st.button("▶️ Начать эфир"):
101
  plt.subplots_adjust(hspace=0.45)
102
 
103
  axs[0].plot(torsion_profile, color='royalblue')
104
- for start, end, val in runs:
105
- axs[0].axvspan(start, end, color="red", alpha=0.3)
106
  axs[0].set_ylim(-200, 200)
107
  axs[0].set_title(f"Шаг {step}: {seq}")
108
  axs[0].set_ylabel("Торсионный угол")
@@ -118,4 +123,5 @@ if st.button("▶️ Начать эфир"):
118
  plot_placeholder.pyplot(fig)
119
  plt.close(fig)
120
 
 
121
  time.sleep(0.3)
 
7
 
8
  st.set_page_config(layout="wide")
9
 
10
+ # --- ПАРАМЕТРЫ ---
11
  seqlen = 60
 
12
  min_run, max_run = 1, 2
13
  ANGLE_MAP = {'A': 60.0, 'C': 180.0, 'G': -60.0, 'T': -180.0, 'N': 0.0}
14
  bases = ['A', 'C', 'G', 'T']
15
 
16
+ # --- ФУНКЦИИ ---
17
  def find_local_min_runs(profile, min_run=1, max_run=2):
18
  result = []
19
  N = len(profile)
 
74
  p = counts / counts.sum()
75
  return scipy_entropy(p, base=2)
76
 
77
+ # --- UI ---
78
+ st.title("🔴 Живой эфир мутаций ДНК")
79
+ start = st.button("▶️ Старт эфира")
80
+ stop = st.checkbox("⏹️ Остановить")
81
 
82
  plot_placeholder = st.empty()
83
 
84
+ if start:
85
  seq = ''.join(random.choices(bases, k=seqlen))
86
  stat_bist_counts = []
87
  stat_entropy = []
 
88
 
89
+ step = 0
90
+ while True:
91
+ if stop:
92
+ st.warning("⏹️ Эфир остановлен пользователем.")
93
+ break
94
+
95
  if step != 0:
96
  seq = bio_mutate(seq)
97
+
98
  torsion_profile = np.array([ANGLE_MAP.get(nt, 0.0) for nt in seq])
99
  runs = find_local_min_runs(torsion_profile, min_run, max_run)
100
  stat_bist_counts.append(len(runs))
 
106
  plt.subplots_adjust(hspace=0.45)
107
 
108
  axs[0].plot(torsion_profile, color='royalblue')
109
+ for start_, end_, val in runs:
110
+ axs[0].axvspan(start_, end_, color="red", alpha=0.3)
111
  axs[0].set_ylim(-200, 200)
112
  axs[0].set_title(f"Шаг {step}: {seq}")
113
  axs[0].set_ylabel("Торсионный угол")
 
123
  plot_placeholder.pyplot(fig)
124
  plt.close(fig)
125
 
126
+ step += 1
127
  time.sleep(0.3)