Skip to content

Commit

Permalink
fixed depth_key check in plotting
Browse files Browse the repository at this point in the history
  • Loading branch information
colganwi committed Aug 23, 2024
1 parent e955b42 commit bda407b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/pycea/pl/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import numpy as np
from scanpy.plotting import palettes

from pycea.utils import get_leaves, get_root
from pycea.utils import check_tree_has_key, get_leaves, get_root


def layout_nodes_and_branches(
Expand Down Expand Up @@ -117,13 +117,12 @@ def layout_trees(
leaves = []
depths = []
for _, tree in trees.items():
check_tree_has_key(tree, depth_key)
tree_leaves = get_leaves(tree)
leaves.extend(tree_leaves)
depths.extend(tree.nodes[leaf].get(depth_key) for leaf in tree_leaves)
if len(depths) != len(leaves):
raise ValueError(
f"Tree does not have {depth_key} attribute. You can run `pycea.pp.add_depth` to add depth attribute."
)
raise ValueError(f"Every node in the tree must have a {depth_key} attribute. ")
max_depth = max(depths)
n_leaves = len(leaves)
leaf_coords = {}
Expand Down
2 changes: 1 addition & 1 deletion src/pycea/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def check_tree_has_key(tree: nx.DiGraph, key: str):
sampled_nodes = random.sample(list(tree.nodes), min(10, len(tree.nodes)))
for node in sampled_nodes:
if key not in tree.nodes[node]:
message = f"Tree does not have {key} attribute."
message = f"Tree nodes to not have {key} attribute."
if key == "depth":
message += " You can run `pycea.pp.add_depth` to add depth attribute."
raise ValueError(message)
Expand Down

0 comments on commit bda407b

Please sign in to comment.