-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhmm_transmembrane.gap
144 lines (129 loc) · 4.04 KB
/
hmm_transmembrane.gap
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
type Rope = extern
signature sig_transmembrane(alphabet, answer) {
answer transition(float, alphabet, answer, answer);
answer transitionend(float, answer);
answer emission(float, alphabet);
answer nil(void);
choice [answer] h([answer]);
}
algebra alg_enum auto enum;
algebra alg_count auto count;
algebra alg_tikz auto tikz;
algebra alg_viterbi implements sig_transmembrane(alphabet=char, answer=float) {
float transition(float transition, char state, float emission, float x) {
return transition * emission * x;
}
float transitionend(float transition, float x) {
return transition * x;
}
float emission(float emission, char a) {
return emission;
}
float nil(void) {
return 1.0;
}
choice [float] h([float] candidates) {
return list(maximum(candidates));
}
}
algebra alg_fwd extends alg_viterbi {
choice [float] h([float] candidates) {
return list(sum(candidates));
}
}
algebra alg_states implements sig_transmembrane(alphabet=char, answer=Rope) {
Rope transition(float transition, char state, Rope emission, Rope x) {
Rope res;
append(res, state);
append(res, x);
return res;
}
Rope transitionend(float transition, Rope x) {
return x;
}
Rope emission(float emission, char a) {
Rope res;
return res;
}
Rope nil(void) {
Rope res;
append(res, '$');
return res;
}
choice [Rope] h([Rope] candidates) {
return candidates;
}
}
algebra alg_structure implements sig_transmembrane(alphabet=char, answer=Rope) {
Rope transition(float transition, char state, Rope emission, Rope x) {
Rope res;
if (state == 'T') {
append(res, 'I');
} else {
append(res, 'O');
}
append(res, x);
return res;
}
Rope transitionend(float transition, Rope x) {
return x;
}
Rope emission(float emission, char a) {
Rope res;
return res;
}
Rope nil(void) {
Rope res;
append(res, '$');
return res;
}
choice [Rope] h([Rope] candidates) {
return unique(candidates);
}
}
/*
st_ short for state, em_ short for emission
*/
grammar gra_transmembrane uses sig_transmembrane(axiom=st_init) {
st_init = transition(CONST_FLOAT(0.89), CONST_CHAR('e'), em_ext, st_ext)
| transition(CONST_FLOAT(0.01), CONST_CHAR('T'), em_trans, st_trans)
| transition(CONST_FLOAT(0.08), CONST_CHAR('i'), em_int, st_int)
| transitionend(CONST_FLOAT(0.02), st_end)
# h;
st_ext = transition(CONST_FLOAT(0.49), CONST_CHAR('e'), em_ext, st_ext)
| transition(CONST_FLOAT(0.05), CONST_CHAR('i'), em_int, st_int)
| transition(CONST_FLOAT(0.44), CONST_CHAR('T'), em_trans, st_trans)
| transitionend(CONST_FLOAT(0.02), st_end)
# h;
st_trans = transition(CONST_FLOAT(0.05), CONST_CHAR('e'), em_ext, st_ext)
| transition(CONST_FLOAT(0.34), CONST_CHAR('i'), em_int, st_int)
| transition(CONST_FLOAT(0.59), CONST_CHAR('T'), em_trans, st_trans)
| transitionend(CONST_FLOAT(0.02), st_end)
# h;
st_int = transition(CONST_FLOAT(0.05), CONST_CHAR('e'), em_ext, st_ext)
| transition(CONST_FLOAT(0.79), CONST_CHAR('i'), em_int, st_int)
| transition(CONST_FLOAT(0.14), CONST_CHAR('T'), em_trans, st_trans)
| transitionend(CONST_FLOAT(0.02), st_end)
# h;
st_end = nil(EMPTY)
# h;
em_ext = emission(CONST_FLOAT(0.15), CHAR('A'))
| emission(CONST_FLOAT(0.15), CHAR('C'))
| emission(CONST_FLOAT(0.60), CHAR('G'))
| emission(CONST_FLOAT(0.10), CHAR('T'))
# h;
em_trans = emission(CONST_FLOAT(0.3), CHAR('A'))
| emission(CONST_FLOAT(0.4), CHAR('C'))
| emission(CONST_FLOAT(0.2), CHAR('G'))
| emission(CONST_FLOAT(0.1), CHAR('T'))
# h;
em_int = emission(CONST_FLOAT(0.1), CHAR('A'))
| emission(CONST_FLOAT(0.1), CHAR('C'))
| emission(CONST_FLOAT(0.6), CHAR('G'))
| emission(CONST_FLOAT(0.2), CHAR('T'))
# h;
}
/*
example inputs: GCGGCCGA
*/
instance test = gra_transmembrane(alg_states);