General Time-Reversible (GTR) [1] is the most general nucleotide substitution model which holds the time-reversibility property.
\[
Q_{ij} =
\begin{bmatrix}
. & \alpha I & \beta I & \gamma I \\
\alpha I & . & \delta I & \epsilon I \\
\beta I & \delta I & . & \zeta I \\
\gamma I & \epsilon I & \zeta I & . \\
\end{bmatrix}
\begin{bmatrix}
\pi_1 & 0 & 0 & 0 \\
0 & \pi_2 & 0 & 0 \\
0 & 0 & \pi_3 & 0\\
0 & 0 & 0 &\pi_4 \\
\end{bmatrix}
\] In PalantiR, GTR is used as a general
state-transition model. It can also be simulated from directly.
Load model parameters:
# Load phylogeny
mammals <- Phylogeny("../inst/extdata/mammals.newick")
# Load nucleotide equilibrium distribution
# Nucleotide order is T,C,A,G
pi <- c(.3, .2, .25, .25)
# Load exchangeability parameters
e <- c(a = 1, b = 2, g = 2, d = 1, e = 1, z = 2)
ex <- matrix(c(0, e["a"], e["b"], e["g"],
e["a"], 0 , e["d"], e["e"],
e["b"], e["d"], 0 , e["z"],
e["g"], e["e"], e["z"], 0), nrow = 4)Create model:
gtr <- GeneralTimeReversible(
equilibrium = pi,
exchangeability = ex)
# To simulate from GTR as a nucleotide model, model type needs to be set manually:
gtr$type <- "nucleotide"Sample sequence from model equilibrium distribution to start at root:
Simulate:
Plot substitution history:
Transition substitutions are shown in green, transversions in red.
Check substitution history table:
| site | node | time | from | to | nucleotide_from | nucleotide_to | transition | color |
|---|---|---|---|---|---|---|---|---|
| 0 | 22 | 0.0035946 | 1 | 2 | C | A | FALSE | #E84B2A |
| 0 | 23 | 0.0330732 | 1 | 2 | C | A | FALSE | #E84B2A |
| 0 | 24 | 0.0188619 | 1 | 0 | C | T | TRUE | #16A35E |
| 0 | 26 | 0.1127014 | 0 | 2 | T | A | FALSE | #E84B2A |
| 0 | 31 | 0.0078614 | 1 | 3 | C | G | FALSE | #E84B2A |
| 0 | 33 | 0.0435775 | 3 | 0 | G | T | FALSE | #E84B2A |