Data provider protocols#
Note
The NetworkDataProvider protocol requires individual providers to implement __call__ which actually processed the network, layout, and label data. We are working on simplifying this situation.
The TreeDataProvider protocol is simpler to implement as this function is standardised and needs not be implemented by individual providers. Only the support functions, which are very simple and small, needs to be implemented by tree providers.
- class iplotx.ingest.typing.NetworkDataProvider(network: Any)[source]#
Protocol for network data ingestion provider for iplotx.
- __call__(layout: str | Sequence[Sequence[float]] | ndarray | DataFrame | dict[Hashable, Sequence[float] | tuple[float, float]] | None = None, vertex_labels: Sequence[str] | dict[Hashable, str] | Series | None = None, edge_labels: Sequence[str] | dict | None = None) NetworkData[source]#
Create network data object for iplotx from any provider.
- class iplotx.ingest.typing.TreeDataProvider(tree: Any)[source]#
Protocol for tree data ingestion provider for iplotx.
- __call__(layout: str | Sequence[Sequence[float]] | ndarray | DataFrame | dict[Hashable, Sequence[float] | tuple[float, float]], layout_style: dict[str, int | float | str] | None = None, directed: bool = False, vertex_labels: Sequence[str] | dict[Hashable, str] | Series | bool | None = None, edge_labels: Sequence[str] | dict | None = None, leaf_labels: Sequence[str] | dict[Hashable, str] | Series | bool | None = None) TreeData[source]#
Create tree data object for iplotx from any tree provider.
NOTE: This function needs NOT be implemented by individual providers.
- static check_dependencies()[source]#
Check whether the dependencies for this provider are installed.
- static get_branch_length(node: Any) float | None[source]#
Get the length of the branch to this node.
- Parameters:
node – The node to get the branch length from.
- Returns:
The branch length to the node.
- get_branch_length_default_to_one(node: Any) float[source]#
Get the length of the branch to this node, defaulting to 1.0 if not available.
- Parameters:
node – The node to get the branch length from.
- Returns:
The branch length to the node, defaulting to 1.0 if not available.
- static get_children(node: Any) Sequence[Any][source]#
Get the children of a node.
- Parameters:
node – The node to get the children from.
- Returns:
A sequence of children nodes.
- get_lca(nodes: Sequence[Hashable]) Hashable[source]#
Find the last common ancestor of a sequence of nodes.
- Parameters:
nodes – The nodes to find a common ancestor for.
- Returns:
The node that is the last (deepest) common ancestor of the nodes.
NOTE: individual providers may implement more efficient versions of this function if desired.
- get_leaves(node: Any | None = None) Sequence[Any][source]#
Get the leaves of the entire tree or a subtree.
- Parameters:
node – The node to get the leaves from. If None, get from the entire tree.
- Returns:
The leaves or tips of the tree or node-anchored subtree.
- get_root() Any[source]#
Get the tree root in a provider-specific data structure.
- Returns:
The root of the tree.
Note: This is a default implemntation that can be overridden by the provider.
- get_subtree(node: Any)[source]#
Get the subtree rooted at the given node.
- Parameters:
node – The node to get the subtree from.
- Returns:
The subtree rooted at the given node.
- is_rooted() bool[source]#
Get whether the tree is rooted.
- Returns:
A boolean indicating whether the tree is rooted.
Note: This is a default implemntation that can be overridden by the provider if they support unrooted trees (e.g. Biopython).
- postorder() Iterable[Any][source]#
Postorder (DFS - child first) iteration over the tree.
- Returns:
An iterable of nodes in preorder traversal.