How to convert posterior distribution of trees into newick format

1,002 views
Skip to first unread message

Josh Williams

unread,
Jun 23, 2011, 2:01:04 PM6/23/11
to beast-users
Hello,

I was wondering if there was a way to convert the trees in the
posterior distribution output from *BEAST into a normal newick
format. Because the *BEAST trees have extra formatting, like below
(one of my trees from a posterior distribution):


(((10[&dmt=0.02206435630732423,dmv={0.0015318154101832844,0.0012792327564427849}]:
0.02206435630732423,19[&dmt=0.02206435630732423,dmv={0.0012575360937068123,4.3506438909926565E-4}]:
0.02206435630732423)
[&dmt=0.0010174828192912808,dmv={0.0017142971455420505,6.354980232855838E-4}]:
0.0010174828192912808,
(((14[&dmt=0.013097384448157386,dmv={0.003334053503411882,7.110718550766282E-4}]:
0.013097384448157386,
(((5[&dmt=0.008185322363632397,dmv={0.0012159849793191714,0.002530337747765068}]:
0.008185322363632397,
(9[&dmt=6.658051678474632E-4,dmv={0.0014839010986993648,2.989576703566814E-4}]:
6.658051678474632E-4,7[&dmt=6.658051678474632E-4,dmv={2.0339680458229969E-4,5.235734025067074E-4}]:
6.658051678474632E-4)
[&dmt=0.007519517195784933,dmv={8.225310728633888E-4,0.0012876450265545993}]:
0.007519517195784933)
[&dmt=0.0033552069921444824,dmv={0.003817982774319667,0.0018426717952679398}]:
0.0033552069921444824,
(8[&dmt=0.005948936924932965,dmv={0.0011248216819087825,2.923628075709584E-4}]:
0.005948936924932965,
((16[&dmt=6.516800881489398E-4,dmv={4.953744723140805E-4,5.26813642106332E-4}]:
6.516800881489398E-4,18[&dmt=6.516800881489398E-4,dmv={6.203159804153562E-4,6.891815689353816E-4}]:
6.516800881489398E-4)
[&dmt=0.0011330263592933725,dmv={0.0012159952110417137,4.986714733565607E-4}]:
0.0011330263592933725,21[&dmt=0.0017847064474423124,dmv={0.0014498795409704,0.0037975062728661645}]:
0.0017847064474423124)
[&dmt=0.004164230477490653,dmv={0.004296177746222725,1.4106767709719863E-4}]:
0.004164230477490653)
[&dmt=0.005591592430843915,dmv={4.33430484668157E-4,7.524091177704563E-4}]:
0.005591592430843915)
[&dmt=5.331322059317269E-4,dmv={0.0025950809130383962,0.0025264007095689715}]:
5.331322059317269E-4,
((13[&dmt=0.008083387312868662,dmv={5.18202045617277E-4,0.0011255950549218519}]:
0.008083387312868662,
(20[&dmt=0.004419835892021963,dmv={0.0025901456499011926,7.911903112748847E-4}]:
0.004419835892021963,6[&dmt=0.004419835892021963,dmv={0.001471465825289436,3.805137519079202E-4}]:
0.004419835892021963)
[&dmt=0.0036635514208466996,dmv={0.0011717040631828049,0.0019504326318614006}]:
0.0036635514208466996)
[&dmt=0.0034501784182041917,dmv={0.0030760276867832525,6.646381135664681E-4}]:
0.0034501784182041917,
(12[&dmt=0.009906860743158523,dmv={2.727864491549159E-4,8.045377183801342E-4}]:
0.009906860743158523,11[&dmt=0.009906860743158523,dmv={6.908308540726824E-4,7.32503286239051E-4}]:
0.009906860743158523)
[&dmt=0.0016267049879143316,dmv={0.001537041004619185,0.0012370997952368809}]:
0.0016267049879143316)
[&dmt=5.40095830635752E-4,dmv={0.0019017379088033491,0.002279832839496191}]:
5.40095830635752E-4)
[&dmt=0.0010237228864487802,dmv={0.004806233549065163,0.0029234790073215076}]:
0.0010237228864487802)
[&dmt=0.001034439907625898,dmv={0.003634550862398136,0.0015069447696934796}]:
0.001034439907625898,17[&dmt=0.014131824355783284,dmv={0.0014846279604340989,8.588158929678985E-4}]:
0.014131824355783284)
[&dmt=0.0032559943958138503,dmv={0.002365760662661378,0.0012600843207181702}]:
0.0032559943958138503,15[&dmt=0.017387818751597135,dmv={0.0026049634239448073,1.888942048156249E-4}]:
0.017387818751597135)
[&dmt=0.005694020375018375,dmv={0.0014489785255337952,0.0011792952650256775}]:
0.005694020375018375)
[&dmt=0.05284077442184044,dmv={0.0018147932883112615,0.0013386020322460569}]:
0.05284077442184044,
(((1[&dmt=0.0016638785071647782,dmv={0.0010884276025815403,4.3677989727334063E-4}]:
0.0016638785071647782,3[&dmt=0.0016638785071647782,dmv={0.001674856423797966,0.0014774390178660464}]:
0.0016638785071647782)
[&dmt=9.14672243732859E-4,dmv={0.001914218915139387,0.0015284835020664535}]:
9.14672243732859E-4,2[&dmt=0.0025785507508976372,dmv={0.002665710191919657,3.181964841681323E-4}]:
0.0025785507508976372)
[&dmt=4.225355683184096E-5,dmv={0.0018466799862345857,4.461767149357939E-4}]:
4.225355683184096E-5,4[&dmt=0.002620804307729478,dmv={0.0012685836654021444,0.0025596560291543118}]:
0.002620804307729478)
[&dmt=0.07330180924072646,dmv={0.0030058327440901055,0.003816407000449406}]:
0.07330180924072646)
[&dmt=0.024966425112478957,dmv={0.005155009032695463,0.005155009032695463}];


