/
eli_fisker_complementary_zipper_style_MS2_FMN_turnon_labs.py
128 lines (94 loc) · 4.28 KB
/
eli_fisker_complementary_zipper_style_MS2_FMN_turnon_labs.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import eterna_utils
import strategy_template
import re
class Strategy(strategy_template.Strategy):
def __init__(self):
strategy_template.Strategy.__init__(self)
# Title, author of the strategy submission
self.title_ = ("[Strategy Market] [Switch]"
"Complementary Zipper Style - MS2/FMN Turnon labs")
self.author_ = "Eli Fisker"
# URL where the strategy was initially submitted
self.url_ = ("https://getsatisfaction.com/eternagame/topics/"
"-strategy-market-switch"
"-complementary-zipper-style-ms2-fmn-turnon-labs")
# Default strategy parameters
self.default_params_ = [1.0, 0, 4, 1.0, 2, 5, 1.0]
# Number of lines of code used to implement the strategy
self.code_length_ = 61
self.publishable_ = True
self.denormalized_ = True
self.comprehensive = False
def findRNAElement(self, type, bp, elements):
for i in range(0, len(elements)):
if elements[i].type_ == type and bp in elements[i].indices_:
return elements[i]
return None
def getSequence(self, elem, strand, seq):
if elem.type_ != eterna_utils.RNAELEMENT_STACK:
return None
sequence = []
indices = sorted(elem.indices_) # preserve current order
for i in range(0, len(indices)):
if (i > 0 and indices[i] - indices[i - 1] > 1):
strand = (strand % 2) + 1
if strand == 1:
sequence.append(seq[indices[i]])
return "".join(sequence)
def score(self, design, params):
score = 100
if "miRNA" in design['labtitle']:
score = eterna_utils.UNSCORABLE
else:
# get aptamer bases
# find strand1, strand2, strand3, strand4
# 10,11,12,13,14,15,16,17,35,36,37,38,39,40,41 should become
# 10, 35
bases = design['site']
bases.sort()
strands = [bases[0], 100]
for i in range(1, len(bases)):
if bases[i] - bases[i-1] > 1:
strands[1] = bases[i]
break
states = range(1, 3) # [1, 2]
# get rnaelements containing strands
for n in states:
for i in range(0, len(strands)):
elem = self.findRNAElement(
eterna_utils.RNAELEMENT_STACK,
strands[i],
design['secstruct_elements' + str(n)]
)
if elem is not None:
strand1 = [m.start() for m in re.finditer(
"CAUG",
self.getSequence(elem, 1, design['sequence'])
)]
strand2 = [m.start() for m in re.finditer(
"CAUG",
self.getSequence(elem, 2, design['sequence'])
)]
strand1 = sorted(
strand1,
key=lambda dist: abs(strands[i] - dist)
)
strand2 = sorted(
strand2,
key=lambda dist: abs(strands[i] - dist)
)
if len(strand1) > 0 and len(strand2) > 0:
score += params[0]
# Ideally we could just use 1 strand, but just in
# case average both.
dist = float(abs(strand1[0] - strands[i]) +
abs(strand2[0] - strands[i])) / 2
# Early aptamer gate
if i == 0:
if params[1] <= dist <= params[2]:
score += params[3]
# Late aptamer gate
else:
if params[4] <= dist <= params[5]:
score += params[6]
return score