-
Notifications
You must be signed in to change notification settings - Fork 1
/
loadhumanproteome.js
110 lines (104 loc) · 2.44 KB
/
loadhumanproteome.js
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
var humanProteome = null;
/*
function codeCharX(c){
switch(c) {
case "A": return 0;
case "C": return 1;
case "D": return 2;
case "E": return 3;
case "F": return 4;
case "G": return 5;
case "H": return 6;
case "I": return 7;
case "K": return 8;
case "L": return 9;
case "M": return 10;
case "N": return 11;
case "P": return 12;
case "Q": return 13;
case "R": return 14;
case "S": return 15;
case "T": return 16;
case "V": return 17;
case "W": return 18;
case "Y": return 19;
case "X": return 20;
default: return -1;
}
}
function getAllkmer(i)
{
if (i <= 0) return [""];
else {
const letters = "ACDEFGHIKLMNPQRSTVWYXU,";
const kmers = getAllkmer(i-1);
const ret = [];
for (let i = 0; i < kmers.length; i++)
{
for (let j = 0; j < 23; j++)
{
ret.push(kmers[i] + letters[j]);
}
}
return ret;
}
}
*/
function find6mer(kmer, initindex)
{
let x = 0;
for (let i = 0; i < 6; i++)
{
x = (x * 20) + codeChar(kmer[initindex + i]);
}
return humanProteome[x];
}
function scanForHuman(kmer)
{
for (let i = 0; i < kmer.length - 5; i++)
{
if (! find6mer(kmer, i)) return false;
}
return true;
}
function loadProteome(data)
{
let s = [];
for (let i = 0; i < 2666680; i++)
{
for (let j = 0; j < 3; j++)
{
let x = data[j+i*4];
for (let k = 0; k < 8; k++)
{
s.push(x >= 128);
x = (x%128)*2;
}
}
if (i%10000 == 0) updateLoading(i/26666.8);
}
humanProteome = s;
updateLoading(100);
}
function loadHumanProteome(cb) {
if (humanProteome === null)
{
const imageObj = new Image();
imageObj.onload = function() {
const canvas = document.createElement("canvas");
canvas.width = imageObj.width;
canvas.height = imageObj.height;
const ctx = canvas.getContext("2d");
ctx.drawImage(imageObj, 0, 0);
const data = ctx.getImageData(0, 0, imageObj.width, imageObj.height).data;
loadProteome(data);
cb();
};
imageObj.src = "humanProteome_6mer.png";
}
else
{
cb();
return;
}
}