-
Notifications
You must be signed in to change notification settings - Fork 2
/
view.py
69 lines (51 loc) · 1.8 KB
/
view.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
AT_DEFAULT_CLASSES = ['at-status', 'tooltipped', 'tooltipped-nw']
AT_HINT_TEMPLATE = 'Last {last_nucliotides_count} bases at the 3`' \
+ 'end {dont}include {residue_length} A or T residues'
def generate_A_T_hint(checkStatus, type):
dont = '' if checkStatus else 'don`t '
last_nucliotides_count = ''
residue_length = ''
if type == 'at5':
last_nucliotides_count = '5'
residue_length = '2-3'
elif type == 'at3':
last_nucliotides_count = '3'
residue_length = '1-2'
elif type == 'at2':
last_nucliotides_count = '2'
residue_length = '1'
else:
raise Exception('unsupported type in generate_A_T_hint')
return AT_HINT_TEMPLATE.format(
last_nucliotides_count=last_nucliotides_count,
dont=dont,
residue_length=residue_length
)
def generate_A_T_classes(checkStatus):
at_classes = AT_DEFAULT_CLASSES + ['at-status_green' if checkStatus else 'at-status_red']
return ' '.join(at_classes)
def generate_A_T_status(checkStatus, type):
return {
'classes': generate_A_T_classes(checkStatus),
'hint': generate_A_T_hint(checkStatus, type)
}
def map_to_view(primers):
results = []
for primer in primers:
d = {}
d['sequence'] = primer['sequence']
d['length'] = primer['length']
d['tm'] = primer['tm']
at_statuses = [
generate_A_T_status(primer['at5'], 'at5'),
generate_A_T_status(primer['at3'], 'at3'),
generate_A_T_status(primer['at2'], 'at2')
]
d['at_statuses'] = at_statuses
results.append(d)
return results
def build_primers_view(primers):
return {
'forwards': map_to_view(primers['forwards']),
'reverses': map_to_view(primers['reverses'])
}