File: evo-ancestral-states.rst

package info (click to toggle)
python-cogent 2024.5.7a1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 74,600 kB
  • sloc: python: 92,479; makefile: 117; sh: 16
file content (41 lines) | stat: -rw-r--r-- 1,466 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
.. jupyter-execute::
    :hide-code:

    import set_working_directory

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.

.. jupyter-execute::

    from cogent3 import get_app

    loader = get_app("load_aligned", format="fasta")
    aln = loader("data/primate_brca1.fasta")
    gn = get_app("model", "GN", tree="data/primate_brca1.tree")
    result = gn(aln)

Define the ``ancestral_states`` app
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. jupyter-execute::

    reconstuctor = get_app("ancestral_states")
    states_result = reconstuctor(result)
    states_result

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.

.. jupyter-execute::

    states_result["edge.0"]

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.)

.. jupyter-execute::

    result.tree.get_figure(contemporaneous=True).show(width=500, height=500)