/
misc.js
101 lines (83 loc) · 2.42 KB
/
misc.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
const $ = require('jquery');
class Misc {
static isString(obj) {
return (Object.prototype.toString.call(obj) === '[object String]');
}
static get chromosomeLabels() {
return new Array(22).fill(0, 0, 22).map((x,i) => `${(i + 1)}`).concat(['X','Y','M']);
}
static get connectionLabels() {
return ['LOOSE', 'REF', 'ALT'];
}
static unique(array) {
return Object.assign([],array).filter((value, index, self) => {
return self.indexOf(value) === index;
});
}
static get server() {
return 'http://localhost:8000'
}
static alerting(text, type) {
return $('#detail').append(`<div class="alert alert-${type}" role="alert">${text}</div>`);
}
static get metadata() {
var input = (function () {
var json = null;
$.ajax({
'async': false,
'global': false,
'url': Misc.server + '/metadata',
'dataType': 'json',
'success': (data) => {
json = data;
}
});
return json;
})();
return input.metadata;
}
static intervals(startPlace, endPlace) {
var input = (function () {
var json = null;
$.ajax({
'async': false,
'global': false,
'url': Misc.server + '/intervals',
'data': {"startPlace": startPlace, "endPlace": endPlace},
'dataType': 'json',
'success': (data) => {
json = data;
}
});
return json;
})();
return input.map((d,i) => { return new Interval(d)});
}
static get guid() {
function S4() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
// then to call it, plus stitch in '4' in the third group
return (S4() + S4() + "-" + S4() + "-4" + S4().substr(0,3) + "-" + S4() + "-" + S4() + S4() + S4()).toLowerCase();
}
static magnitude(n) {
let order = Math.floor(Math.log(n) / Math.LN10 + 0.000000001); // because float math sucks like that
return Math.pow(10, order);
}
//static groupBy(list, keyGetter) {
// const map = new Map();
// list.forEach((item) => {
// const key = keyGetter(item);
// const collection = map.get(key);
// if (!collection) {
// map.set(key, [item]);
// } else {
// collection.push(item);
// }
// });
// return map;
// }
}
module.exports = {
Misc : Misc
}