Skip to content

Instantly share code, notes, and snippets.

@darmitage
Created April 24, 2012 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darmitage/2484454 to your computer and use it in GitHub Desktop.
Save darmitage/2484454 to your computer and use it in GitHub Desktop.
Collapse a phylogenetic clade by support values
#Code to collapse a phylogeny by a tree's support values, when nodes have support value names
#tree = phylogenetic tree, cutoff = support value cutoff (can be changed or made into a vector)
require(ape)
h <- which(tree$node.label < cutoff)
nodes <- matrix(h + Ntip(tree))
nodes <- nodes[-1]
k <- matrix(tree$edge[,2])
j <- matrix(nrow = length(i), ncol = 1)
for (i in 1:length(nodes)){
j[i] = which(k == nodes[i])
}
tree$edge.length[j] <- 0
newtree <- di2multi(tree)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment