You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current visualization function create_similarity_graphviz is specific to visualizing the similarity between two nodes.
It's common that the user has a known subset of nodes for which they'd like to visualize the subgraph. Some flexibility is needed to allow users to pick how they'd like to label nodes and to apply additional styling. So proposing utility functions to help create subgraphs for graphviz visualizations.
Some existing code below that might be helpful
Expand for code
# code used to create figures at https://github.com/EBISPOT/efo/issues/926#issuecomment-760366239fromnxontologyimportNXOntologyfromtypingimportIterablefromnxontology.ontologyimportNodefromnxontology.vizimportget_hex_colorfromnetworkx.drawing.nx_agraphimportto_agraphfrompygraphviz.agraphimportAGraphfromIPython.displayimportImagedefcreate_subgraph_for_graphviz(
nxo: NXOntology,
nodes: Iterable[Node],
) ->"NXOntology":
nodes=set(nodes)
# independent shallow copy: creates new independent attribute dictssubgraph=nxo.graph.subgraph(nodes).copy()
# node labels and fill/font colorsfornode, datainsubgraph.nodes(data=True):
info=nxo.node_info(node)
ifinfo.label:
data["label"] =info.nameifinfo.identifier:
data["tooltip"] =info.identifierifinfo.url:
data["URL"] =info.urlreturnsubgraphdefcreate_graphviz(
nxo: NXOntology,
nodes: Iterable[Node],
outline_nodes: Iterable[Node],
keyword: str,
) ->"AGraph":
nodes=set(nodes)
outline_nodes=set(outline_nodes)
subgraph=create_subgraph_for_graphviz(nxo, nodes)
fornode, datainsubgraph.nodes(data=True):
data["style"] ="filled"info=nxo.node_info(node)
data["label"] = (
f"<{info.name}<br/>"'<font point-size="9">'f"{info.n_descendants:,} descendants · IC<sub>res</sub> {info.intrinsic_ic_scaled:.2f}""</font>>"
)
scaled_ic=info.intrinsic_ic_scaleddata["fillcolor"] =get_hex_color(scaled_ic)
data["fontcolor"] ="#ffffff"ifscaled_ic>0.7else"#000000"# node stylesfornodeinnodes-outline_nodes:
subgraph.nodes[node]["penwidth"] =1.0fornodeinnodes&outline_nodes:
subgraph.nodes[node]["penwidth"] =4.0subgraph.nodes[node]["color"] ="#b400b4"subgraph.nodes[node]["style"] +=",solid"# titlesubgraph.graph["label"] =f"Nodes {keyword} by EFO-OTAR (purple online) and their ancestors"subgraph.graph["labelloc"] ="t"# raster resolutionsubgraph.graph["dpi"] =125gviz=to_agraph(subgraph)
gviz.layout("dot")
returngviz# elsewhere have found wrapped names in labels is helpfulimporttextwrapname_wrapped="<br/>".join(textwrap.wrap(info.name, width=10, break_long_words=False))
# and finally to plot in a Jupyter notebookImage(gviz.draw(format="png"))
The text was updated successfully, but these errors were encountered:
The current visualization function
create_similarity_graphviz
is specific to visualizing the similarity between two nodes.It's common that the user has a known subset of nodes for which they'd like to visualize the subgraph. Some flexibility is needed to allow users to pick how they'd like to label nodes and to apply additional styling. So proposing utility functions to help create subgraphs for graphviz visualizations.
Some existing code below that might be helpful
Expand for code
The text was updated successfully, but these errors were encountered: