Skip to content

Commit

Permalink
Remove gardening.get_node(t, id) (since now it is simply t[id] )
Browse files Browse the repository at this point in the history
  • Loading branch information
jordibc committed Oct 18, 2023
1 parent 7d791a1 commit 16f9440
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 28 deletions.
18 changes: 9 additions & 9 deletions ete4/smartview/gui/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,8 +860,8 @@ def find_node(tree, args):
def get_selections(tree_id):
tid, subtree = get_tid(tree_id)
tree = app.trees[tid]
node = gdn.get_node(tree.tree, subtree)
return [ name for name, (results, _) in tree.selected.items() if node in results ]
node = tree.tree[subtree]
return [name for name, (results, _) in tree.selected.items() if node in results]


def update_node_props(node, args):
Expand Down Expand Up @@ -958,13 +958,13 @@ def change_selection_name(tid, args):
def unselect_node(tree_id, args):
tid, subtree = get_tid(tree_id)
tree = app.trees[tid]
node = gdn.get_node(tree.tree, subtree)
node = tree.tree[subtree]
name = args.pop('text', '').strip()

if name in tree.selected.keys():
selections = { name: tree.selected[name] }
selections = {name: tree.selected[name]}
else:
selections = dict(tree.selected)
selections = dict(tree.selected) # copy all

removed = False
for name, (results, parents) in selections.items():
Expand Down Expand Up @@ -1067,7 +1067,7 @@ def store_selection(tree_id, args):
def activate_node(tree_id):
tid, subtree = get_tid(tree_id)
tree = app.trees[int(tid)]
node = gdn.get_node(tree.tree, subtree)
node = tree.tree[subtree]
tree.active.nodes.results.add(node)
tree.active.nodes.parents.clear()
tree.active.nodes.parents.update(get_parents(tree.active.nodes.results))
Expand Down Expand Up @@ -1119,7 +1119,7 @@ def get_active_clades(results, parents):
def activate_clade(tree_id):
tid, subtree = get_tid(tree_id)
tree = app.trees[int(tid)]
node = gdn.get_node(tree.tree, subtree)
node = tree.tree[subtree]
tree.active.clades.results.add(node)
for n in node.descendants():
tree.active.clades.results.discard(n)
Expand Down Expand Up @@ -1151,7 +1151,7 @@ def remove_active_clade(node, active):
def deactivate_clade(tree_id):
tid, subtree = get_tid(tree_id)
tree = app.trees[int(tid)]
node = gdn.get_node(tree.tree, subtree)
node = tree.tree[subtree]
remove_active_clade(node, tree.active.clades.results)
tree.active.clades.parents.clear()
tree.active.clades.parents.update(get_parents(tree.active.clades.results))
Expand Down Expand Up @@ -1283,7 +1283,7 @@ def key(node):
'children': node.children, 'ch': node.children,
'len': len, 'sum': sum, 'abs': abs})

gdn.sort(gdn.get_node(t, node_id), key, reverse)
gdn.sort(t[node_id], key, reverse)


def add_trees_from_request():
Expand Down
20 changes: 1 addition & 19 deletions ete4/smartview/renderer/gardening.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -201,26 +201,8 @@ cdef (double, double) get_size(nodes):
return sumdists, nleaves


def get_node(tree, node_id):
"Return the node that matches the given node_id, or None"
if callable(node_id): # node_id can be a True/False function
return next((node for node in tree.traverse() if node_id(node)), None)
elif type(node_id) == str: # or the name of a node
return next((node for node in tree.traverse() if node.name == node_id), None)
elif type(node_id) == int: # or the index of a child
return tree.children[node_id]
else: # or a list/tuple of the (sub-sub-...)child
node = tree
for i in node_id:
node = node.children[i]
return node


def standardize(tree):
"Transform from a tree not following strict newick conventions"
if tree.dist == -1:
tree.dist = 0

"""Transform from a tree not following strict newick conventions."""
update_sizes_all(tree)

for node in tree.traverse():
Expand Down

0 comments on commit 16f9440

Please sign in to comment.