But I would like to get all my trees into a standard newick format,
like so:

((D_tenebrosus:0.002620804307729478,(D_copei:0.0025785507508976372,
(D_aterrimus:0.0016638785071647782,D_ensatus:0.0016638785071647782):
9.14672243732859E-4):4.225355683184096E-5):0.07330180924072646,
((gracile:0.02206435630732423,talpoideum:0.02206435630732423):
0.0010174828192912808,(maculatum:0.017387818751597135,(opacum:
0.014131824355783284,(macrodactylum:0.013097384448157386,(((laterale:
0.009906860743158523,jeffersonianum:0.009906860743158523):
0.0016267049879143316,(mabeei:0.008083387312868662,(texanum:
0.004419835892021963,barbouri:0.004419835892021963):
0.0036635514208466996):0.0034501784182041917):5.40095830635752E-4,
((annulatum:0.008185322363632397,(cingulatum:
6.658051678474632E-4,bishopi:6.658051678474632E-4):
0.007519517195784933):0.0033552069921444824,(californiense:
0.005948936924932965,(tigrinum:0.0017847064474423124,(mexicanum:
6.516800881489398E-4,ordinarium:6.516800881489398E-4):
0.0011330263592933725):0.004164230477490653):0.005591592430843915):
5.331322059317269E-4):0.0010237228864487802):0.001034439907625898):
0.0032559943958138503):0.005694020375018375):0.05284077442184044);



I'm aware that FigTree can export BEAST trees in nexus or newick
format, but the problem is that, when I try to open one of my
posterior distributions in FigTree (my file has several thousand
trees), the program crashes, so I'm not able to export it in newick
format. I was wondering if there was some other way to overcome this,
or if maybe another program would be able to do such a thing? I tried
uploading my files into TreeEdit, but it wouldn't read it.

