Anaphory
Anaphory

Reputation: 6400

Using ape to display BEAST ancestral state reconstructions

I have run ancestral state reconstructions using BEAST, which gives me a Nexus file like this

#NEXUS

Begin taxa;
    Dimensions ntax=93;
        Taxlabels
            adan1251 
            blag1240-nule 
            wers1238-marit
            ;
End;
Begin trees;
    Translate
           1 adan1251,
           2 blag1240-nule,
           3 wers1238-marit
;
tree STATE_0 = ((1[&recon_lexicon:cooked rice="00000000000001",recon_lexicon:mountain="000000000001",recon_lexicon:to die="00001",recon_lexicon:wall="00000001"]:0.02243609504948792,2[&recon_lexicon:cooked rice="00000000000001",recon_lexicon:mountain="000000000001",recon_lexicon:to die="00001",recon_lexicon:wall="00000001"]:0.02243609504948792)[&recon_lexicon:cooked rice="00000000000001",recon_lexicon:mountain="000000000001",recon_lexicon:to die="00001",recon_lexicon:wall="00000001"]:0.01067010801410265,3[&recon_lexicon:cooked rice="00000000000001",recon_lexicon:mountain="000000000001",recon_lexicon:to die="00001",recon_lexicon:wall="00000001"]:0.03310620306359057)[&recon_lexicon:cooked rice="00000000000001",recon_lexicon:mountain="000000000001",recon_lexicon:to die="00001",recon_lexicon:wall="00000001"]:0.022661511629175332;
tree STATE_1 = ((1[&recon_lexicon:cooked rice="00000000000001",recon_lexicon:mountain="000000000001",recon_lexicon:to die="00001",recon_lexicon:wall="00000001"]:1.02243609504948792,2[&recon_lexicon:cooked rice="00000000000001",recon_lexicon:mountain="000000000001",recon_lexicon:to die="00001",recon_lexicon:wall="00000001"]:0.02243609504948792)[&recon_lexicon:cooked rice="00000000000001",recon_lexicon:mountain="000000000001",recon_lexicon:to die="00001",recon_lexicon:wall="00000001"]:0.01067010801410265,3[&recon_lexicon:cooked rice="00000000000001",recon_lexicon:mountain="000000000001",recon_lexicon:to die="00001",recon_lexicon:wall="00000001"]:0.03310620306359057)[&recon_lexicon:cooked rice="00000000000001",recon_lexicon:mountain="000000000001",recon_lexicon:to die="00001",recon_lexicon:wall="00000001"]:0.022661511629175332;
tree STATE_2 = ((1[&recon_lexicon:cooked rice="00000000000001",recon_lexicon:mountain="000000000001",recon_lexicon:to die="00001",recon_lexicon:wall="00000001"]:2.02243609504948792,2[&recon_lexicon:cooked rice="00000000000001",recon_lexicon:mountain="000000000001",recon_lexicon:to die="00001",recon_lexicon:wall="00000001"]:0.02243609504948792)[&recon_lexicon:cooked rice="00000000000001",recon_lexicon:mountain="000000000001",recon_lexicon:to die="00001",recon_lexicon:wall="00000001"]:0.01067010801410265,3[&recon_lexicon:cooked rice="00000000000001",recon_lexicon:mountain="000000000001",recon_lexicon:to die="00001",recon_lexicon:wall="00000001"]:0.03310620306359057)[&recon_lexicon:cooked rice="00000000000001",recon_lexicon:mountain="000000000001",recon_lexicon:to die="00001",recon_lexicon:wall="00000001"]:0.022661511629175332;
tree STATE_3 = ((1[&recon_lexicon:cooked rice="00000000000001",recon_lexicon:mountain="000000000001",recon_lexicon:to die="00001",recon_lexicon:wall="00000001"]:3.02243609504948792,2[&recon_lexicon:cooked rice="00000000000001",recon_lexicon:mountain="000000000001",recon_lexicon:to die="00001",recon_lexicon:wall="00000001"]:0.02243609504948792)[&recon_lexicon:cooked rice="00000000000001",recon_lexicon:mountain="000000000001",recon_lexicon:to die="00001",recon_lexicon:wall="00000001"]:0.01067010801410265,3[&recon_lexicon:cooked rice="00000000000001",recon_lexicon:mountain="000000000001",recon_lexicon:to die="00001",recon_lexicon:wall="00000001"]:0.03310620306359057)[&recon_lexicon:cooked rice="00000000000001",recon_lexicon:mountain="000000000001",recon_lexicon:to die="00001",recon_lexicon:wall="00000001"]:0.022661511629175332;
tree STATE_4 = ((1[&recon_lexicon:cooked rice="00000000000001",recon_lexicon:mountain="000000000001",recon_lexicon:to die="00001",recon_lexicon:wall="00000001"]:4.02243609504948792,2[&recon_lexicon:cooked rice="00000000000001",recon_lexicon:mountain="000000000001",recon_lexicon:to die="00001",recon_lexicon:wall="00000001"]:0.02243609504948792)[&recon_lexicon:cooked rice="00000000000001",recon_lexicon:mountain="000000000001",recon_lexicon:to die="00001",recon_lexicon:wall="00000001"]:0.01067010801410265,3[&recon_lexicon:cooked rice="00000000000001",recon_lexicon:mountain="000000000001",recon_lexicon:to die="00001",recon_lexicon:wall="00000001"]:0.03310620306359057)[&recon_lexicon:cooked rice="00000000000001",recon_lexicon:mountain="000000000001",recon_lexicon:to die="00001",recon_lexicon:wall="00000001"]:0.022661511629175332;
End;

(except with 20 times as many taxa, 2000 times as many trees and trees actually differing.)

I would like to visualize the reconstructions for the lexical items in the intenal and tip nodes, and it seems that ape may be a good tool to do it, because it can be scripted, it can read the Nexus file (I tried using read.nexus("filename.nex"), and it seems the str is reasonable) and judging from http://ape-package.ird.fr/ape_screenshots.html it can display the reconstructions in a nice format:

ape tree with reconstructions in ancestral nodes

How do I get ape to construct something like this thermo tree from data given in the comments ([&...]) of 10000 different Newick trees, after constructing some kind of consensus tree from the raw data?

Upvotes: 1

Views: 54

Answers (1)

Greg Nelson
Greg Nelson

Reputation: 33

After looking at some of the documentation for the ape package, if looks like you would be interested in the nodelabels() function.

After you have plotted your tree, you simply need to pass a vector with length equal to the number of taxa you have with each values representing the probability of occupying one of the character states. Then, simply plot the probabilities on the nodes with the thermo option on.

From the help files:

data(bird.orders)
plot(bird.orders, "c", use.edge.length = FALSE, font = 1) 
nodelabels(thermo = runif(22), cex = .8)

If you have more than two states, you must create a matrix with the number of columns equal to the number of you states and rows equal to the number of taxa. For each row, include the relative probability of that state for each taxa. Each row should add up to 1.

Extended example with 3 states:

thermo <- matrix(c(.6,.3,.1), nrow=22, ncol=3)
plot(bird.orders, "c", use.edge.length = FALSE, font = 1)
nodelabels(thermo = thermo, cex = .8)

Upvotes: 1

Related Questions