tipDropper: Randomly drop tips from a phylogeny

View source: R/tipDropper.R

tipDropperR Documentation

Randomly drop tips from a phylogeny

Description

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.

Usage

tipDropper(tree, groupings, no.to.drop)

Arguments

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.

Details

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.

Value

A pruned phylogeny.

Examples

#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)

eliotmiller/addTaxa documentation built on Feb. 3, 2024, 12:19 a.m.