skbio.tree.TreeNode.copy#

TreeNode.copy(deep=True)[source]#

Return a copy of self using an iterative approach.

Parameters:
deepbool, optional

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

Added in version 0.6.2.

Note

The default value will be changed to False in 0.7.0.

Returns:
TreeNode

A new copy of self.

See also

unrooted_copy

Notes

This method iteratively copies the current node and its descendants. That is, if the current node is not the root of the tree, only the subtree below the node, instead of the entire tree, will be copied.

All nodes and their attributes will be copied. The copies are new objects rather than references to the original objects. The distinction between deep and shallow copies only applies to each node attribute.

Examples

>>> from skbio import TreeNode
>>> tree = TreeNode.read(["((a,b)c,(d,e)f)root;"])
>>> tree_copy = tree.copy()
>>> tree_nodes = set([id(n) for n in tree.traverse()])
>>> tree_copy_nodes = set([id(n) for n in tree_copy.traverse()])
>>> print(len(tree_nodes.intersection(tree_copy_nodes)))
0