tipDropper | R Documentation |
Given a phylogeny and a data frame of species and the taxonomic group to which they belong, will drop requested number of species, with some caveats.
tipDropper(tree, groupings, no.to.drop)
tree |
An ape-style phylogenetic tree |
groupings |
A data frame with two columns, "species" and "group". Missing species, to be added, are taken as those that do not match a value in the tip labels of tree. |
no.to.drop |
The number of tips to drop from the tree. |
This function drops tips from a phylogeny but ensures that no genera are entirely removed from the tree. No check is made to ensure that the number of tips to drop can be can be accomplished without dropping below the threshold of leaving one species per genus.
A pruned phylogeny.
#load an example tree up
data(chelonia)
tree <- chelonia$phy
#some species in this tree are identified to subspecies. drop those
temp <- lapply(strsplit(tree$tip.label, "_"), length)
names(temp) <- tree$tip.label
temp <- temp[temp==2]
tree <- drop.tip(tree, setdiff(tree$tip.label, names(temp)))
#create an example groupings data frame.
groupsDF <- data.frame(species=tree$tip.label)
groupsDF$group <- unlist(lapply(strsplit(tree$tip.label, "_"), "[", 1))
#use the function to drop 20 species
example <- tipDropper(tree, groupsDF, 20)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.