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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -4
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import streamlit as st
2
  import numpy as np
3
  import matplotlib.pyplot as plt
@@ -30,6 +31,7 @@ def find_local_min_runs(profile, min_run=1, max_run=2):
30
 
31
  def bio_mutate(seq):
32
  r = random.random()
 
33
  if r < 0.70:
34
  idx = random.randint(0, len(seq)-1)
35
  orig = seq[idx]
@@ -41,26 +43,31 @@ def bio_mutate(seq):
41
  else:
42
  newbase = random.choice([b for b in bases if b != orig])
43
  seq = seq[:idx] + newbase + seq[idx+1:]
 
44
  elif r < 0.80:
45
  idx = random.randint(0, len(seq)-1)
46
  ins = ''.join(random.choices(bases, k=random.randint(1, 3)))
47
  seq = seq[:idx] + ins + seq[idx:]
48
  if len(seq) > seqlen:
49
  seq = seq[:seqlen]
 
50
  elif r < 0.90:
51
  if len(seq) > 4:
52
  idx = random.randint(0, len(seq)-2)
53
  dell = random.randint(1, min(3, len(seq)-idx))
 
54
  seq = seq[:idx] + seq[idx+dell:]
 
55
  else:
56
  if len(seq) > 10:
57
  start = random.randint(0, len(seq)-6)
58
  end = start + random.randint(3,6)
59
- subseq = seq[start:end][::-1]
60
- seq = seq[:start] + subseq + seq[end:]
 
61
  while len(seq) < seqlen:
62
  seq += random.choice(bases)
63
- return seq[:seqlen]
64
 
65
  def compute_autocorr(profile):
66
  profile = profile - np.mean(profile)
@@ -80,6 +87,9 @@ 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))
@@ -93,7 +103,9 @@ if start:
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)
@@ -123,5 +135,9 @@ if start:
123
  plot_placeholder.pyplot(fig)
124
  plt.close(fig)
125
 
 
 
 
 
126
  step += 1
127
  time.sleep(0.3)
 
1
+
2
  import streamlit as st
3
  import numpy as np
4
  import matplotlib.pyplot as plt
 
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
  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
  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
  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
  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)