I am trying to implement automated node collapsing on large trees. When the tree is initially loaded, I want to collapse all nodes except for important nodes. I design this by saying if the leaf node A is important then keep all its ancestors uncollapsed till the root. I defined important nodes as a part of the annotation.json file which is supplied along with the tree file. I have implemented the solution using toggleCollapse and tree traverse_and_compute function. It works but gives some error. I think the error may be due to collapsing a parent whose child is already collapse? am not sure why this is happening and if there is better way for me to code for this functionality.
// Construct a tree
tree = new phylotree.phylotree(test_string); global_tree = tree;
// Get the list of nodes not to be collapsed nodes_not_collpase = do_not_collapse(tree,metadata["important"]);
// Traverse the tree and collapse everything except for the important nodes
tree.traverse_and_compute ((n) => { if ((nodes_not_collpase.includes(n.data.name) == false) && (tree.isLeafNode(n) == false)){ rendered_tree.toggleCollapse(n); } }); rendered_tree.update();
I found the root cause of the issue. If you run multiple collapse on the clade recursively as you travel upwards the tree, it cannot find the attributes. I handled this. Will close this issue.
Hello,
I am trying to implement automated node collapsing on large trees. When the tree is initially loaded, I want to collapse all nodes except for important nodes. I design this by saying if the leaf node A is important then keep all its ancestors uncollapsed till the root. I defined important nodes as a part of the annotation.json file which is supplied along with the tree file. I have implemented the solution using toggleCollapse and tree traverse_and_compute function. It works but gives some error. I think the error may be due to collapsing a parent whose child is already collapse? am not sure why this is happening and if there is better way for me to code for this functionality.
// Construct a tree
tree = new phylotree.phylotree(test_string); global_tree = tree;
// Get the list of nodes not to be collapsed
nodes_not_collpase = do_not_collapse(tree,metadata["important"]);
// Traverse the tree and collapse everything except for the important nodes
tree.traverse_and_compute ((n) => { if ((nodes_not_collpase.includes(n.data.name) == false) && (tree.isLeafNode(n) == false)){ rendered_tree.toggleCollapse(n); } }); rendered_tree.update();
TREE:
ERROR:
Thank you for your help.