Thanks,
Josh

Joseph W. Brown

unread,
Jun 23, 2011, 3:00:55 PM6/23/11
to beast...@googlegroups.com, Josh Williams
If you use search-and-replace with grep you can remove all of the extra information by searching for the regular expression:

\[.+?\]

This will give you a standard Nexus tree file; any tree viewing program should enable you to export as newick. Alternatively, you can use Phyutility or Mesquite.

HTH.
Joseph.

--
You received this message because you are subscribed to the Google Groups "beast-users" group.
To post to this group, send email to beast...@googlegroups.com.
To unsubscribe from this group, send email to beast-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/beast-users?hl=en.




_____________________________________________________
Joseph W. Brown
Post-doctoral Researcher, Harmon Laboratory
University of Idaho, Department of Biological Sciences
Box 443051
Moscow, Idaho 83844

Hassan Ebrahimi

unread,
Jun 23, 2011, 10:39:44 PM6/23/11
to beast...@googlegroups.com
Regarding the crash of Figtree, you need to first use TreeAnnotator to find the consensus tree(s) among the thousands. The result would be one of a few trees. You can open them with Figtree then.

Regards,

Hassan


From: Josh Williams <jshwil...@gmail.com>
To: beast-users <beast...@googlegroups.com>
Sent: Friday, June 24, 2011 3:01 AM
Subject: How to convert posterior distribution of trees into newick format
((13[&dmt=0.008083387 312868662,dmv={5.18202045617277E-4,0.0011255950549218519}]:

0.008083387312868662,
(20[&dmt=0.004419835892021963,dmv={0.0025901456499011926,7.911903112748847E-4}]:
0.004419835892021963,6[&dmt=0.004419835892021963,dmv={0.001471465825289436,3.805137519079202E-4}]:
0.004419835892021963)
[&dmt=0.0036635514208466996,dmv={0.0011717040631828049,0.0019504326318614006}]:
0.0036635514208466996)
[&dmt=0.0034501784182041917,dmv={0.0030760276867832525,6.646381135664681E-4}]:
0.0034501784182041917,
(12[&dmt=0.009906860743158523,dmv={2.727864491549159E-4,8.045377183801342E-4}]:
0.009906860743158523,11[&dmt=0.009906860743158523,dmv={6.908308540726824E-4,7.32503286239051E-4}]:
0.009906860743158523)
[&dmt=0.0016267049879143316,dmv={0.001537041004619185,0.0012370997952368809}]:
0.0016267049879143316)
[&dmt=5.40095830635752E-4,dmv={0.0019017379088033491,0.002279832839496191}]:
5.40095830635752E-4)< br>[&dmt=0.0010237228864487802,dmv={0.004806233549065163,0.0029234790073215076}]:
--
You received this message because you are subscribed to the Google Groups "beast-users" group.
To post to this group, send email to beast...@googlegroups.com.
To unsubscribe from this group, send email to beast-users+unsub...@googlegroups.com.

Josh Williams

unread,
Jun 24, 2011, 11:24:32 PM6/24/11
to Joseph W. Brown, beast...@googlegroups.com
Ok, so I tried doing that, and it ended up deleting the lines with trees altogether.  This is how I set up the command:

grep -Ev "\[.+?\]" <input >output

I'm not too dexterous with the grep command, so maybe there's a way to do it that works better than what I tried.

Josh

dbto...@gmail.com

unread,
Jan 24, 2016, 10:16:41 PM1/24/16
to beast-users
Based on the dates, I'm sure this has been resolved, but for anyone else out there, run your ".tree" file through LogCombiner where you remove burnin and sample at a lower frequency (to get few enough trees for TreeAnnotator to use it), then run that output file through TreeAnnotator, which will give you the summary tree you want. After that, you can export it from FigTree as a newick file.
Reply all
Reply to author
Forward
0 new messages