xavierdidelot / BactDating

Bayesian inference of ancestral dates on bacterial phylogenetic trees
https://xavierdidelot.github.io/BactDating
MIT License
81 stars 15 forks source link

export final tree with CI intervals #9

Closed fengyuchengdu closed 5 years ago

fengyuchengdu commented 5 years ago

Thanks for this great tool. I'm new to R and wondering if it allows to save the final tree with CI intervals, then I can, for example, drawing 95% CI bars in program like figtree or dragging it into itol, etc. So far I tried write.tree/nexus and it didn't incorperate CI values. Thanks.

xavierdidelot commented 5 years ago

Hi,

I think this should be possible if you use the recently added function as.treedata and then the function write.beast from the treeio package. You will need to have both packages ggtree and treeio installed, and the latest version of BactDating from github. Could you please give this a try and let me know if this works or not?

Best wishes, Xavier

fengyuchengdu commented 5 years ago

it worked. thanks

xavierdidelot commented 5 years ago

Great!

fengyuchengdu commented 4 years ago

Sorry to re-open this.

I followed the example "Application of BactDating on S. aureus ST239" and got the "res". Then I followed your suggestion as shown above (installed treeio and ggtree)

write.beast(as.treedata(res$tree)) however it didn't work as it did once before, instead it showed me the following (the last few lines) 51 51, 52 52, 53 53, 54 54, 55 55, 56 56, 57 57, 58 58 ; TREE * UNTITLED = [&R] Error in seq_len(nrow(yy)) : argument must be coercible to non-negative integer In addition: Warning messages: 1: Unknown or uninitialised column: 'node'. 2: In seq_len(nrow(yy)) : first element used of 'length.out' argument

treeio v1.11.2 ggtree v1.14.6

could you please help me fix this, many thanks.

xavierdidelot commented 4 years ago

Here's an example of how to use this functionality:

library(treedata)
library(ggtree)
res=bactdate(...)
l=as.treedata.resBactDating(res)
obj=methods::new('treedata',phylo=l[[1]],data=dplyr::tbl_df(as.data.frame(l[[2]])))
ggtree(obj) + geom_range(range='length_0.95_HPD', color='red', alpha=.6, size=2)
fengyuchengdu commented 4 years ago

Many thanks