Dmtlant commited on
Commit
716b99a
·
verified ·
1 Parent(s): e250773

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -19
app.py CHANGED
@@ -5,6 +5,8 @@ import matplotlib.pyplot as plt
5
  import random
6
  from scipy.stats import entropy as scipy_entropy
7
  import time
 
 
8
 
9
  st.set_page_config(layout="wide")
10
 
@@ -31,7 +33,6 @@ def find_local_min_runs(profile, min_run=1, max_run=2):
31
 
32
  def bio_mutate(seq):
33
  r = random.random()
34
- mutation_type = "None"
35
  if r < 0.70:
36
  idx = random.randint(0, len(seq)-1)
37
  orig = seq[idx]
@@ -43,31 +44,26 @@ def bio_mutate(seq):
43
  else:
44
  newbase = random.choice([b for b in bases if b != orig])
45
  seq = seq[:idx] + newbase + seq[idx+1:]
46
- mutation_type = f"Substitution at {idx}: {orig} → {newbase}"
47
  elif r < 0.80:
48
  idx = random.randint(0, len(seq)-1)
49
  ins = ''.join(random.choices(bases, k=random.randint(1, 3)))
50
  seq = seq[:idx] + ins + seq[idx:]
51
  if len(seq) > seqlen:
52
  seq = seq[:seqlen]
53
- mutation_type = f"Insertion at {idx}: {ins}"
54
  elif r < 0.90:
55
  if len(seq) > 4:
56
  idx = random.randint(0, len(seq)-2)
57
  dell = random.randint(1, min(3, len(seq)-idx))
58
- deleted = seq[idx:idx+dell]
59
  seq = seq[:idx] + seq[idx+dell:]
60
- mutation_type = f"Deletion at {idx}: {deleted}"
61
  else:
62
  if len(seq) > 10:
63
  start = random.randint(0, len(seq)-6)
64
  end = start + random.randint(3,6)
65
- subseq = seq[start:end]
66
- seq = seq[:start] + subseq[::-1] + seq[end:]
67
- mutation_type = f"Inversion from {start} to {end}: {subseq} → {subseq[::-1]}"
68
  while len(seq) < seqlen:
69
  seq += random.choice(bases)
70
- return seq[:seqlen], mutation_type
71
 
72
  def compute_autocorr(profile):
73
  profile = profile - np.mean(profile)
@@ -87,9 +83,6 @@ start = st.button("▶️ Старт эфира")
87
  stop = st.checkbox("⏹️ Остановить")
88
 
89
  plot_placeholder = st.empty()
90
- status_placeholder = st.sidebar.empty()
91
- entropy_placeholder = st.sidebar.empty()
92
- mutation_type_placeholder = st.sidebar.empty()
93
 
94
  if start:
95
  seq = ''.join(random.choices(bases, k=seqlen))
@@ -103,9 +96,7 @@ if start:
103
  break
104
 
105
  if step != 0:
106
- seq, mut_type = bio_mutate(seq)
107
- else:
108
- mut_type = "Initial sequence"
109
 
110
  torsion_profile = np.array([ANGLE_MAP.get(nt, 0.0) for nt in seq])
111
  runs = find_local_min_runs(torsion_profile, min_run, max_run)
@@ -135,9 +126,5 @@ if start:
135
  plot_placeholder.pyplot(fig)
136
  plt.close(fig)
137
 
138
- status_placeholder.markdown(f"### ℹ️ Шаг: {step}")
139
- entropy_placeholder.metric("Энтропия", f"{ent:.2f}")
140
- mutation_type_placeholder.markdown(f"**Мутация:** {mut_type}")
141
-
142
  step += 1
143
  time.sleep(0.3)
 
5
  import random
6
  from scipy.stats import entropy as scipy_entropy
7
  import time
8
+ import imageio
9
+ from datetime import datetime
10
 
11
  st.set_page_config(layout="wide")
12
 
 
33
 
34
  def bio_mutate(seq):
35
  r = random.random()
 
36
  if r < 0.70:
37
  idx = random.randint(0, len(seq)-1)
38
  orig = seq[idx]
 
44
  else:
45
  newbase = random.choice([b for b in bases if b != orig])
46
  seq = seq[:idx] + newbase + seq[idx+1:]
 
47
  elif r < 0.80:
48
  idx = random.randint(0, len(seq)-1)
49
  ins = ''.join(random.choices(bases, k=random.randint(1, 3)))
50
  seq = seq[:idx] + ins + seq[idx:]
51
  if len(seq) > seqlen:
52
  seq = seq[:seqlen]
 
53
  elif r < 0.90:
54
  if len(seq) > 4:
55
  idx = random.randint(0, len(seq)-2)
56
  dell = random.randint(1, min(3, len(seq)-idx))
 
57
  seq = seq[:idx] + seq[idx+dell:]
 
58
  else:
59
  if len(seq) > 10:
60
  start = random.randint(0, len(seq)-6)
61
  end = start + random.randint(3,6)
62
+ subseq = seq[start:end][::-1]
63
+ seq = seq[:start] + subseq + seq[end:]
 
64
  while len(seq) < seqlen:
65
  seq += random.choice(bases)
66
+ return seq[:seqlen]
67
 
68
  def compute_autocorr(profile):
69
  profile = profile - np.mean(profile)
 
83
  stop = st.checkbox("⏹️ Остановить")
84
 
85
  plot_placeholder = st.empty()
 
 
 
86
 
87
  if start:
88
  seq = ''.join(random.choices(bases, k=seqlen))
 
96
  break
97
 
98
  if step != 0:
99
+ seq = bio_mutate(seq)
 
 
100
 
101
  torsion_profile = np.array([ANGLE_MAP.get(nt, 0.0) for nt in seq])
102
  runs = find_local_min_runs(torsion_profile, min_run, max_run)
 
126
  plot_placeholder.pyplot(fig)
127
  plt.close(fig)
128
 
 
 
 
 
129
  step += 1
130
  time.sleep(0.3)