I wish my trees were always strictly bifurcating! But sometimes that's just not the case.
Here's a simple workaround in R using the package APE. The crucial command is multi2di, which transforms all polytomies into a series of dichotomies with one or more branches of length zero. Here's my R code:
###Code for a Phylo Object###
library(ape)
myTree<-read.tree("myTree.tre")
is.binary.tree(myTree)
[1] FALSE
myTree.bifurcating<-multi2di(myTree)
is.binary.tree(myTree.bifurcating)
[1] TRUE
write.tree(myTree.bifurcating, file="myTree.bifurcating.tre")
###Code for a Multiphylo Object###
library(ape)
myTrees<-read.tree("myTrees.tre")
is.binary.tree(myTrees[[1]])
[1] FALSE
make.bifurcating<-function(phy){
for(i in 1:length(phy)){
phy[[i]]<-multi2di(phy[[i]])
}
return(phy)
}
myTrees.bifurcating<-make.bifurcating(myTrees)
is.binary.tree(myTrees.bifurcating[[1]])
[1] TRUE
write.tree(myTree.bifurcating, file="myTrees.bifurcating.trees")
NOTE: I would NOT recommend using poorly resolved trees with multiple polytomies as an input into any program that assumes or depends on the accuracy of gene trees. That said, if you have lots of gene trees with just one or two small polytomies, this method works pretty well.