TreeNode.unrooted_copy(parent=None, branch_attrs={'length', 'name', 'support'}, root_name='root', deep=False)[source]#

Walk the tree unrooted-style and return a copy.

parentTreeNode or None

Direction of walking (from parent to self). If specified, walking to the parent will be prohibited.

branch_attrsset of str, optional

Attributes of TreeNode objects that should be considered as branch attributes during the operation.

Added in version 0.6.2.


name will be removed from the default in 0.7.0, as it is usually considered as an attribute of the node instead of the branch.

root_namestr or None, optional

Name for the new root node, if it doesn’t have one.

Added in version 0.6.2.


This parameter will be removed in 0.7.0, and the root node will not be renamed.

deepbool, optional

Whether perform a shallow (False, default) or deep (True) copy of node attributes.

Added in version 0.6.2.


A new copy of the tree rooted at the given node.

Changed in version 0.6.2: Node attributes other than name and length will also be copied.


The default behavior of unrooted_copy is subject to change in 0.7.0. The new default behavior can be achieved by specifying branch_attrs={"length", "support"}, root_name=None.

See also



This method recursively walks a tree from a given node in an unrooted style (i.e., directions of branches are not assumed), and copies each node it visits, such that the copy of the given node becomes the root node of a new tree and the copies of all other nodes are re-positioned accordingly, whereas the topology of the new tree will be identical to the existing one.


>>> from skbio import TreeNode
>>> tree =["((a,(b,c)d)e,(f,g)h)i;"])
>>> new_tree = tree.find('d').unrooted_copy()
>>> print(new_tree)