phylox.newick_parser.dinetwork_to_extended_newick

phylox.newick_parser.dinetwork_to_extended_newick(network, simple=False)

Converts a phylogenetic network to a Newick string. The newick string has :length:bootstrap:probability annotations if any edge has a bootstrap or probability. If only lengths are available, the newick string has :length annotations.

Parameters:
  • network – a phylogenetic network, i.e., a phylox DiNetwork.

  • simple – Boolean, indicating whether to create a simple newick string without parameters

Returns:

a string in extended Newick format for phylogenetic networks.

Example:

>>> from phylox import DiNetwork
>>> from phylox.constants import LENGTH_ATTR
>>> from phylox.newick_parser import dinetwork_to_extended_newick
>>> network = DiNetwork(
...     edges=[
...         (0, 1, {LENGTH_ATTR: 1.0}),
...         (0, 2, {LENGTH_ATTR: 1.0}),
...         (1, 3, {LENGTH_ATTR: 1.0}),
...         (2, 3, {LENGTH_ATTR: 1.0}),
...         (1, 4, {LENGTH_ATTR: 1.0}),
...         (2, 5, {LENGTH_ATTR: 1.0}),
...         (3, 6, {LENGTH_ATTR: 1.0}),
...     ],
...     labels=((0, "A"), (4, "B"), (5, "C"), (6, "D"), (3, "E")),
... )
>>> newick = dinetwork_to_extended_newick(network)
>>> "C:1.0" in newick
True