Reconstructing ancestral states

This app takes a model_result and returns a tabular_result consisting of the posterior probabilities of ancestral states for each node of a tree. These probabilities are computed using the marginal reconstruction algorithm.

We first fit a model to the sample data.

[1]:
from cogent3.app import io, evo

reader = io.load_aligned(format="fasta")
aln = reader("../data/primate_brca1.fasta")
gn = evo.model("GN", tree="../data/primate_brca1.tree")
result = gn(aln)

Define the ancestral_states app

[2]:
reconstuctor = evo.ancestral_states()
states_result = reconstuctor(result)
states_result
[2]:
5x tabular_result('edge.0': DictArray, 'edge.1': DictArray, 'edge.2': DictArray, 'edge.3': DictArray)

The tabular_result is keyed by the node name. Each value is a DictArray, with header corresponding to the states and rows corresponding to alignment position.

[3]:
states_result['edge.0']
[3]:
T C A G
0 1.000 0.000 0.000 0.000
1 0.000 0.000 0.000 1.000
2 1.000 0.000 0.000 0.000
3 0.000 0.000 0.000 1.000
4 0.000 0.000 0.000 1.000
... ... ... ... ...
2809 0.000 0.000 0.000 1.000
2810 1.000 0.000 0.000 0.000
2811 0.000 0.000 0.000 1.000
2812 0.000 0.000 1.000 0.000
2813 0.000 0.000 0.000 1.000

If not included in the newick tree file, the internal node names are automatically generated open loading. You can establish what those are by interrogating the tree bound to the likelihood function object. (If you move your mouse cursor over the nodes, their names will appear as hover text.)

[4]:
result.tree.get_figure(contemporaneous=True).show(width=500, height=500)