-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Additional algorithm 92.html
120 lines (92 loc) · 4.29 KB
/
Additional algorithm 92.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
<!-- ############################################################################################################################## -->
<!-- # 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. # -->
<!-- # # -->
<!-- ############################################################################################################################## -->
<script>
//ORDER VALUES ON EACH COLUMN
c = "|G\t-0.92\t-0.22\t0.69\t1.39\t-40.06\t0.69\t-0.92\t1.16\t-0.92" +
"|A\t0.18\t0.47\t-0.22\t-40.06\t-40.06\t0.69\t1.03\t-0.92\t-40.06" +
"|T\t-0.22\t0.18\t-0.22\t-40.06\t1.39\t-40.06\t-40.06\t-0.92\t1.03" +
"|C\t0.47\t-0.92\t-0.92\t-40.06\t-40.06\t-40.06\t-0.22\t-40.06\t-0.22"
var tmp;
tmp = load(c);
document.write(SMC(tmp[0])+ '<br>');
var M = tmp[0];
var a=[];
for(var j=1; j<M[0].length; j++){
document.write('<hr>column=' +j);
for(var k=0; k<M.length; k++){
a[k]=[];
a[k][0] = Number(M[k][j].split('|')[0]);
a[k][1] = M[k][j].split('|')[1];
}
a=iSort(a);
document.write(SMC(a)+ '<br>');
for(var k=0; k<M.length; k++){
M[k][j]=a[k][0] + '|' + a[k][1];
}
}
document.write(SMC(M)+ '<br>');
//SORT
function iSort(a) {
var n = a.length;
for (var i = 1; i < n; i++) {
let n = a[i][0];
let j = i-1;
while ((j > -1) && (n < a[j][0])) {
a[j+1][0] = a[j][0];
var t = a[j+1][1];
a[j+1][1] = a[j][1];
a[j][1]=t;
j--;
}
a[j+1][0] = n;
}
return a;
}
//LOAD MATRICES FROM STRINGS
function load(t){
var n = [];
var m = [];
var L = [];
m = t.split('|');
var max = 0;
for(var i=1; i<m.length; i++) {
L[i-1]=[];
n = m[i].split('\t');
for(var j=0; j<n.length; j++){
L[i-1][j]=n[j]; //Number(n[j]);
if(j>0){L[i-1][j]+='|'+L[i-1][0];}
if(max<=L[i-1][j]){max=L[i-1][j];}
}
}
return [L, max];
}
// SHOW MATRIX CONTENT
function SMC(m) {
var r = "<table border=1>";
for(var i=0; i<m.length; i++) {
r += "<tr>";
for(var j=0; j<m[i].length; j++){
r += "<td>"+m[i][j]+"</td>";
}
r += "</tr>";
}
r += "</table>";
return r;
}
</script>