skbio.tree.TreeNode.unrooted_copy#
- 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.
- Parameters:
- 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.
Note
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.
Note
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.
- Returns:
- TreeNode
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.
Warning
The default behavior of
unrooted_copy
is subject to change in 0.7.0. The new default behavior can be achieved by specifyingbranch_attrs={"length", "support"}, root_name=None
.See also
Notes
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.
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;