forked from jlab/fold-grammars
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmotoh.gap
More file actions
220 lines (191 loc) · 5.31 KB
/
motoh.gap
File metadata and controls
220 lines (191 loc) · 5.31 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import "Extensions/rnaoptions_defaults.hh"
import "Extensions/motif.hh"
import "ali_t.hh"
input < rnali, rnali >
type strip = (string first, string second, string third)
type shape_t = shape
type base_t = extern
type ali_t = extern
signature sig_motoh(alphabet, answer) {
answer match(<Subsequence, Subsequence>, answer);
answer motif(<Subsequence, Subsequence>, answer);
answer del(< Subsequence, void >, answer);
answer ins(< void, Subsequence >, answer);
answer delx( < Subsequence, void >, answer);
answer insx( < void, Subsequence >, answer);
answer nil( <void, void> );
choice [answer] h([answer]);
}
algebra alg_motoh implements sig_motoh(alphabet = char, answer = shape_t) {
shape_t motif(<Subsequence a, Subsequence b>, shape_t m) {
char sub = '|';
char mot = identify_motif_align(a,b,sub);
if (mot != '|') {
return shape_t(mot) + m;
}
else{
return m;
}
}
shape_t match(<Subsequence a, Subsequence b>, shape_t m) {
return m;
}
shape_t del (<Subsequence a, void>, shape_t m){
return m;
}
shape_t ins(<void, Subsequence b>, shape_t m) {
return m;
}
shape_t delx(< Subsequence a, void>, shape_t m) {
return m;
}
shape_t insx(<void, Subsequence b>, shape_t m) {
return m;
}
shape_t nil(<void,void>){
shape_t r;
return r;
}
choice [shape_t] h([shape_t] l) {
return unique(l);
}
}
algebra alg_mali implements sig_motoh(alphabet = char, answer = int) {
int motif(<Subsequence a, Subsequence b>, int m) {
char sub = '|';
char mot = identify_motif_align(a, b, sub);
if (size(a) >= size(b)){
return m + motif_scoring(size(a), mot);
}
else {
return m + motif_scoring(size(b),mot);
}
}
int match( < Subsequence a, Subsequence b > , int m) {
if (a == b) {
return m + alignment_match();
}
else {
return m - alignment_mismatch();
}
}
int del(<Subsequence a, void>, int m) {
return m - alignment_gap_open() - alignment_gap_extension();
}
int ins(<void, Subsequence b>, int m) {
return m - alignment_gap_open() - alignment_gap_extension();
}
int delx(< Subsequence a, void>, int m) {
return m - alignment_gap_extension();
}
int insx(<void, Subsequence b>, int m) {
return m - alignment_gap_extension();
}
int nil(<void,void>){
return 0;
}
choice [int] h([int] l) {
return list(maximum(l));
}
}
algebra alg_prettier implements sig_motoh(alphabet = char, answer = strip) {
strip motif(< Subsequence a, Subsequence b>, strip m) {
strip r;
ali_append(r.first, a);
ali_append(r.second, b);
char sub = '|';
char mot = identify_motif_align(a, b, sub);
if (size(a) <= size(b)) {
append(r.first,'~',size(b)-size(a));
append(r.third,mot,size(b));
}
else { //covers the inverse case that motif sequence a is bigger than b
append(r.second,'~',size(a)-size(b));
append(r.third,mot,size(a));
}
append(r.first, m.first);
append(r.second, m.second);
append(r.third, m.third);
return r;
}
strip match(<Subsequence a, Subsequence b>, strip m) {
strip r;
ali_append(r.first, a);
append(r.first, m.first);
ali_append(r.second, b);
append(r.second, m.second);
if (a == b) {
append(r.third, '|');
}
else {
append(r.third, '*');
}
append(r.third, m.third);
return r;
}
strip del(<Subsequence a, void>,strip m) {
strip r;
ali_append(r.first, a);
append(r.first, m.first);
append(r.second, '=');
append(r.second, m.second);
append(r.third, ' ');
append(r.third, m.third);
return r;
}
strip ins(<void, Subsequence b>, strip m){
strip r;
append(r.first, '=');
append(r.first, m.first);
ali_append(r.second, b);
append(r.second, m.second);
append(r.third, ' ');
append(r.third, m.third);
return r;
}
strip delx(<Subsequence a, void>, strip m) {
strip r;
ali_append(r.first, a);
append(r.first, m.first);
append(r.second, '-');
append(r.second, m.second);
append(r.third, ' ');
append(r.third, m.third);
return r;
}
strip insx(<void, Subsequence b>, strip m) {
strip r;
append(r.first, '-');
append(r.first, m.first);
ali_append(r.second, b);
append(r.second, m.second);
append(r.third, ' ');
append(r.third, m.third);
return r;
}
strip nil(<void, void>) {
strip r;
return r;
}
choice [strip] h([strip] l) {
return l;
}
}
algebra alg_count auto count;
algebra alg_enum auto enum;
grammar gra_motoh uses sig_motoh(axiom = alignment) {
alignment = nil( < EMPTY, EMPTY> ) |
del( < REGION with maxsize(1), EMPTY >, xDel) |
ins( < EMPTY, REGION with maxsize(1)>, xIns ) |
match( < REGION with maxsize(1), REGION with maxsize(1) >, alignment) |
motif( < REGION with minsize(3) with maxsize(7), REGION with minsize(3) with maxsize(7) > with motif_match, alignment) # h ;
// with minsize(3) with maxsize(7) with has_motif, if motif match returns true then I dont need other filters!
// minsize back to 1 when I implement Internal Loops, for hairpins minsize(3) works. I should keep the filters to minimize lookups
xDel = alignment |
delx( <REGION with maxsize(1), EMPTY>, xDel) # h ;
xIns = alignment |
insx( < EMPTY, REGION with maxsize(1) >, xIns) # h ;
}
instance test = gra_motoh(alg_mali*alg_enum);
instance motoh = gra_motoh(alg_mali*alg_prettier);
instance motoh2 = gra_motoh((alg_motoh * alg_mali) * alg_prettier);