-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAdditional algorithm 85.html
148 lines (111 loc) · 4.91 KB
/
Additional algorithm 85.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
<!-- ############################################################################################################################## -->
<!-- # 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. # -->
<!-- # # -->
<!-- ############################################################################################################################## -->
<canvas id="bio" height="300" width="1100"></canvas>
<script>
// SCANNER
// THE INFORMATION ENTROPY
// THE INFORMATION CONTENT
var z = "AAAAAACAGGTGAGTAAAAAAAA";
var signal_s = '';
var signal_e = '';
var wl = 12;
var w = '';
var u = z.length - wl + 1;
for(var l=0; l<u; l++) {
w = z.substr(l, wl);
signal_s += content(w);
signal_e += entropy(w);
if(l<u-1){
signal_s += ',';
signal_e += ',';
}
}
document.write('<hr>Sequence: '+z+'<br>');
document.write('Information CONTENT: '+signal_s+'<br>');
document.write('Information ENTROPY: '+signal_e+'<br>');
Chart(signal_s, '#ff0000', 'y')
Chart(signal_e, '#000000', 'n')
//INFORMATION CONTENT (SELF-SEQUENCE ALIGNMENT)
function content(s)
{
var t = 0;
var m = 0;
var x = [];
x = s.split('');
for (var u=1; u<=(s.length - 1); u++)
{
for (var i=0; i<=(s.length-u); i++)
{m += f(x[i], x[u+i]);}
t += (m / (s.length-u) * 100);
m = 0;
}
return (100 - (t / (s.length - 1))).toFixed(1);
}
function f(x1, x2){
if (x1 == x2) {return 1;} else {return 0;}
}
//INFORMATION ENTROPY
function entropy(c){
//ALPHABET DETECTION
var a = [];
var t = c.split('');
var k = t.length;
for(var i=0; i<=k; i++){
var q = 1;
for(var j=0; j<=a.length; j++){
if (t[i] === a[j]) {q = 0;}
}
if (q === 1) {a.push(t[i]);}
}
var e = 0;
var r = '';
for(var i=0; i<=a.length-1; i++){
r = c.replace(new RegExp(a[i], 'g'),'').length;
a[i]=(k-r)/k;
//e += -(a[i]*Log(2,a[i]));
e += (a[i]*Log(2,(1/a[i])));
}
return e.toFixed(1);
}
function Log(n, v) {
return Math.log(v) / Math.log(n);
}
function Chart(q,c,e) {
var s = q.split(",");
var mx = Math.max.apply(null, s);
var canvas = document.getElementById('bio');
var w = canvas.width;
var h = canvas.height;
if (canvas.getContext) {
var ctx = canvas.getContext('2d');
if(e=='y'){ctx.clearRect(0, 0, w, h);}
ctx.moveTo(0, 0);
ctx.beginPath();
for (var i=0; i<=s.length-1; i++)
{
var y = h-((h / mx) * s[i]);
var x = (w / s.length) * i;
ctx.lineTo(x, y+2);
}
ctx.lineWidth = 2;
ctx.strokeStyle = c;
ctx.stroke();
}
}
</script>