scikit-bio is back in active development! Check out our announcement of revitalization.

skbio.tree.TreeNode.unrooted_copy#

TreeNode.unrooted_copy(parent=None)[source]#

Walk the tree unrooted-style and returns a copy.

Perform a copy of self and return a new copy of the tree as an unrooted copy. This is useful for defining new roots of the tree as the TreeNode.

This method is recursive.

Warning, this is _NOT_ a deepcopy

Parameters:
parentTreeNode or None

Used to avoid infinite loops when performing the unrooted traverse

Returns:
TreeNode

A new copy of the tree

Examples

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