Skip to main content
`Ctrl`+`K`

# skbio.tree.TreeNode.unrooted_copy

TreeNode.unrooted_copy(parent=None, branch_attrs={'length', 'support'}, root_name=None, deep=False, exclude_attrs=None)

  Walk the tree unrooted-style and return a copy.

  Parameters:
    parent TreeNode or None

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

    branch_attrs set of str, optional

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

      Added in version 0.6.2.

      Changed in version 0.7.0: Removed `name` from the default values.

    root_name str or None, optional

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

      Added in version 0.6.2.

      Changed in version 0.7.0: Set the default value to None.

    deep bool, optional

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

      Added in version 0.6.2.

    exclude_attrs set, optional

      Node attributes that should not be copied. If None (default), the caches will be excluded. This parameter keeps a memo during recursive copying for efficiency. It should not be customized by the user unless absolutely needed.

      Added in version 0.6.3.

  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.

  See also

  `copy`
  `unrooted_move`

  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.

  Nodes attributes except for caches will be copied to the new tree. Attributes in `branch_attrs` will be transferred to the node at the other end of a branch if the branch is flipped in the new 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)i)e)d;