Skip to main content
`Ctrl`+`K`

# skbio.tree.TreeNode.prune

TreeNode.prune(uncache=True)

  Collapse single-child nodes in the tree.

  Internal nodes with only one child will be removed, and direct connections will be made from the parent to the child. The branch length of the node will be added to the child. The name and properties of the child will override those of the parent following the operation.

  Parameters:
    uncache bool, optional

      Whether to clear caches of the tree if present (default: True). See `details`.

      Added in version 0.6.3.

  See also

  `shear`
  `pop`
  `remove`
  `remove_by_func`

  Notes

  This method is useful for cleaning up single-child nodes after some nodes were removed from a tree.

  If called from an internal node of the tree, only the clade below the node will be pruned.

  Examples

      >>> from skbio import TreeNode
      >>> tree = TreeNode.read(["(((a,b)c,(d)e)g,((h,i)j)k)root;"])
      >>> print(tree.ascii_art())
                                    /-a
                          /c-------|
                /g-------|          \-b
               |         |
      -root----|          \e------- /-d
               |
               |                    /-h
                \k------- /j-------|
                                    \-i

      >>> tree.prune()
      >>> print(tree.ascii_art())
                                    /-a
                          /c-------|
                /g-------|          \-b
               |         |
      -root----|          \-d
               |
               |          /-h
                \j-------|
                          \-i