collapse unsupported branches of trees into polytomy using ggtree

1,012 views
Skip to first unread message

mingl...@gmail.com

unread,
Sep 12, 2016, 4:05:25 AM9/12/16
to ggtree
Hi, guangchuang


Very powerful package.

Now I need to collapse some branches into polytomies, whose bootstrap value is lower than a threshold, such as 75.

After google search, I found the answer, which solve the question using ape package. Because of downstream annotation, I wonder to know how
to solve it using ggtree package.


Very appreciate for any help.

Yu, Guangchuang

unread,
Sep 12, 2016, 1:51:21 PM9/12/16
to mingl...@gmail.com, ggtree
Hi, I just write a function, as.polytomy to do this. Currently it only work with phylo object and will extend to support other tree object in future.

For example, if you have a newick tree that encode bootstrap in node.label, you can use:

as.polytomy(tree, feature='node.label', fun=function(x) as.numeric(x) < 70)





--
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+unsubscribe@googlegroups.com.
To post to this group, send email to bioc-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bioc-ggtree/472fd1b2-eede-4275-ab89-503678e3bcb1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
--~--~---------~--~----~------------~-------~--~----~
Guangchuang Yu, PhD Candidate
State Key Laboratory of Emerging Infectious Diseases
School of Public Health
The University of Hong Kong
Hong Kong SAR, China
-~----------~----~----~----~------~----~------~--~---
Message has been deleted
Message has been deleted

Yu, Guangchuang

unread,
Sep 12, 2016, 11:00:50 PM9/12/16
to 任明磊, ggtree
your post should be deleted by yourself. Maybe some keyboard setting that you didn't aware.

For your question, you can check:

> ape_tree2.re.poly$node.label
 [1] "41"  ""    "99"  "99"  "96"  "100" "98"  "93"  "100" "89"  "99"  "99"
[13] "100" "96"  "82"  "83"  "88"  "99"  "98"  "96"  "100" "97"  "91"  "85"
[25] "83"  "98"  "100" "100" "100" "99"  "100" "97"  "99"  "96"  "100" "100"
[37] "100" "96"

only the root node that is lower than the threshold since we can't collapse root node.

You input tree is indeed has bootstrap value lower than the threshold at the root node:

> ape_tree2.re$node.label
 [1] "41"  ""    "44"  "32"  "99"  "99"  "64"  "96"  "59"  "21"  "41"  "100"
[13] "23"  "67"  "98"  "93"  "64"  "100" "89"  "69"  "99"  "44"  "15"  "46"
[25] "66"  "99"  "43"  "19"  "30"  "100" "42"  "47"  "64"  "96"  "82"  "83"
[37] "88"  "48"  "51"  "70"  "64"  "32"  "35"  "99"  "98"  "96"  "100" "97"
[49] "91"  "85"  "50"  "83"  "98"  "100" "100" "33"  "30"  "100" "54"  "49"
[61] "99"  "100" "97"  "56"  "36"  "23"  "99"  "56"  "96"  "100" "29"  "74"
[73] "100" "47"  "100" "96"  "55"

We just can't collapse root node.



On Tue, Sep 13, 2016 at 10:46 AM, 任明磊 <mingl...@gmail.com> wrote:
Hi, Guangchuang


I posted my question and some answers on the google group of ggtree at 9:30 am. The two posts was deleted and I don't understand the reason. The code I send to you is about a little flaw in as.polytomy.

When finishing collapse, the bootstrap value at the basal of tree still keep there even if it is lower than some threshold (in my case, 75).



Best,
Minglei

2016-09-13 10:34 GMT+08:00 任明磊 <mingl...@gmail.com>:
Hi Guangchuang,


The attached file is one of the output from RAxML. After rooting the tree using ape package, I draw the tree using ggtree.





ape_tree2 <- read.tree("RAxML_bipartitions.HL13641")   # when reading this tree file using read.raxml, an error "object bootstrap" not found!
ape_tree2.re <- root(ape_tree2, "Escherichia_coli_str_K-12_substr_MG1655|b0003")

# use the function you provided
ape_tree2.re.poly <- as.polytomy(ape_tree2.re, "node.label", fun=function(x) as.numeric(x)<75)

tree.df <- fortify(ape_tree2.re.poly)
tree.df2 <- fortify(ape_tree2.re)

p1 <- ggtree(tree_df) + geom_text2(aes( label= label, subset= !isTip)) + geom_tiplab()
p2 <- ggtree(tree_df2) + geom_text2(aes( label= label, subset= !isTip)) + geom_tiplab()

multiplot(p1, p2, ncol= 2)


By the way, Could you know other root function in R, which support multiple outgroup that maybe not monophyletic?


Anyway, Thanks for your kind help.


Yu, Guangchuang

unread,
Sep 12, 2016, 11:16:01 PM9/12/16
to 任明磊, ggtree
root node should not have bootstrap value. you should remove it after re-root and then everything will just work as you expected.

as.polytomy will not remove any bootstrap value, since I designed the function to apply 'fun' to filter 'feature' (not necessarily bootstrap, and I have no idea of removing feature value and intend not to doing so).



On Tue, Sep 13, 2016 at 11:06 AM, 任明磊 <mingl...@gmail.com> wrote:
Thanks for your reply.

Sorry for the confusion. I know that we shouldn't collapse the root node. What i want to say that ggtree or as.polytomy function should suppress the occurrence of the lower bootstrap value (such as 41).


Best,
Minglei
Reply all
Reply to author
Forward
0 new messages