This repository has been archived by the owner on Jun 3, 2021. It is now read-only.
forked from SelfHacked/rsid-overlap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
118 lines (99 loc) · 3.1 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>RSID Overlap</title>
</head>
<body>
<p>
The program will find all instances of "rs"+number in each file,
and find the overlap between them.
There is no need to preprocess the files.
</p>
<p>
After selecting each file, the number of rsids found will be shown next to it.
</p>
<p>
After selecting two files, hit the "compare" button.
The total number of overlap will be shown as well as the first 100 overlapping rsids.
</p>
<p>
You can download the full comparison as a csv file.
All rsids in the source file will be exported.
The first column is rsid, and the second column is true/false.
</p>
<table>
<tbody>
<tr>
<th>Source file</th>
<td><input id="f0" type="file" name="f0" onchange="readFile(this, 0);"></td>
<td><span id="f0-count"></span></td>
</tr>
<tr>
<th>Compare to</th>
<td><input id="f1" type="file" name="f1" onchange="readFile(this, 1);"></td>
<td><span id="f1-count"></span></td>
</tr>
<tr>
<td>
<button id="compare" onclick="compare(false);">Compare</button>
</td>
<td>
<button id="compare-download" onclick="compare(true);">Compare & Download</button>
</td>
</tr>
<tr>
<th>Overlap</th>
<td><span id="overlap-count"></span></td>
</tr>
</tbody>
</table>
<ul id="overlap-list"></ul>
<script type="text/javascript">
const rsids = [null, null];
const countSpans = [document.getElementById('f0-count'), document.getElementById('f1-count')];
const overlapSpan = document.getElementById('overlap-count');
const list = document.getElementById('overlap-list');
const tmpDownload = document.createElement('a');
// https://stackoverflow.com/a/42316936/3248736
function readFile(input, i) {
const file = input.files[0];
const reader = new FileReader();
reader.onload = (event) => {
const file = event.target.result;
const match = file.match(/rs[0-9]+/g);
rsids[i] = new Set(match);
countSpans[i].innerText = rsids[i].size;
};
reader.onerror = (event) => {
alert(event.target.error.name);
};
reader.readAsText(file);
}
function compare(download) {
if (rsids[0] === null || rsids[1] === null)
return;
let count = 0;
list.innerHTML = '';
let data = 'rsid,overlap\n';
for (const x of rsids[0]) {
const overlap = rsids[1].has(x);
data = data + `${x},${overlap}\n`;
if (!overlap)
continue;
count++;
if (count > 100)
continue;
list.innerHTML += `<li>${x}</li>`;
}
overlapSpan.innerText = count;
if (download) {
const blob = new Blob([data], {type: 'text/csv'});
tmpDownload.href = URL.createObjectURL(blob);
tmpDownload.download = 'overlap.csv';
tmpDownload.click();
}
}
</script>
</body>
</html>