Plot as Fan Tree?
Opened this issue · 2 comments
Dear Steven,
Thanks for an awesome piece of software. I am using MBASR on a routine basis and used it in this publication: https://onlinelibrary.wiley.com/doi/abs/10.1111/evo.14380
I am dealing with a phylogeny containing 300+ tips. I was wondering whether it is possible to have MBASR plot the tree as a "fan" type tree as can be done in phytools? I looked into the code, but could not find any obvious way of tweaking this.
Thanks for your time, and hope you can help
Take care,
Niklas
Hi Niklas,
I’m happy to hear that the software is useful to you. And thanks for the citation!
MBASR cannot automatically plot a tree in a fan, circle, swoop, or anything other than the default rectangle tree that you already know about. But, if you are willing to tinker with R a little bit, you could possibly do so… outside of the MBASR toolkit. The key to this is the ASR node probability table (“MrBayes.ASR.results.txt”) that is written to the results folder after you run an MBASR analysis. An alternate plot command from any R package could use this table to annotate nodes in your tree.
You mentioned phytools so I assume that you have some experience in R. That makes this explanation easier.
You’ll need the “MrBayes.ASR.results.txt” file and your original tree to do it. First, be certain to prep your tree in the same way that MBASR does so you get a perfect correspondence in tree node numbering. This code will do so:
target.folder="D:/Documents/Desktop/abcdefg" #change as needed
setwd(target.folder)
tree.file.name="tree.nwk" #change as needed
library(ape)
my.tree=read.tree(tree.file.name)
prepped.tree=multi2di(my.tree,random=FALSE)
prepped.tree=collapse.singles(prepped.tree)
prepped.tree.file.name=paste("prepped.",tree.file.name,sep="")
write.tree(prepped.tree,prepped.tree.file.name)
#and to load/prepare the asr node probability table
table.file.name="MrBayes.ASR.results.txt"
my.table=read.table(table.file.name)
rownames(my.table)=my.table[,1]
my.table=my.table[,-1]
my.table=as.matrix(my.table)
colnames(my.table)=NULL
prepped.table=my.table
mode(prepped.table)="numeric"
#to show your prepped table
print(prepped.table)
Now you have two R objects: prepped.tree & prepped.table
Then you can use whatever tree plotting tools/packages that you like to annotate the table onto the tree. Phytools is an option… I think ggplot(2) has some phylogenetic tree plotting commands now too.
The only caveat to this approach, is that if you also want pie charts at your tree tips that indicate the input trait states for the MBASR analysis, you’ll need to also convert your input data to an additional (separate) probability table. In other words, for a 3-state trait where a single taxon was coded as “0”, you’ll need a table where the row for the corresponding tip number is coded as ”100 0 0”, indicating a pie chart that is 100% zero, 0% one, and 0% two. I hope this makes sense.
If you figure out a cool plotting solution for a tree with 300+ tips, I’d love to see it. If you are willing to share it, please send it privately to my email address in the MBASR manuscript.
Feel free to keep the questions/feedback coming. Good luck!
Steven
Dear Steven,
Thanks a lot for this brilliant guide. I am getting some errors at the rownames(mytable) step but I think this is an issue with my R version. I will get back to you when it works!
Take care