Annotating nodes wit bootstrap cutoff

952 views
Skip to first unread message

oyenira...@gmail.com

unread,
Oct 8, 2020, 5:16:46 PM10/8/20
to ggtree

Dear Members,

I am making a rooted Iqtree with specified outgroup and I intend to annotate the branch with nodes representing bootstrap cut offs  eg from  >70 upwards. I could not find a specific tutorial pointing at this. I shall be grateful if someone can point me to a tutorial. I intend to achieve something like this: 

Many thanks!

Kehinde Oyeniran

unread,
Oct 8, 2020, 5:20:19 PM10/8/20
to ggtree
Kindly see what I intend to achieve.

--
1. G Yu*. Using ggtree to visualize data on tree-like structures. Current Protocols in Bioinformatics. 2020, 69:e96. https://doi.org/10.1002/cpbi.96
2. LG Wang, TTY Lam, S Xu, Z Dai, L Zhou, T Feng, P Guo, CW Dunn, BR Jones, T Bradley, H Zhu, Y Guan, Y Jiang, G Yu*. treeio: an R package for phylogenetic tree input and output with richly annotated and associated data. Molecular Biology and Evolution. 2020, 37(2):599-603. http://dx.doi.org/10.1093/molbev/msz240
3. G Yu*, TTY Lam, H Zhu, Y Guan*. Two methods for mapping and visualizing associated data on phylogeny using ggtree. Molecular Biology and Evolution, 2018, 35(2):3041-3043. https://doi.org/10.1093/molbev/msy194
4. G Yu, DK Smith, H Zhu, Y Guan, TTY Lam*. ggtree: an R package for visualization and annotation of phylogenetic trees with their covariates and other associated data, Methods in Ecology and Evolution, 2017, 8(1):28-36. https://doi.org/10.1111/2041-210X.12628
5. Book: https://yulab-smu.top/treedata-book/
---
You received this message because you are subscribed to the Google Groups "ggtree" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bioc-ggtree...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bioc-ggtree/9c3bb320-5c3e-4942-aaac-04ce217c42bcn%40googlegroups.com.


--
Kehinde Adewole Oyeniran

PhD Scholar | Computational Biology | Institute of Infectious Diseases and
Molecular Medicine (IDM) | Faculty of Health Sciences | University of Cape
Town | Health Sciences Campus, Anzio Road, Observatory, 7925 | Blog:
www.electoralreform-ng.blogspot.com | UCT email: OYNK...@myuct.ac.za |
+27(0)619507372 | +27(0)736207568 |+234(0)8038294995|
“As you rise you must lift the others up” -- Justice Skweyiya (RIP)





















Bootstrap.jpg

Yonghe Xia

unread,
Oct 9, 2020, 4:47:08 AM10/9/20
to Kehinde Oyeniran, ggtree
library("ggplot2")
library("ggtree")
library("treeio")
library("tidytree")
#tree
nwk <- "example.phy.treefile"
tree <- read.tree(nwk)
#Extract node label
bootsv <-data.frame(tree[["node.label"]])
ntip <- length(tree[["tip.label"]])
nnode <- tree[["Nnode"]]
SHaLRT <- data.frame(lapply(bootsv, function(x) as.numeric(sub("/.*", "",x))))
SHaLRT$node <- c((ntip + 1) : (ntip + nnode))
colnames(SHaLRT) <- c("label","node")

# cut data
SHaLRT$label <- cut(as.numeric(SHaLRT$label), breaks = c(0,80,85,90,95,100),right = F,include.lowest = TRUE)

# rename levels
levels(SHaLRT$label) <- c("0<=SHaLRT<80","80<=SHaLRT<85", "85<=SHaLRT<90",  "90<=SHaLRT<95", "95<=SHaLRT<=100")

# remove null levels
SHaLRT$label <- SHaLRT$label[, drop=T]

#Put the results back into the tree.
tree[["node.label"]] <- SHaLRT$label

#make a color list according to levels
fun_color_range <- colorRampPalette(c("#f7f7f7", "#252525")) # set color range
my_colors <- fun_color_range(nlevels(SHaLRT$label))

#plot
treeplot <- ggtree(tree) +
  xlim(0,1)+ # adjust width of tree
  geom_point2(aes(subset = !isTip,color  = label), size=3,shape=19)+
  geom_tiplab(align=TRUE, linesize=0.25)+
  scale_color_manual("SHaLRT branch support", #legend name
                      values = my_colors, #legend color
                      na.translate = F,#remove na
                      labels = levels(SHaLRT$label))  #rename key label of legend with levels
