Skip to content

Commit

Permalink
Phylo: handle branch widths in to_networkx and draw_graphviz
Browse files Browse the repository at this point in the history
Oops from last two commits: the attribute name is 'width', not 'weight' and
definitely not 'water'.

See Bug 3047 -- this closes it.
  • Loading branch information
etal committed Apr 8, 2010
1 parent f2a52d6 commit 1ea0c92
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions Bio/Phylo/_utils.py
Expand Up @@ -79,12 +79,12 @@ def add_edge(graph, n1, n2):
graph[n1][n2]['color'] = n1.color.to_hex()
n2.color = n1.color
# Copy branch weight value (float) if available
if hasattr(n2, 'weight') and n2.weight is not None:
graph[n1][n2]['weight'] = n2.weight
elif hasattr(n1, 'weight') and n1.weight is not None:
# Cascading weight attributes
graph[n1][n2]['weight'] = n1.weight
n2.weight = n1.weight
if hasattr(n2, 'width') and n2.width is not None:
graph[n1][n2]['width'] = n2.width
elif hasattr(n1, 'width') and n1.width is not None:
# Cascading width attributes
graph[n1][n2]['width'] = n1.width
n2.width = n1.width
elif networkx.__version__ >= '0.99':
graph.add_edge(n1, n2, (n2.branch_length or 1.0))
else:
Expand Down Expand Up @@ -194,6 +194,10 @@ def get_label_mapping(G, selection):
kwargs['edge_color'] = [isinstance(e[2], dict)
and e[2].get('color', 'k') or 'k'
for e in G.edges(data=True)]
if 'width' not in kwargs:
kwargs['width'] = [isinstance(e[2], dict)
and e[2].get('width', 1.0) or 1.0
for e in G.edges(data=True)]
networkx.draw(G, posn, labels=labels, node_color=node_color, **kwargs)


Expand Down

0 comments on commit 1ea0c92

Please sign in to comment.