pruneTree {TreeSummarizedExperiment}R Documentation

remove branches of a phylo tree

Description

pruneTree is to remove branches that the specified leaves are in from a phylo tree

Usage

pruneTree(tree, rmLeaf, mergeSingle = TRUE)

Arguments

tree

A phylo object.

rmLeaf

A numeric or character vector. The labels or numbers of leaves to be removed.

mergeSingle

A logical value, TRUE or FALSE. If TRUE, the internal node that has only one child will be omitted. For example, a tree has structure as A-[B,C-D] (A has two children B, and C. C has a child D). If mergeSingle = TRUE, the node C is removed and D become the child of A. If mergeSingle = FALSE, the node C is kept. Another example: the tree has a structure as A-[B,C-[D,E]] (The root is A, and A has two children B, and C. C has two children D, and E.) If mergeSingle = TRUE, nothing changes because there is no internal node with only one child.

Value

A phylo object.

Examples

library(ggtree)
data(tinyTree)
ggtree(tinyTree, branch.length = "none") +
    geom_text2(aes(label = label), color = "darkorange",
           hjust = -0.1, vjust = -0.7) +
    geom_text2(aes(label = node), color = "darkblue",
               hjust = -0.5, vjust = 0.7) +
    geom_hilight(node = 18) +
    geom_point2()

# remove the blue branch
NT1 <- pruneTree(tree = tinyTree, rmLeaf = c(4, 5),
                mergeSingle = FALSE)

ggtree(NT1, branch.length = "none") +
    geom_text2(aes(label = label), color = "darkorange",
               hjust = -0.1, vjust = -0.7) +
    geom_point2()

# if mergeSingle = TRUE, the node (Node_17) is removed.
NT2 <- pruneTree(tree = tinyTree, rmLeaf = c(4, 5),
                mergeSingle = TRUE)
# or use the ape::drop.tip
# NT3 <-  ape::drop.tip(phy = tinyTree, tip = 4:5)
# all.equal(NT2, NT3)

ggtree(NT2, branch.length = "none") +
    geom_text2(aes(label = label), color = "darkorange",
               hjust = -0.1, vjust = -0.7) +
    geom_point2()

[Package TreeSummarizedExperiment version 1.0.3 Index]