Reconstructing ancestral sequences

How to reconstruct ancestral sequences?
This tutorial shows how to reconstruct ancestral sequences using likelihood methods. It assumes that you have a sequence alignment (as a SiteContainer object) and a phylogenetic tree (as a Tree object).

Define a sequence evolution model and fit it
You can chose any homogeneous or non-homogeneous model to reconstruct ancestral sequences. Currently mixed models are not supported. In order to use the reconstruction method, we will need a double-recursive likelihood class:

In most cases you will like to fit the model to the data, and estimate parameters. This requires the use of the OptimizationTools::optimizeNumericalParameter function. For doing so, it might be a good idea to use a RHomogeneousTreeLikelihood, as it will be less memory greedy and faster to optimize, and in a second step build the DR likelihood object directly from estimated parameters.

Reconstruct ancestral sequences using the marginal method
This method implements the marginal reconstruction of Yang (ref). It reconstructs sequences at requested nodes independently, and therefore can be inaccurate when several ancestral sequences are to be reconstructed.

This will retrieve the ancestral sequence for the node with id 25. In this case, the state with maximum posterior probability for each site will be used. In order to assess the uncertainty in the ancestral reconstruction, it is possible to retrieve the posterior probabilities for each state at each site:

The uncertainty is the reconstruction can for example be assessed with the Shannon entropy:

It is also possible to sample the ancestral sequence from the posterior probabilities:

The full set of ancestral sequences can be retrieved as a SiteContainer object, with or without sampling:

Note: for now, joint reconstruction is not available.