-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
172 lines (162 loc) · 8.64 KB
/
index.js
File metadata and controls
172 lines (162 loc) · 8.64 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
const DnaAnalyzer = require('./lib/analyzer').DnaAnalyzer
const LineReader = require('./lib/linereader').LineReader
const fetch = require('node-fetch')
window.addEventListener('load', async event => { //{{{
const logArea = document.getElementById('log')
const log = console.log
console.log = function() {
logArea.value += '\n' + Array.prototype.join.call(arguments, ' ')
logArea.scrollTop = logArea.scrollHeight
log.apply(console, arguments)
}
logArea.value = 'Loading...'
const dataFiles = ['Rsnum', 'RsnumI', 'Genotype', 'GenotypeI', 'Genoset', 'Medicine']
const dataRequests = await Promise.all(dataFiles.map(e => fetch('data/' + e + '.json')))
const [Rsnum, RsnumI, Genotype, GenotypeI, Genoset, Medicine] = await Promise.all(dataRequests.map(e => e.json()))
const MedicineIndex = {}
const NumMedicineIndex = {}
Medicine.forEach(e => {
MedicineIndex[e.id] = e
e.criteria.forEach(f => {
if (!NumMedicineIndex[f]) {
NumMedicineIndex[f] = [e.id]
} else {
NumMedicineIndex[f].push(e.id)
}
})
})
const analyzer = new DnaAnalyzer(Rsnum, RsnumI, Genotype, GenotypeI, Genoset)
const fileInput = document.getElementById('file')
//const outputArea = document.getElementById('output')
console.log('Rsnum:', Rsnum.length)
console.log('RsnumI:', RsnumI.length)
console.log('Genotype:', Genotype.length)
console.log('GenotypeI:', GenotypeI.length)
console.log('Genoset:', Genoset.length)
console.log('Medicine:', Medicine.length)
console.log('Loaded.')
fileInput.disabled = false
//outputArea.value = 'Output...'
console.outputRsnum = function(rsid, genotype, magnitude, repute, summary, mergedRsid) {
const outputBody = document.getElementById('RsnumTableBody')
const Rs = 'rs' + rsid
const MergedRs = 'rs' + mergedRsid
const Gs = '(' + genotype.join(';') + ')'
genotype = genotype.join(';')
const html = '<tr><td><a id="' + Rs +'">'
+ rsid +'</td><td></a>'
+ genotype.substr(0,11) + (genotype.length > 11 ? '...' : '') +'</td><td>'
+ (magnitude === undefined ? 'Undefined' : magnitude) + '</td><td>'
+ (repute === undefined ? 'Undefined' : repute) + '</td><td>'
+ (summary === undefined ? '' : summary) + (mergedRsid ? ' Merged with above: <a href="#' + MergedRs +'">#' + MergedRs + '</a>.' : '') + '</td><td>'
+ '<a target="blank" href="https://www.snpedia.com/index.php/' + Rs +'">' + Rs + '</a>'
+ '<a target="blank" href="https://www.snpedia.com/index.php/' + Rs + Gs + '">' + Gs.substr(0,6) + (Gs.length > 6 ? '...' : '') + '</a>'
//+ (mergedRsid ? ', <a href="#' + MergedRs +'">#' + MergedRs + '</a>' : '')
+ '<td></tr>'
outputBody.innerHTML += html
/*if (rsid == 15793179) {
outputBody.innerHTML += "Dedly mutation for chickens detected. Do not worry unless you are a chicken!"
}*/
if (NumMedicineIndex[Rs]) {
const outputBodyPharm = document.getElementById('PharmacogeneticsTableBody')
NumMedicineIndex[Rs].forEach(e => {
const html = '<tr><td>'
+ '<a target="blank" href="https://www.snpedia.com/index.php/' + e + '">' + e + '</a></td><td>'
+ (magnitude === undefined ? 'Undefined' : magnitude) + '</td><td>'
+ (repute === undefined ? 'Undefined' : repute) + '</td><td>'
+ (summary === undefined ? '' : summary) + (mergedRsid ? ' Merged with above: <a href="#' + MergedRs +'">#' + MergedRs + '</a>.' : '') + '</td><td>'
+ '<a target="blank" href="https://www.snpedia.com/index.php/' + Rs +'">' + Rs + '</a>'
+ '<a target="blank" href="https://www.snpedia.com/index.php/' + Rs + Gs + '">' + Gs.substr(0,6) + (Gs.length > 6 ? '...' : '') + '</a>'
+ '<td></tr>'
outputBodyPharm.innerHTML += html
})
}
}
console.outputGenoset = function(gsid, magnitude, repute, summary, output) {
const outputBody = document.getElementById('GenosetTableBody')
const Gs = 'gs' + gsid
const html = '<tr><td><a id="' + Gs + '">'
+ gsid +'</td><td></a>'
+ (magnitude === undefined ? 'Undefined' : magnitude) + '</td><td>'
+ (repute === undefined ? 'Undefined' : repute) + '</td><td>'
+ (summary === undefined ? '' : summary) + '<h3>Criteria:</h3><pre>' + output + '</pre></td><td>'
+ '<a target="blank" href="https://www.snpedia.com/index.php/' + Gs + '">' + Gs + '</a>'
+ '<td></tr>'
outputBody.innerHTML += html
if (NumMedicineIndex[Gs]) {
const outputBodyPharm = document.getElementById('PharmacogeneticsTableBody')
NumMedicineIndex[Gs].forEach(e => {
const html = '<tr><td>'
+ '<a target="blank" href="https://www.snpedia.com/index.php/' + e + '">' + e + '</a></td><td>'
+ (magnitude === undefined ? 'Undefined' : magnitude) + '</td><td>'
+ (repute === undefined ? 'Undefined' : repute) + '</td><td>'
+ (summary === undefined ? '' : summary) + '<h3>Criteria:</h3><pre>' + output + '</pre></td><td>'
+ '<a target="blank" href="https://www.snpedia.com/index.php/' + Gs + '">' + Gs + '</a>'
+ '<td></tr>'
outputBodyPharm.innerHTML += html
})
}
}
const searchFields = ['searchRsid', 'searchGenotype', 'searchMagnitude', 'searchRepute', 'searchSummary', 'searchSource']
searchFields.forEach((e,j) => {
const outputBody = document.getElementById('RsnumTablebody')
const input = document.getElementById(e)
input.addEventListener('change', event => {
const rows = outputBody.getElementsByTagName('tr')
for (let i = 0; i < rows.length; i++) {
const row = rows[i]
let match = true
searchFields.forEach((e,j) => {
if (!match) return
const input = document.getElementById(e)
const filter = input.value.toLowerCase()
if (!filter || filter.trim() == '') return
const td = row.getElementsByTagName("td")[j]
if (td) {
const txtValue = td.textContent || td.innerText
const c = filter[0]
if (c == '>') {
match &= txtValue.toLowerCase() > parseFloat(filter.substr(1))
} else if (c == '<') {
match &= txtValue.toLowerCase() < parseFloat(filter.substr(1))
} else if (c == '=') {
match &= txtValue.toLowerCase() == filter.substr(1)
} else if (c == '!') {
match &= txtValue.toLowerCase() != filter.substr(1)
} else if (c == '/') {
match &= txtValue.toLowerCase().match(new RegExp(filter.substr(1)))
} else {
match &= txtValue.toLowerCase().indexOf(filter) > -1
}
}
});
row.style.display = match ? "" : "none"
}
})
})
fileInput.addEventListener('change', async event => {
fileInput.disabled = true
const file = fileInput.files[0]
const name = file.name.split(/(\\|\/)/g).pop()
const ext = name.split('.').pop().toLowerCase()
console.log('Input:', name, ext)
const textReader = new LineReader(file)
await analyzer.run(textReader, console.log)
console.log('Done.')
})
const tablinks = document.getElementsByClassName("tablinks");
for (let j = 0; j < tablinks.length; j++) {
tablinks[j].addEventListener('click', event => {
const tabcontent = document.getElementsByClassName("tabcontent");
for (let i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
for (let i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(event.currentTarget.id.split('Button')[0]).style.display = "table";
event.currentTarget.className += " active";
})
}
document.getElementById("RsnumTabButton").click();
});//}}}