-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
200 lines (149 loc) · 6.08 KB
/
index.html
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
<!-- ############################################################################################################################## -->
<!-- # John Wiley & Sons, Inc. # -->
<!-- # # -->
<!-- # Book: Algorithms in Bioinformatics: Theory and Implementation # -->
<!-- # Author: Dr. Paul A. Gagniuc # -->
<!-- # # -->
<!-- # Institution: # -->
<!-- # University Politehnica of Bucharest # -->
<!-- # Faculty of Engineering in Foreign Languages # -->
<!-- # Department of Engineering in Foreign Languages # -->
<!-- # # -->
<!-- # Area: European Union # -->
<!-- # Date: 04/01/2021 # -->
<!-- # # -->
<!-- # Cite this work as: # -->
<!-- # Paul A. Gagniuc. Algorithms in Bioinformatics: Theory and Implementation. John Wiley & Sons, 2021, ISBN: 9781119697961. # -->
<!-- # # -->
<!-- ############################################################################################################################## -->
<style>
body {
padding: 1rem;
font-family: monospace;
font-size: 18px;
font-style: normal;
font-variant: normal;
line-height: 20px;
}
</style>
<script>
// Variable statement
var Match = +2;
var Mismatch = -1;
var gap = -2;
var s0 = 'CCUGCAACUUAGGCAGG';
s0 = complement(s0);
var s1 = 'AAGCCAAGCCAAGCCAAGCCGGACGUUGAAUCCGUCCCCCCCAA';
var AlignmentA = "";
var AlignmentM = "";
var AlignmentB = "";
var e = ' ';
var m = [];
var s = [];
var MMax = 0;
var MMin = 0;
var x = 0;
var y = 0;
// Matrix initialization and completion
s[0] = [] = s0.split('');
s[1] = [] = s1.split('');
var n_0 = s[0].length + 1;
var n_1 = s[1].length + 1;
for(var i=0; i<=n_0; i++) {
m[i]=[];
for(var j=0; j<=n_1; j++) {
m[i][j]=0;
if (i==1 && j>1) {m[i][j]=m[i][j-1]+gap;}
if (j==1 && i>1) {m[i][j]=m[i-1][j]+gap;}
if (i>1) {m[i][0]=s[0][i-2];}
if (j>1) {m[0][j]=s[1][j-2];}
if(i>1 && j>1){
var A = m[i-1][j-1] + f(m[i][0],m[0][j]); //'\
var B = m[i-1][j] + gap; //'-
var C = m[i][j-1] + gap; //'|
var D = 0;
m[i][j] = Math.max(A, B, C, D);
if(m[i][j] > MMax){MMax = m[i][j];x=i;y=j;}
if(m[i][j] < MMin){MMin = m[i][j];}
}
}
}
//Traceback & text alignment
var i = x;
var j = y;
while (i>=2 || j>=2) {
var Ai = m[i][0];
var Bj = m[0][j];
A = m[i-1][j-1] + f(Ai, Bj);
B = m[i-1][j] + gap;
C = m[i][j-1] + gap;
if(i>=2 && j>=2 && m[i][j]==A) {
AlignmentA = Ai + AlignmentA;
AlignmentB = Bj + AlignmentB;
if(Ai==Bj){
AlignmentM = '|' + AlignmentM;
} else {
AlignmentM = e + AlignmentM;
}
i = i - 1;
j = j - 1;
} else {
if(i>=2 && m[i][j]==B) {
AlignmentA = Ai + AlignmentA;
AlignmentB = '-' + AlignmentB;
AlignmentM = e + AlignmentM;
i = i - 1;
} else {
AlignmentA = '-' + AlignmentA;
AlignmentB = Bj + AlignmentB;
AlignmentM = e + AlignmentM;
j = j - 1;
}
}
var r1 = i-1;
var r2 = j-1;
if(m[i][j]<=0){break;}
}
// LAYOUT
var tM='';
var tS='';
// Check the end
AlignmentA = AlignmentA + s0.substr(x-1, n_0 - x);
AlignmentB = AlignmentB + s1.substr(y-1, n_1 - y);
// Check the beginning
AlignmentA = s0.substr(0, r1) + AlignmentA;
AlignmentB = s1.substr(0, r2) + AlignmentB;
if(r1>r2){
var v = r1 - r2;
for(var u=1; u<=v; u++) {tS = tS + e;}
for(var u=1; u<=v+r2; u++) {tM = tM + e;}
AlignmentB = tS + AlignmentB;
AlignmentM = tM + AlignmentM;
} else {
var v = r2 - r1;
for(var u=1; u<=v; u++) {tS = tS + e;}
for(var u=1; u<=v+r1; u++) {tM = tM + e;}
AlignmentA = tS + AlignmentA;
AlignmentM = tM + AlignmentM;
}
// Print the alignment
document.write(complement(AlignmentA) + '<br>');
document.write(AlignmentM + '<br>');
document.write(AlignmentB + '<br>');
// Matching function
function f(a1, a2) {
if(a1 === a2){return Match;} else {return Mismatch;}
}
// Make complementarity
function complement(c) {
c = c.replace(/C/g,'1');
c = c.replace(/G/g,'2');
c = c.replace(/A/g,'3');
c = c.replace(/U/g,'4');
c = c.replace(/1/g,'G');
c = c.replace(/2/g,'C');
c = c.replace(/3/g,'U');
c = c.replace(/4/g,'A');
return c;
}
</script>