1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
\name{drop.tip}
\alias{drop.tip}
\alias{drop.tip.phylo}
\alias{drop.tip.multiPhylo}
\alias{keep.tip}
\alias{keep.tip.phylo}
\alias{keep.tip.multiPhylo}
\alias{extract.clade}
\title{Remove Tips in a Phylogenetic Tree}
\description{
\code{drop.tip} removes the terminal branches of a phylogenetic tree,
possibly removing the corresponding internal branches. \code{keep.tip}
does the opposite operation (i.e., returns the induced tree).
\code{extract.clade} does the inverse operation: it keeps all the tips
from a given node, and deletes all the other tips.
}
\usage{
drop.tip(phy, tip, \dots)
\method{drop.tip}{phylo}(phy, tip, trim.internal = TRUE, subtree = FALSE,
root.edge = 0, rooted = is.rooted(phy), collapse.singles = TRUE,
interactive = FALSE, \dots)
\method{drop.tip}{multiPhylo}(phy, tip, \dots)
keep.tip(phy, tip)
\method{keep.tip}{phylo}(phy, tip)
\method{keep.tip}{multiPhylo}(phy, tip)
extract.clade(phy, node, root.edge = 0, collapse.singles = TRUE,
interactive = FALSE)
}
\arguments{
\item{phy}{an object of class \code{"phylo"}.}
\item{tip}{a vector of mode numeric or character specifying the tips
to delete.}
\item{trim.internal}{a logical specifying whether to delete the
corresponding internal branches.}
\item{subtree}{a logical specifying whether to output in the tree how
many tips have been deleted and where.}
\item{root.edge}{an integer giving the number of internal branches to
be used to build the new root edge. This has no effect if
\code{trim.internal = FALSE}.}
\item{rooted}{a logical indicating whether the tree must be treated as
rooted or not. This allows to force the tree to be considered as
unrooted (see examples). See details about a possible root.edge
element in the tree.}
\item{collapse.singles}{a logical specifying whether to delete the
internal nodes of degree 2.}
\item{node}{a node number or label.}
\item{interactive}{if \code{TRUE} the user is asked to select the tips
or the node by clicking on the tree which must be plotted.}
\item{\dots}{arguments passed from and to methods.}
}
\details{
The argument \code{tip} can be either character or numeric. In the
first case, it gives the labels of the tips to be deleted; in the
second case the numbers of these labels in the vector
\code{phy$tip.label} are given.
This also applies to \code{node}, but if this argument is character
and the tree has no node label, this results in an error. If more than
one value is given with \code{node} (i.e., a vector of length two or
more), only the first one is used with a warning.
If \code{trim.internal = FALSE}, the new tips are given \code{"NA"} as
labels, unless there are node labels in the tree in which case they
are used.
If \code{subtree = TRUE}, the returned tree has one or several
terminal branches indicating how many tips have been removed (with a
label \code{"[x_tips]"}). This is done for as many monophyletic groups
that have been deleted.
Note that \code{subtree = TRUE} implies \code{trim.internal = TRUE}.
To undestand how the option \code{root.edge} works, see the examples
below. If \code{rooted = FALSE} and the tree has a root edge, the
latter is removed in the output.
}
\value{an object of class \code{"phylo"}.}
\author{Emmanuel Paradis, Klaus Schliep, Joseph Brown}
\seealso{\code{\link{bind.tree}}, \code{\link{root}}}
\examples{
data(bird.families)
tip <- c(
"Eopsaltriidae", "Acanthisittidae", "Pittidae", "Eurylaimidae",
"Philepittidae", "Tyrannidae", "Thamnophilidae", "Furnariidae",
"Formicariidae", "Conopophagidae", "Rhinocryptidae", "Climacteridae",
"Menuridae", "Ptilonorhynchidae", "Maluridae", "Meliphagidae",
"Pardalotidae", "Petroicidae", "Irenidae", "Orthonychidae",
"Pomatostomidae", "Laniidae", "Vireonidae", "Corvidae",
"Callaeatidae", "Picathartidae", "Bombycillidae", "Cinclidae",
"Muscicapidae", "Sturnidae", "Sittidae", "Certhiidae",
"Paridae", "Aegithalidae", "Hirundinidae", "Regulidae",
"Pycnonotidae", "Hypocoliidae", "Cisticolidae", "Zosteropidae",
"Sylviidae", "Alaudidae", "Nectariniidae", "Melanocharitidae",
"Paramythiidae","Passeridae", "Fringillidae")
plot(drop.tip(bird.families, tip))
plot(drop.tip(bird.families, tip, trim.internal = FALSE))
data(bird.orders)
plot(drop.tip(bird.orders, 6:23, subtree = TRUE))
plot(drop.tip(bird.orders, c(1:5, 20:23), subtree = TRUE))
plot(drop.tip(bird.orders, c(1:20, 23), subtree = TRUE))
plot(drop.tip(bird.orders, c(1:20, 23), subtree = TRUE, rooted = FALSE))
### Examples of the use of `root.edge'
tr <- read.tree(text = "(A:1,(B:1,(C:1,(D:1,E:1):1):1):1):1;")
drop.tip(tr, c("A", "B"), root.edge = 0) # = (C:1,(D:1,E:1):1);
drop.tip(tr, c("A", "B"), root.edge = 1) # = (C:1,(D:1,E:1):1):1;
drop.tip(tr, c("A", "B"), root.edge = 2) # = (C:1,(D:1,E:1):1):2;
drop.tip(tr, c("A", "B"), root.edge = 3) # = (C:1,(D:1,E:1):1):3;
}
\keyword{manip}
|