-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
577 lines (492 loc) · 17.9 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
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>SARS-CoV-2-Variants by @3dgiordano</title>
<meta name="generator" content="Jekyll v3.9.0" />
<meta property="og:title" content="SARS-CoV-2-Variants" />
<meta name="author" content="David Giordano" />
<meta property="og:locale" content="en_US" />
<meta name="description" content="SARS-CoV-2-Variants by @3dgiordano" />
<meta property="og:description" content="SARS-CoV-2-Variants by @3dgiordano" />
<link rel="canonical" href="https://3dgiordano.github.io/SARS-CoV-2-Variants/" />
<meta property="og:url" content="https://3dgiordano.github.io/SARS-CoV-2-Variants/" />
<meta property="og:site_name" content="SARS-CoV-2-Variants by @3dgiordano" />
<meta name="twitter:card" content="summary" />
<meta property="twitter:title" content="SARS-CoV-2-Variants by @3dgiordano" />
<meta property="og:image" content="/web/favicon.png">
<link rel="shortcut icon" type="image/x-icon" href="./web/favicon.ico">
<link rel="shortcut icon" type="image/png" href="./web/favicon.png">
<link rel="apple-touch-icon" sizes="170x170" href="./web/favicon.png">
<link rel="icon" type="image/png" sizes="32x32" href="./web/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="./web/favicon-16x16.png">
<link rel='stylesheet' href='web/general.css'>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-QBJJX8MJH3"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'G-QBJJX8MJH3');
</script>
<script type="application/ld+json">
{"headline":"SARS-CoV-2-Variants by @3dgiordano","description":"SARS-CoV-2 Variants by @3dgiordano","url":"https://3dgiordano.github.io/SARS-CoV-2-Variants/","@type":"WebSite","name":"SARS-CoV-2-Variants by @3dgiordano","author":{"@type":"Person","name":"David Giordano"},"@context":"https://schema.org"}
</script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/apexcharts/3.27.3/apexcharts.min.js'></script>
<script src='https://gmousse.github.io/dataframe-js/dist/dataframe.min.js'></script>
<script id="rendered-js" crossorigin="anonymous">
var loc_df = null;
var continent = null;
var locations = [];
var doc_width = 1024;
var chart_width = 640;
var chart_list = [];
var variants = [];
var variants_color_map = {};
function windowSizeUpdate() {
doc_width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
chart_width = parseInt((doc_width / 2) - 70);
if (doc_width <= 1024) {
chart_width = parseInt(doc_width - 100);
}
chart_list.forEach(chart => {
ApexCharts.exec(chart, 'updateOptions', {
chart: {
width: chart_width + "px"
}
});
});
}
window.addEventListener('resize', windowSizeUpdate);
windowSizeUpdate();
function start() {
dfjs.DataFrame.fromJSON("https://3dgiordano.github.io/SARS-CoV-2-Variants/data/update.json").then(df => {
var update_date_str = df.select("last_update_utc").toArray().join('') + "Z";
var date_str = new Date(update_date_str).toString();
document.getElementById("last_update").innerText = date_str;
});
new Promise(() => {
if (variants.length == 0){
dfjs.DataFrame.fromCSV("https://3dgiordano.github.io/SARS-CoV-2-Variants/data/variants.csv").then(df => {
variants = df.toArray("label").reverse();
update_continent();
});
} else {
update_continent();
}
});
}
function get_color_columns(columns, variants) {
var colors = [
"#3360a9",
"#2a939b",
"#e6332e",
"#ca2628",
"#ffd53e",
"#9ecc8a",
"#34983f",
"#ff7f0e",
"#1f77b4",
"#ffbb78",
"#2ca02c",
"#98df8a",
"#d62728",
"#ff9896",
"#9467bd",
"#c5b0d5",
"#8c564b",
"#c49c94",
"#e377c2",
"#f7b6d2",
"#7f7f7f",
"#c7c7c7",
"#bcbd22",
"#dbdb8d",
"#17becf",
"#9edae5",
"#1f77b4",
"#3C4E66",
"#B13507",
"#00847E",
"#6D3E91",
"#CF0A66",
"#883039",
"#00823F",
"#4C6A9C",
"#C05917",
"#D73C50",
"#287669",
"#CD2285",
"#0F739C",
"#9A5129",
"#C45267",
"#008860",
"#8C4569",
"#B36216",
"#366388",
"#A2559C",
"#578145",
"#D7263F",
"#18470F",
"#BC8E5A",
"#585C64",
"#F66F9E",
"#B87BE1",
"#4AB5E1",
"#4BC59F",
"#4A73BD",
];
color_linages = [
"#eb5164",
"#ffd970",
"#d85078",
"#ff5151",
"#ffce7d",
"#68ff90",
"#c4508b",
"#ffc38a",
"#79f08d",
"#b14f9e",
"#ffb796",
"#8ae18b",
"#9d4fb2",
"#ffaca3",
"#9ad288",
"#8a4ec5",
"#ffa1b0",
"#abc385",
"#764ed8",
"#ff96bd",
"#bcb483",
"#634dec",
"#ff8ac9",
"#cda580",
"#4f4dff",
"#ff7fd6",
"#dd967d",
"#ff74e3",
"#ee877b",
"#ff7878",
];
if (typeof variants === 'undefined') {
// console.log("Uppss variants disapears...");
return colors;
}
var palettte = []
// console.log(variants);
columns.forEach(variant => {
variant = variant.split("(")[0].trim();
if (variant in variants_color_map) {
palettte.push(variants_color_map[variant]);
} else {
// console.log(variant);
if (variant == "Other" || variant == "") {
variants_color_map[variant] = "#8B8B8B";
} else {
var found = variants.indexOf(variant);
// console.log(found);
if (found > -1) {
var col_index = found % (colors.length - 1);
// console.log("Idx:" + col_index);
var calt = colors[found % (colors.length - 1)];
// console.log("P:" + calt);
variants_color_map[variant] = calt;
} else {
// Generate color based on the letters
if (variant.length == 2) {
var calt1 = color_linages[variant[0].charCodeAt(0) - 65];
var pp = (color_linages.length - 1) - (variant[1].charCodeAt(0) - 65);
// console.log(pp);
var calt2 = color_linages[pp];
// console.log("Y:" + calt2);
var calt = calt1.substring(0, 4) + calt2.substring(4, 7);
// console.log(variant + ":ALT:" + calt);
variants_color_map[variant] = calt;
} else {
var calt = color_linages[variant[0].charCodeAt(0) - 65];
// console.log(variant + ":ALT2:" + calt);
variants_color_map[variant] = calt;
}
}
}
palettte.push(variants_color_map[variant]);
}
});
// console.log(palettte);
return palettte;
}
function renderChart(data_title, data_url, element_selector, variants) {
var chart_width_px = chart_width + "px";
var chart_height_px = "400px";
if (element_selector == "#world" && chart_width > 400) {
chart_width_px = (chart_width * 2) + "px";
chart_height_px = "500px";
}
var series = [];
var columns = [];
var dates = [];
var colors_columns = [];
/*
columns.forEach(function (column, col_ind) {
console.log(column + ":" + colors_columns[col_ind]);
});
*/
var options = {
title: {
text: data_title,
align: 'center',
margi: 0,
offsetY: 20,
style: {
fontSize: '16px',
fontFamily: "Verdana"
},
},
grid: {
show: false,
},
colors: colors_columns,
chart: {
id: element_selector,
type: 'area',
height: chart_height_px,
width: chart_width_px,
redrawOnParentResize: false,
redrawOnWindowResize: false,
stacked: true,
animations: { enabled: false },
offsetY: 0,
toolbar: {
show: false,
},
zoom: {
enabled: false,
},
},
noData: {
text: "Loading...",
},
legend: {
show: false
},
dataLabels: {
enabled: false,
},
tooltip: {
onDatasetHover: { highlightDataSeries: true },
shared: true,
followCursor: false,
custom: function ({ series, seriesIndex, dataPointIndex, w }) {
var str_html = '<div style="">';
v_date = new Date(w.config.xaxis.categories[dataPointIndex]);
f_date = new Date(v_date - (( 3600 * 1000 * 24) * 13 ));
v_date_str = f_date.toISOString().split("T")[0] + " to " + v_date.toISOString().split("T")[0];
str_html += '<div class="arrow_box apexcharts-tooltip-title" style="display:flex">' +
'<span style="width:100%;text-align:center;display:block;">' + v_date_str + '</span>' +
'</div>';
var sortIndex = [];
w.globals.seriesNames.forEach(function (sn_value, sn_i) {
sortIndex.push((series[sn_i][dataPointIndex] + 100) + ":" + sn_i);
});
sortIndex = sortIndex.sort().reverse();
sortIndex.forEach(function (value, i) {
var val = parseFloat(value.split(":")[0]) - 100;
if (val >= 1) {
var d_index = parseInt(value.split(":")[1]);
var val_frmt = w.globals.ttVal.formatter(val, { series, seriesIndex, d_index, w });
var s_name = w.globals.seriesNames[d_index];
str_html += '<div class="arrow_box apexcharts-tooltip-series-group" style="display:flex">' +
'<span class="apexcharts-tooltip-marker" style="width:15px;height:10px;background-color:' + w.globals.colors[d_index] + '">' + '</span>' +
'<span class="apexcharts-tooltip-text" style="width:100%">' + s_name + '</span>' +
'<span style="width:50px;text-align:right;display:block;">' + val_frmt + '</span>' +
'</div>';
}
});
str_html += '</div>';
return str_html;
},
style: {
fontSize: '9px',
fontFamily: "Verdana"
},
y: {
formatter: function (value, { series, seriesIndex, dataPointIndex, w }) {
return Number(value).toFixed(0) + "%";
}
}
},
fill: {
type: 'solid'
},
stroke: {
curve: 'smooth',
width: 0,
},
series: series,
xaxis: {
tooltip: {
enabled: false
},
type: 'datetime',
categories: dates
},
yaxis: {
max: 100,
show: false,
}
};
var chart = new ApexCharts(document.querySelector(element_selector), options);
chart.render();
chart_list.push(element_selector);
period_list = document.getElementById("period_list");
selected_period = parseInt(period_list.options[ period_list.selectedIndex ].value);
dfjs.DataFrame.fromCSV(data_url).then(df => {
df.listColumns().forEach(column => {
if ((['location', 'date']).indexOf(column) == -1 && df.toArray(column).reduce(function (pv, cv) { return parseFloat(pv.toString().replace(',', '.')) + parseFloat(cv.toString().replace(',', '.')); }, 0) > 0) {
columns.push(column);
// Only latest data
data = df.toArray(column).map(function (x) { return parseFloat(x.toString().replace(',', '.')) })
if (selected_period != -1) {
data = data.slice(data.length-selected_period,data.length);
}
series.push(
{ name: column, data: data }
);
};
}
);
dates = df.toArray("date");
if (selected_period != -1) {
dates = dates.slice(dates.length-selected_period,dates.length);
}
colors_columns = get_color_columns(columns, variants);
chart.updateOptions (
{
series: series,
colors: colors_columns,
noData: {
text: "No Data",
},
xaxis: {
tooltip: {
enabled: false
},
type: 'datetime',
categories: dates
},
},
true, false, true
);
});
}
function load_charts(variants) {
document.querySelectorAll(".location").forEach(e => e.remove());
if (continent == "World") {
document.getElementById("world_container").style.visibility = "visible";
new Promise(() => {
setTimeout(renderChart("World", 'https://3dgiordano.github.io/SARS-CoV-2-Variants/data/World.csv', "#world", variants), 0);
});
} else {
document.getElementById("world_container").style.visibility = "collapse";
}
dfjs.DataFrame.fromCSV('https://3dgiordano.github.io/SARS-CoV-2-Variants/data/genomics.csv').then(df => {
df_sequence = df.groupBy('location').aggregate(group => group.stat.sum('num_sequences')).rename('aggregation', 'tot_sequences');
df_variant = df.groupBy('location', 'variant').aggregate(group => group.stat.sum('num_sequences')).rename('aggregation', 'tot_sequences');
// df_sequence.show();
// df_variant.show();
c_locations = [...new Set(df.toArray("location"))];
var content_table = document.querySelector("#content");
var i = 0;
var content_row;
c_locations.forEach(location => {
if (locations.includes(location)) {
tot_sequences = df_sequence.filter(row => row.get('location') == location).toArray("tot_sequences");
tot_variants = df_variant.filter(row => row.get('location') == location).toArray("variant").length;
if (tot_sequences > 50 && tot_variants >= 2) {
if (i % 2 == 0) {
content_row = content_table.insertRow();
content_row.classList.add('location');
}
var cell = content_row.insertCell();
cell.style = "width: 50%;";
var container = document.createElement("div");
container.id = "location_" + i;
cell.appendChild(container);
new Promise(() => {
setTimeout(renderChart(location, 'https://3dgiordano.github.io/SARS-CoV-2-Variants/data/' + location.replace(' ', '%20') + ".csv", "#" + container.id, variants), 0);
});
i += 1;
}
}
});
});
}
function load_df_locations(){
locations = [...new Set(loc_df.filter(row => row.get('continent') == continent).toArray("location"))].sort();
console.log(locations);
load_charts(variants);
}
function update_continent() {
continent = document.querySelector('input[name="continent"]:checked').id.replace("_", " ");
setTimeout(function(){
if (loc_df == null) {
dfjs.DataFrame.fromCSV('https://raw.githubusercontent.com/owid/covid-19-data/master/public/data/jhu/locations.csv').then(l_df => {
loc_df = l_df;
console.log("load loc");
load_df_locations();
});
} else {
console.log("no load loc");
load_df_locations();
}
}, 300);
}
</script>
<div class="info">
<h1>SARS-CoV-2 Variants</h1>
<div class="info">
This site tries to give a glimpse of the different variants of SAR-CoV-2 in the world.<br />
<br />
<b>Last update: </b><span id="last_update"></span><br>
<br /><br />
<table class="actions"><tr><td><a class="button_active" href="./">Sequences</a></td><td><a class="button" href="fit">Fitting cases to sequences</a></td><td><a class="button" href="about">About</a></td></tr></table><br>
</div>
</div>
<table id="content" class="content">
<tr>
<td colspan=2 align="center">
<form style="text-align: center">
<label style="white-space:nowrap"><input type="radio" name="continent" id="World" checked onclick="update_continent();"/>World</label>
<label style="white-space:nowrap"><input type="radio" name="continent" id="Europe" onclick="update_continent();"/>Europe</label>
<label style="white-space:nowrap"><input type="radio" name="continent" id="North_America" onclick="update_continent();"/>North America</label>
<label style="white-space:nowrap"><input type="radio" name="continent" id="South_America" onclick="update_continent();"/>South America</label>
<label style="white-space:nowrap"><input type="radio" name="continent" id="Asia" onclick="update_continent();"/>Asia</label>
<label style="white-space:nowrap"><input type="radio" name="continent" id="Africa" onclick="update_continent();"/>Africa</label>
<label style="white-space:nowrap"><input type="radio" name="continent" id="Oceania" onclick="update_continent();"/>Oceania</label>
</form>
</td>
</tr>
<tr>
<td colspan=2 align="right">
Show data from last <select id="period_list" style="width:100px;" onchange="start();">
<option value="7">14 weeks</option>
<option value="14">28 weeks</option>
<option value="28">56 weeks</option>
<option value="42">84 weeks</option>
<option value="-1">All</option>
</select>
</td>
</tr>
<tr id="world_container">
<td colspan=2 align="center">
<div id="world"></div>
</td>
</tr>
</table>
<script>
start();
</script>
</body>
</html>