phylox.dinetwork.remove_unlabeled_leaves

phylox.dinetwork.remove_unlabeled_leaves(network, inplace=True)

Iteratively removes unlabeled leaves until none are left, then suppresses all degree-2 nodes.

Parameters:
  • network (phylox.DiNetwork) – The network to remove unlabeled leaves from.

  • inplace (bool) – Whether to modify the network in place or return a copy.

Returns:

The network with unlabeled leaves removed.

Return type:

phylox.DiNetwork

Examples

>>> from phylox import DiNetwork
>>> from phylox.constants import LABEL_ATTR
>>> network = DiNetwork(
...     edges=[(0, 1), (1, 2), (1, 3), (3, 4), (3, 5)],
...     labels=[(2, 'a'), (4, 'b')],
... )
>>> network = remove_unlabeled_leaves(network)
>>> network.edges()
OutEdgeView([(0, 1), (1, 2), (1, 4)])
>>> network.nodes(data=True)
NodeDataView({0: {}, 1: {}, 2: {'label': 'a'}, 4: {'label': 'b'}})