-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewer.py
78 lines (55 loc) · 1.54 KB
/
viewer.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import math
WHITE = 0xFFFFFF
RED = 0xFF0000
GREEN = 0x00FF00
BLUE = 0x8888FF
YELLOW = 0xFFFF00
BLACK = 0x000000
def view(width, height, helix, output):
half = width // 2
import pygame
pygame.init()
surface = pygame.Surface((width, height))
# pygame.display.set_caption(title)
cells = [helix.start, helix.size, helix.checksum]
cells.extend(iter(helix.data))
cells.append(helix.end)
for cell in cells:
print(cell)
if True:
surface.fill((255, 255, 255))
start_y = 0
for cell in cells:
lines = list(zip(cell.get_left()[0], cell.get_right()[0]))
degrees = [30, 75, 115, 150]
colors = {
'A': RED,
'T': GREEN,
'C': YELLOW,
'G': BLUE
}
step = 180 // (len(lines) + 1)
mapped_bars = {
step * (index + 1): [colors[letter] for letter in line]
for index, line in enumerate(lines)
}
for degrees in range(0, 180):
x = int(math.sin(math.radians(degrees)) * 50)
y = start_y + degrees
left = half + x
right = half - x
if degrees in mapped_bars:
bars = mapped_bars[degrees]
distance = right - left
bar_length = distance / len(bars)
for index, bar in enumerate(bars):
start = (left + (bar_length * index), y)
end = (left + (bar_length * (index + 1)), y)
pygame.draw.line(surface, bar, start, end, 2)
surface.set_at((left, y), BLACK)
surface.set_at((right, y), BLACK)
"""if degrees == 0:
pygame.draw.line(surface, YELLOW, (0, y), (width, y), 1)"""
start_y += 180
pygame.image.save(surface, output)
# pygame.display.update()