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
|
function remove_children(element) {
Array.from(element.children).forEach(child => {
element.removeChild(child);
});
}
function trigger_change_event(element) {
evt = new Event("change");
element.dispatchEvent(evt);
}
function setup_groups(group_data) {
elt = document.getElementById("group");
remove_children(elt);
the_groups = group_data.reduce(
function(acc, row) {
grouping = row[2].slice(7).trim();
if(acc[grouping] === undefined) {
acc[grouping] = [];
}
acc[grouping].push([row[0], row[1]]);
return acc;
},
{});
for(grouping in the_groups) {
optgrp = document.createElement("optgroup");
optgrp.setAttribute("label", grouping);
the_groups[grouping].forEach(group => {
opt = document.createElement("option");
opt.setAttribute("value", group[0]);
opt.appendChild(document.createTextNode(group[1]));
optgrp.appendChild(opt);
});
elt.appendChild(optgrp);
}
trigger_change_event(elt);
}
function setup_types(type_data) {
elt = document.getElementById("type");
remove_children(elt);
the_types = type_data.reduce(function(acc, row) {
grp = row[2];
if(acc[grp] === undefined) {
acc[grp] = [];
}
acc[grp].push([row[0], row[1]]);
return acc;
}, {});
for(type_group in the_types) {
optgrp = document.createElement("optgroup");
optgrp.setAttribute("label", type_group);
the_types[type_group].forEach(type => {
opt = document.createElement("option");
opt.setAttribute("value", type[0]);
opt.appendChild(document.createTextNode(type[1]));
optgrp.appendChild(opt);
});
elt.appendChild(optgrp);
}
trigger_change_event(elt);
}
function setup_datasets(dataset_data) {
elt = document.getElementById("dataset");
remove_children(elt);
dataset_data.forEach(dataset => {
opt = document.createElement("option");
opt.setAttribute("value", dataset[0]);
opt.appendChild(document.createTextNode(
"[" + dataset[1] + "] " + dataset[2]));
elt.appendChild(opt);
});
trigger_change_event(elt);
}
function radio_column(chip) {
col = document.createElement("td");
radio = document.createElement("input");
radio.setAttribute("type", "radio");
radio.setAttribute("name", "genechipid");
radio.setAttribute("value", chip["GeneChipId"]);
radio.setAttribute("required", "required");
col.appendChild(radio);
return col;
}
function setup_genechips(genechip_data) {
columns = ["GeneChipName", "Name", "GeoPlatform", "GO_tree_value"]
submit_button = document.querySelector(
"#select-dataset-form input[type='submit']");
elt = document.getElementById(
"genechips-table").getElementsByTagName("tbody")[0];
remove_children(elt);
if((genechip_data === undefined) || genechip_data.length === 0) {
row = document.createElement("tr");
col = document.createElement("td");
col.setAttribute("colspan", "5");
text = document.createTextNode("No chips found for selected species");
col.appendChild(text);
row.appendChild(col);
elt.appendChild(row);
submit_button.setAttribute("disabled", true);
return false;
}
submit_button.removeAttribute("disabled")
genechip_data.forEach(chip => {
row = document.createElement("tr");
row.appendChild(radio_column(chip));
columns.forEach(column => {
col = document.createElement("td");
content = document.createTextNode(chip[column]);
col.appendChild(content);
row.appendChild(col);
});
elt.appendChild(row);
});
}
function menu_contents() {
return JSON.parse(
document.getElementById("select-dataset-form").getAttribute(
"data-menu-content"));
}
function genechips() {
return JSON.parse(
document.getElementById("select-dataset-form").getAttribute(
"data-genechips"));
}
function update_menu(event) {
menu = menu_contents();
genec = genechips();
species_elt = document.getElementById("species");
group_elt = document.getElementById("group");
type_elt = document.getElementById("type");
dataset_elt = document.getElementById("dataset");
if(event.target == species_elt) {
setup_groups(menu["groups"][species_elt.value]);
setup_genechips(genec[species_elt.value.toLowerCase()]);
}
if(event.target == group_elt) {
setup_types(menu["types"][species_elt.value][group_elt.value]);
}
if(event.target == type_elt) {
setup_datasets(
menu["datasets"][species_elt.value][group_elt.value][type_elt.value]
);
}
}
|