From 0dca4e5ccf4c574f2627b3aa7a7b5fdc477a9a42 Mon Sep 17 00:00:00 2001 From: Monica Dragan Date: Tue, 29 Oct 2024 22:53:00 +0100 Subject: [PATCH] updates --- display_tree.js | 4 +-- oncotreevis.js | 89 ++++++++++++++++++++++++++----------------------- 2 files changed, 50 insertions(+), 43 deletions(-) diff --git a/display_tree.js b/display_tree.js index 6b17f19..d267b66 100755 --- a/display_tree.js +++ b/display_tree.js @@ -305,7 +305,7 @@ function displayTree(div_id, tree_label, tree_data, target_gene, target_drug, dr max_genes_in_list = 4 node.on('mousemove', function(d) { // Compute html info. - if (d.parent && mapSize(d.data.gene_events) != 0) { + if (d.parent) { html_info = "" if (d.data.matching_label) { html_info += "Matching label: " + d.data.matching_label + "
" @@ -319,7 +319,7 @@ function displayTree(div_id, tree_label, tree_data, target_gene, target_drug, dr } var gene_events = d.data.gene_event_categories var gene_events_with_details = d.data.gene_event_categories_details - if (gene_events.size) { + if (gene_events) { html_info += "

Gene events:
" var keys = Array.from(gene_events.keys()).sort().reverse() for (event of keys) { diff --git a/oncotreevis.js b/oncotreevis.js index 82db41d..c87ba70 100644 --- a/oncotreevis.js +++ b/oncotreevis.js @@ -29,7 +29,7 @@ function oncotreeVIS(data, container_div_id) { tree = trees[sample_name]["tree"] matching_labels = new Set(Array.from(getTreeMalignantMatchingLabels(tree).keys())) for (let matching_label of matching_labels) { - key = matching_label.toString() + key = matching_label if (key in unique_matching_labels_cohort) { unique_matching_labels_cohort[key] = false } else { @@ -194,40 +194,46 @@ function oncotreeVIS(data, container_div_id) { // kNN knn_json = {} - for (sample_1 in trees) { - tree_1 = trees[sample_1]["tree"] - var matching_labels = new Set(Array.from(getTreeMalignantMatchingLabels(tree_1).keys())) - matching_tree_ids = new Set() - for (let key of matching_labels) { - for (let sample of matching_label_tree_map.get(key)) { - matching_tree_ids.add(sample) - } - } - for (let sample_2 of matching_tree_ids) { - if (sample_1 != sample_2) { - var tree_2 = trees[sample_2]["tree"] - var matching_node_pairs = getMatchingNodes(getTreeNodes(tree_1), getTreeNodes(tree_2)) - const [nodes_1, links_1, max_depth_1] = getJSONNodes(sample_1, tree_1) - const [nodes_2, links_2, max_depth_2] = getJSONNodes(sample_2, tree_2) - const max_depth = Math.max(max_depth_1, max_depth_2) - nodes = nodes_1.concat(nodes_2) - links = links_1.concat(links_2) - for (let pair of matching_node_pairs) { - links.push({ - "source": sample_1 + "_" + pair[0].data.node_id, - "target": sample_2 + "_" + pair[1].data.node_id, - "similarity": 1, - }) - } - knn_json[sample_1 + "_" + sample_2] = { - "sample_1": sample_1, - "sample_2": sample_2, - "nodes": nodes, - "links": links, - "similarity": matching_node_pairs.length, - "max_depth": max_depth + if(mapSize(trees) < 200) { + for (let sample_1 in trees) { + tree_1 = trees[sample_1]["tree"] + //var matching_tree_ids = Object.keys(trees) + var matching_labels = new Set(Array.from(getTreeMalignantMatchingLabels(tree_1).keys())) + matching_tree_ids = new Set() + for (let key of matching_labels) { + for (let sample of matching_label_tree_map.get(key)) { + matching_tree_ids.add(sample) } - } + } + for (let sample_2 of matching_tree_ids) { + if (sample_1 != sample_2) { + var tree_2 = trees[sample_2]["tree"] + var matching_node_pairs = getMatchingNodes(getTreeNodes(tree_1), getTreeNodes(tree_2)) + if (!matching_node_pairs[0]) { + continue + } + const [nodes_1, links_1, max_depth_1] = getJSONNodes(sample_1, tree_1) + const [nodes_2, links_2, max_depth_2] = getJSONNodes(sample_2, tree_2) + const max_depth = Math.max(max_depth_1, max_depth_2) + nodes = nodes_1.concat(nodes_2) + links = links_1.concat(links_2) + for (let pair of matching_node_pairs) { + links.push({ + "source": sample_1 + "_" + pair[0].data.node_id, + "target": sample_2 + "_" + pair[1].data.node_id, + "similarity": 1, + }) + } + knn_json[sample_1 + "_" + sample_2] = { + "sample_1": sample_1, + "sample_2": sample_2, + "nodes": nodes, + "links": links, + "similarity": matching_node_pairs.length, + "max_depth": max_depth + } + } + } } } data["matching_trees"] = knn_json @@ -505,12 +511,12 @@ function populateTreeView(args){ tree_info_div = document.getElementById(tree_info_div_id) tree_info_div.innerHTML = '
The tree clusters are indicated by
' + - 'different background colo'+ + ' different background colo'+ 'rs.
' + - ' Zoom out to get the
full overview of the tree clusters.

***

' + - 'Click on the trees to visualize
details of each subclone.

' + - 'Click on the " show cluster details" icons
' + - 'to visualize additional cluster information.'+ + ' Zoom out to get the
full overview of the tree clusters.

***

' + + ' Click on the trees to visualize
details of each subclone.

' + + ' Click on the " show cluster details" icons
' + + ' to visualize additional cluster information.'+ '
' tree_info_div.style.backgroundColor = "white" @@ -775,7 +781,8 @@ function getTreeNodes(tree_json) { function getMalignantMatchingLabels(node_list){ var node_map = new Map() for (node of node_list) { - if (node.data.matching_label && !node.data.is_neutral && mapSize(node.data.gene_states)) { + if ((!node.parent && mapSize(node.data.gene_states)) || + (node.parent && node.data.matching_label && !node.data.is_neutral)) { node_map.set(node.data.matching_label, node) } } @@ -1757,7 +1764,7 @@ function populateHeatmapView(args) { div_tree_info.style.backgroundColor = "transparent" div_tree_info.innerHTML = "
Click on the sample names
and" + - " on the colored frames
(corresponding to the given tree clusters)
to visualize additional information.
" + " on the colored frames
(corresponding to the given tree clusters)
to visualize additional information." // Data. data = args.data