-
Notifications
You must be signed in to change notification settings - Fork 0
/
21_dna_visual.py
51 lines (45 loc) · 1.06 KB
/
21_dna_visual.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import random, sys, time
DNA_STR=[('G','C'),('C','G'),('T','A'),('A','T')]
PAUSE=0.1
DNA_ROWS=[
' ##',
' #{}-{}#',
' #{}---{}#',
' #{}-----{}#',
' #{}------{}#',
' #{}------{}#',
' #{}-----{}#',
' #{}---{}#',
' #{}-{}#',
' ##',
' #{}-{}#',
' #{}---{}#',
' #{}-----{}#',
' #{}------{}#',
' #{}------{}#',
' #{}-----{}#',
' #{}---{}#',
' #{}-{}#',
]
def main():
print('press ctrl-c to stop\n')
time.sleep(2)
row_count=0
while True:
# get a random sequence
dna_seq=random.choice(DNA_STR)
row_count+=1
if row_count == len(DNA_ROWS):
row_count=0
# handle `##` case
if row_count==0 or row_count==9:
print(DNA_ROWS[row_count])
continue
print(DNA_ROWS[row_count].format(dna_seq[0],dna_seq[1]))
sys.stdout.flush()
time.sleep(PAUSE)
if __name__=='__main__':
try:
main()
except KeyboardInterrupt:
sys.exit()