Rplot04.png

Kehinde Oyeniran <oyenira...@gmail.com> 于2020年10月9日周五 上午5:20写道:

Kehinde Oyeniran

unread,
Oct 9, 2020, 9:12:25 AM10/9/20
to Yonghe Xia, ggtree
Dear Yonghe,
I tried my data with this code but it returned several warnings and removed about 80% from the tree data. Please what do you think is wrong? Meanwhile I found a tutorial  (13.2 Displaying different symbolic points for bootstrap values.) at https://yulab-smu.top/treedata-book/chapter13.html  and I tried with my data please see my codes:

library(treeio)
library(ggplot2)
library(ggtree)
df4 = read.newick('/Users/ciznetwork/Downloads/MLtree_fixedmsa_nostarttree_rooted.tree', node.label = 'support')
Warning message:
In eval_tidy(xs[[j]], mask) : NAs introduced by coercion.    # This warning is weird to me 
root = rootnode(tree)
nodes = ggtree(df4, color="black", size=0.5, linetype=1,  right=TRUE) + 
  geom_point2(aes(subset=!isTip & node != root, 
                  fill=cut(support, c(0,800,900,1000))), 
              shape=21, size=1.5) + 
  theme_tree(legend.position=c(0.2, 0.2)) + 
  scale_fill_manual(values=c("white", "grey", "black"), guide='legend', 
                    name='Bootstrap_support (%)', 
                    breaks=c('(900,1e+03]', '(800,900]', '(0,800]'), 
                    labels=expression(BP>=90,80 <= BP * " < 90", BP < 80))

I have attached what I got from these codes. The codes do not seem to be doing what I want it to do, I did not get any legend also. I am keen on making these two methods work out especially the latter, kindly advise.

Many thanks
Screenshot 2020-10-09 at 15.00.52.png

xiayh17

unread,
Oct 9, 2020, 10:06:33 AM10/9/20
to oyenira...@gmail.com, bioc-...@googlegroups.com
A tree file in format of IQtree is used in my code.
Your tree file seems not produced by IQtree, can you send me a copy of yours.

example.phy.treefile

Kehinde Oyeniran

unread,
Oct 9, 2020, 12:16:27 PM10/9/20
to xiayh17, bioc-...@googlegroups.com
Dear Yonghe,
Many thanks for your response, I will send you my tree when I have made it properly. Meanwhile, I could reproduce the visualization in the sample code with the tree you sent. But I am still puzzled that I can't still do that with the (13.2 Displaying different symbolic points for bootstrap values.) at https://yulab-smu.top/treedata-book/chapter13.html . My question is does the latter require specific tree like those produced from phymL only as used in the tutorial? I really need to reproduce that tutorial. 

Thanks!

Yonghe Xia

unread,
Oct 9, 2020, 12:43:50 PM10/9/20
to ggtree
There are some  differences of a tree file  format produced by different software.
The code has to be tweaked for these differences.
Attached is the tree file in the tutorial
RMI.phy_phyml_tree_rooted_labeled.txt

Kehinde Oyeniran

unread,
Oct 9, 2020, 2:49:57 PM10/9/20
to Yonghe Xia, ggtree
Dear Yonghe,

I could reproduce that with the tree you sent. I made a little progress with a sample Iqtree tree data but I noticed it is still not doing what I want as it's annotating every node. I am suspecting an issue with processing the bootstrap support further somehow. here are my codes:


df6 = read.iqtree('/Users/ciznetwork/Downloads/MLtree_fixedmsa_nostarttree_rooted.tree')
root = rootnode(df6)
nodes = ggtree(df6, color="black", size=0.5, linetype=1,  right=TRUE) + 
  geom_point2(aes(subset=!isTip & node != root, 
                  fill=cut(SH_aLRT, c(0, 800, 900, 1000))), 
              shape=21, size=1.5) + 
  theme_tree(legend.position=c(0.2, 0.2)) + 
  scale_fill_manual(values=c("white", "grey", "black"), guide='legend', 
                    name='Bootstrap Percentage(BP)', 
                    breaks=c('(900,1e+03]', '(800,900]', '(0,800]'), 
                    labels=expression(BP>=90,80 <= BP * " < 90", BP < 80))

Many thanks!

Screenshot 2020-10-09 at 20.40.02.png
Reply all
Reply to author
Forward
0 new messages