to_newick#

biotite.sequence.phylo.to_newick(tree: DiGraph, labels: Sequence[str] | None = None, include_distance: bool = True, round_distance: int | None = None) → str[source]#

Obtain the Newick notation of a tree.

Parameters:
treeDiGraph

The tree.

labelssequence of str, optional

The labels the leaf nodes refer to. By default, the leaf nodes themselves are used as labels.

include_distancebool, optional

If true, the "distance" attribute of the edges is written into the Newick notation, otherwise it is omitted.

round_distanceint, optional

If set, the distances are rounded to the given number of digits.

Returns:
newickstr

The Newick notation of the tree.

Examples

>>> tree = from_newick("((0:5.0,1:7.0):3.0,2:10.0);")
>>> print(to_newick(tree))
((0:5.0,1:7.0):3.0,2:10.0):0.0;
>>> print(to_newick(tree, include_distance=False))
((0,1),2);
>>> labels = ["foo", "bar", "foobar"]
>>> print(to_newick(tree, labels=labels, include_distance=False))
((foo,bar),foobar);