-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
284 lines (247 loc) · 10.5 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
<!DOCTYPE html>
<meta charset="utf-8">
<head>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<!-- Load the javascript libraries -->
<script src="dependencies/jquery.min.js"></script>
<script src="dependencies/d3.v4.min.js"></script>
<script src="dependencies/d3-selection-multi.v1.js"></script>
<script src="dependencies/tinycolor.js"></script>
<script src="dependencies/numeric.js"></script>
<script src="dependencies/svd.js"></script>
<script src="oncotreevis.js"></script>
<script src="display_tree.js"></script>
<script src="display_tree_matching.js"></script>
<script src="dgidb_query_response.js"></script>
<!-- Load tree datasets -->
<script src="data/aml_morita/trees_aml_morita.json"></script>
<script src="data/aml_morita/knn_aml_morita.json"></script>
<script src="data/aml_compass/trees_aml_compass.json"></script>
<!-- <script src="data/brca_razavi/trees_brca_razavi.json"></script> -->
<script src="data/tracerx/tracerx_lung/trees_tracerx_lung.json"></script>
<script src="data/tracerx/tracerx421/trees_tracerx421.json"></script>
<script src="data/noble2022/trees_noble2022.json"></script>
</head>
<body style="margin-top: 5px; margin-left: 5px; margin-right: 5px;">
<div style="display: flex">
<div style="background-color: #b4a7d6; flex-grow: 1; height: 60px"></div>
<div style="width: 300px; height: 60px; background: radial-gradient(#ffffff 0%, #b4a7d6); text-align: center; ">
<p id="logo" style="font-family:calibri; font-size:40px; letter-spacing: 0.5px;"><b> oncotreeVIS </b></p>
</div>
<div style="background-color: #b4a7d6; height: 60px; padding-top:5px;">
<a style="text-decoration: none" href="https://github.com/cbg-ethz/oncotreeVIS" target="new">
<i class="fa fa-github" style="font-size:48px; color:#353935"></i> </a>
</div>
</div><br/>
<div width="100%" style="font-size: 13px;">
Select predefined or custom mutation tree cohort: <select id="drop-down-cohort"></select><br/>
<input type="file" id="picker" onchange="load()" style="display:none">
</div><br/>
<div width=100% id="container"> </div>
<script>
function load () {
// Get selected file.
let file = document.getElementById("picker").files[0];
// Read selected file.
let reader = new FileReader();
reader.onload = () => {
let data = JSON.parse(reader.result);
oncotreeVIS(data, "container")
};
reader.readAsText(file);
}
</script>
<script>
datasets = {
"[CLUSTERED] 123 AML point mutation trees (Morita et al. 2020)": {"data": data_aml_morita, "matching_trees": knn_aml_morita},
"145 AML joint CN-point mutation trees (COMPASS, Sollier et al. 2022)": {"data": data_aml_compass},
//"[CLUSTERED] 25 TumorProfiler AML CN trees": {"data": data_tupro_aml},
"[CLUSTERED] 43 tumor evolution trees (Noble et al. 2022)": {"data": data_noble2022},
"[CLUSTERED] 99 non-small cell lung cancer point mutation trees (TRACERx, Jamal-Hanjani et al. 2017)": {"data": data_tracerx_lung},
"126 non-small cell lung metastatic cancer point mutation trees (TRACERx421, Al Bakir et al. 2023)": {"data": data_tracerx421},
//"1,315 Breast cancer mutation trees (Razavi et al. 2018)": {"data": data_brca_razavi},
"--> Load custom mutation tree cohort file (specific input format required)": {}
}
var drop_down_cohorts = document.getElementById("drop-down-cohort")
Object.keys(datasets).forEach(function (dataset, idx) {
drop_down_cohorts.options[drop_down_cohorts.options.length] = new Option(dataset, idx);
})
$('#drop-down-cohort').change(function(){
e = document.getElementById("drop-down-cohort")
var cohort_name = e.options[e.selectedIndex].text
if (cohort_name.includes("custom mutation tree cohort")) {
$('input[type=file]').trigger('click');
} else {
data = datasets[cohort_name]["data"]
data["matching_trees"] = datasets[cohort_name]["matching_trees"]
oncotreeVIS(data, "container")
}
});
data = data_aml_morita
data["matching_trees"] = knn_aml_morita
oncotreeVIS(data, "container")
/////// OncotreeVIS LIBRARY
function oncotreeVIS(data, container_div_id) {
var num_max_node_colors = 10
var tree_cohort_div_id = "tree_cohort"
var tree_info_div_id = "tree_info"
// Compute additional information from the data.
trees = data["trees"]
// Additional data to all trees.
unique_matching_labels_cohort = {} // map {matching_label: bool}
for (sample_name in trees) {
tree = trees[sample_name]["tree"]
matching_labels = getMatchingLabels(tree)
for (matching_label of matching_labels) {
key = matching_label.toString()
if (key in unique_matching_labels_cohort) {
unique_matching_labels_cohort[key] = false
} else {
unique_matching_labels_cohort[key] = true
}
}
}
display_matching_labels = false
num_non_unique_matching_labels = Object.values(unique_matching_labels_cohort).filter(x => x == false).length
if(num_non_unique_matching_labels > num_max_node_colors) {
display_matching_labels = true
}
cohort_node_color_map = {}
cohort_node_color_generator = new ColorGenerator(node_colors, shuffle=true, transparent_flavour=0.3)
for (key in unique_matching_labels_cohort) {
if (!unique_matching_labels_cohort[key]) {
cohort_node_color_map[key] = cohort_node_color_generator.next()
}
}
for (sample_name in trees) {
tree = trees[sample_name]["tree"]
// Propagate gene states.
populateGeneStates(tree)
// Populate the node colors.
var node_list = getTreeNodes(trees[sample_name]["tree"])
for(node of node_list) {
if (node.parent && node.data.matching_label) { // not root.
key = node.data.matching_label.toString()
if (key in cohort_node_color_map) {
node.data.color_in_cohort = cohort_node_color_map[key]
node.data.display_node_label_cohort = display_matching_labels
}
}
}
}
// Clusters.
if ("clusters" in data && data["clusters"].length != 0) {
clusters = data["clusters"]
} else {
clusters = [Object.keys(trees)] // One big cluster.
}
// Colors at cluster level.
used_colors = {}
cluster_color_generator = new ColorGenerator(background_colors, shuffle=false, transparent_flavour=0.7)
cluster_node_color_generator = new ColorGenerator(node_colors, shuffle=true, transparent_flavour=0.3)
for (const [i, cluster] of clusters.entries()) {
conserved_branches_cluster = getBranches(trees[cluster[0]]["tree"])
unique_matching_labels_cluster = {}
for (sample_name of cluster) {
// Cluster colors.
trees[sample_name]["cluster_color"] = "white"
trees[sample_name]["2d_color"] = "white"
// Nodes and branches.
tree = trees[sample_name]["tree"]
conserved_branches_cluster = conserved_branches_cluster.intersection(getBranches(tree))
matching_labels = getMatchingLabels(tree)
for (matching_label of matching_labels) {
key = matching_label.toString()
if (key in unique_matching_labels_cluster) {
unique_matching_labels_cluster[key] = false
} else {
unique_matching_labels_cluster[key] = true
}
}
}
display_matching_labels = false
num_non_unique_matching_labels = Object.values(unique_matching_labels_cluster).filter(x => x == false).length
if(num_non_unique_matching_labels > num_max_node_colors) {
display_matching_labels = true
}
if (cluster.length > 1 && clusters.length > 1) {
cluster_color = cluster_color_generator.next()
cluster_node_color_map = {}
for (key in unique_matching_labels_cluster) {
if (!unique_matching_labels_cluster[key]) {
if (key in used_colors) {
cluster_node_color_map[key] = used_colors[key]
} else {
color = cluster_node_color_generator.next()
cluster_node_color_map[key] = color
used_colors[key] = color
}
}
}
for (sample_name of cluster) {
// Update cluster colors.
trees[sample_name]["cluster_color"] = cluster_color
trees[sample_name]["2d_color"] = tinycolor(cluster_color).darken(50).toHexString()
// For each cluster tree populate node colors and conserved branches.
for (sample_name of cluster) {
var node_list = getTreeNodes(trees[sample_name]["tree"])
for(node of node_list) {
if(node.parent) { // not root.
// Conserved branches.
if (conserved_branches_cluster.has(node.parent.data.matching_label + "_" + node.data.matching_label)) {
node.data.conserved_parent_node_edge_cluster = true
}
// Matching nodes.
if (node.parent && node.data.matching_label) {
key = node.data.matching_label.toString()
if (key in cluster_node_color_map) {
node.data.color_in_cluster = cluster_node_color_map[key]
node.data.display_node_label_cluster = display_matching_labels
}
}
}
}
}
}
// Cluster metadata.
var sample_metadata_map = {}
for (sample_name of cluster) {
if ("metadata" in trees[sample_name]) {
sample_metadata = trees[sample_name]["metadata"]
sample_metadata_map[sample_name] = sample_metadata
}
}
[sample_metadata_colors, metadata_color_map] = getMetadataColorMap(sample_metadata_map)
table_color_codes = getColorCodesTable(metadata_color_map)
trees[cluster[0]]["sample_metadata_colors"] = sample_metadata_colors
trees[cluster[0]]["table_color_codes"] = table_color_codes
}
}
// END Populate additional data.
var useful_variables = {
"tree_cohort_div_id": tree_cohort_div_id,
"tree_info_div_id": tree_info_div_id,
"data": data,
"sorting": 0,
"matching": 0
}
// DGIdb data.
var gene_drug_map = parseGeneDrugInteractions(gene_drug_interaction)
// Create the HTML elements.
addHTMLElements(container_div_id, useful_variables)
// Populate with tree data.
populateTreeView(useful_variables)
}
$(function(){
var container = $('#tree_info');
var initial_position = container.position().top
$(document).scroll(function() {
scroll_offset = $(document).scrollTop()
container.css('top', Math.max(0, initial_position - scroll_offset));
});
});
</script>
</body>