| ... | ... | @@ -2,10 +2,9 @@ |
|
|
|
|
|
|
|
We sometimes have multiple demes, i.e. different types of individuals that contribute to the phylogeny or that can be sampled (e.g. juveniles vs. adults or acute vs. chronic infections).
|
|
|
|
|
|
|
|
We illustrate this example using a birth-death (BD) model with two patches (labeled 1 and 2) and migration between these patches (at a rate *μ*).
|
|
|
|
We illustrate this example using a birth-death (BD) model with two patches (labeled 1 and 2) and migration between these patches (at a rate _μ_).
|
|
|
|
|
|
|
|
Initializing the system
|
|
|
|
-----------------------
|
|
|
|
## Initializing the system
|
|
|
|
|
|
|
|
```math
|
|
|
|
\begin{aligned}
|
| ... | ... | @@ -49,7 +48,7 @@ the parameters values are |
|
|
|
theta <- list(gamma1 = c(0.2, 0.09), gamma2 = 0.1, mu1 = 0.025, mu2 = 0.021, beta1 = c(0.26,0.37), beta2 = 0.414)
|
|
|
|
```
|
|
|
|
|
|
|
|
and the time step (for the *τ*-leap and mixed algorithms) is:
|
|
|
|
and the time step (for the _τ_-leap and mixed algorithms) is:
|
|
|
|
|
|
|
|
```r
|
|
|
|
dT <- 0.01
|
| ... | ... | @@ -61,8 +60,7 @@ A safe version of the simulator `bd_simu()` is: |
|
|
|
safe_bd_simu <- function(...) safe_run(bd_simu, ...)
|
|
|
|
```
|
|
|
|
|
|
|
|
Tau-leap trajectory simulation
|
|
|
|
------------------------------
|
|
|
|
## Tau-leap trajectory simulation
|
|
|
|
|
|
|
|
We perform the simulations using:
|
|
|
|
|
| ... | ... | @@ -93,10 +91,10 @@ Graphically, we get: |
|
|
|
```r
|
|
|
|
plot(trajbd_tl)
|
|
|
|
```
|
|
|
|
<img src="uploads/3a2faeb23a8cbd99b5e83742bf5cebeb/unnamed-chunk-37-1.png" width="350" height="230">
|
|
|
|
|
|
|
|
Phylogeny simulation
|
|
|
|
--------------------
|
|
|
|
{width="350" height="230"}
|
|
|
|
|
|
|
|
## Phylogeny simulation
|
|
|
|
|
|
|
|
### With known sampling dates and known proportion of sampling
|
|
|
|
|
| ... | ... | @@ -139,7 +137,49 @@ ape::plot.phylo(bd_tree, root.edge = T, no.margin = F, align.tip.label = T) |
|
|
|
nodelabels(pch=20,col=inode_cols)
|
|
|
|
```
|
|
|
|
|
|
|
|
<img src="uploads/277ee24ec0551ae8e833147256790e0e/unnamed-chunk-41-1.png" width="350" height="400">
|
|
|
|
{width="350" height="400"}
|
|
|
|
|
|
|
|
### With known sampling dates, each assigned to a compartment by the user
|
|
|
|
|
|
|
|
One can give as input, sampling dates assigned to a compartment, in which case the option `sampled` is not required.
|
|
|
|
|
|
|
|
```r
|
|
|
|
dates_bd <- seq(from=2015, to=2018, length.out=100)
|
|
|
|
dates_bd <- data.frame(Date=sample(dates_bd),Comp=c(rep("I1",20),rep("I2",80)))
|
|
|
|
head(dates_bd)
|
|
|
|
#> Date Comp
|
|
|
|
#> 1 2017.212 I1
|
|
|
|
#> 2 2015.515 I1
|
|
|
|
#> 3 2017.606 I1
|
|
|
|
#> 4 2015.576 I1
|
|
|
|
#> 5 2017.515 I1
|
|
|
|
#> 6 2015.030 I1
|
|
|
|
```
|
|
|
|
|
|
|
|
Now let's simulate a phylogeny with sampling dates assigned to a compartment by the user.
|
|
|
|
|
|
|
|
```r
|
|
|
|
bd_tree <- simulate_tree(
|
|
|
|
simuResults = trajbd_tl,
|
|
|
|
dates = dates_bd,
|
|
|
|
deme = c("I1", "I2"),
|
|
|
|
root = "I2", # type of individual at the root of the tree
|
|
|
|
nTrials = 3,
|
|
|
|
addInfos = TRUE) # additional info for each node
|
|
|
|
```
|
|
|
|
|
|
|
|
We can plot the phylogeny and color the external nodes given the compartment.
|
|
|
|
|
|
|
|
```r
|
|
|
|
tips_cols <- ifelse(grepl(x=bd_tree$tip.label,pattern="I2"),"blue","red")
|
|
|
|
```
|
|
|
|
|
|
|
|
```r
|
|
|
|
ape::plot.phylo(bd_tree, root.edge = T, no.margin = F, show.tip.label = F)
|
|
|
|
tiplabels(pch=20,col=tips_cols)
|
|
|
|
```
|
|
|
|
|
|
|
|
{width="350" height="400"}
|
|
|
|
|
|
|
|
### With known sampling dates, each assigned to a compartment by the user
|
|
|
|
|
| ... | ... | @@ -181,4 +221,51 @@ ape::plot.phylo(bd_tree, root.edge = T, no.margin = F, show.tip.label = F) |
|
|
|
tiplabels(pch=20,col=tips_cols)
|
|
|
|
```
|
|
|
|
|
|
|
|
<img src="uploads/93146df8aff6c245d2aa599f5441d7ed/unnamed-chunk-45-1.png" width="350" height="400"> |
|
|
\ No newline at end of file |
|
|
|
{width="350" height="400"}
|
|
|
|
|
|
|
|
### With only known sampling dates
|
|
|
|
|
|
|
|
In the case where the user has no information on the sampling proportions or the assignment of sampling dates on any compartment, the algorithm will randomly assign each sampling date to a compartment. The user gives as input sampling dates:
|
|
|
|
|
|
|
|
```r
|
|
|
|
dates_bd <- seq(from=2015, to=2018, length.out=100)
|
|
|
|
```
|
|
|
|
|
|
|
|
Now let's simulate a phylogeny with sampling dates and no information about the sampling schemes :
|
|
|
|
|
|
|
|
```r
|
|
|
|
bd_tree <- simulate_tree(
|
|
|
|
simuResults = trajbd_tl,
|
|
|
|
dates = dates_bd,
|
|
|
|
sampled = c("I1","I2"),
|
|
|
|
deme = c("I1", "I2"),
|
|
|
|
root = "I2", # type of individual at the root of the tree
|
|
|
|
nTrials = 10,
|
|
|
|
addInfos = TRUE) # additional info for each node
|
|
|
|
```
|
|
|
|
|
|
|
|
```r
|
|
|
|
ape::plot.phylo(bd_tree, root.edge = T, no.margin = F, show.tip.label = F)
|
|
|
|
```
|
|
|
|
|
|
|
|
{width="350" height="400"}
|
|
|
|
|
|
|
|
### Without given sampling dates
|
|
|
|
|
|
|
|
Let's simuate a phylogeny where simulated deaths in the trajectory generate leaves. This can be done with the `isFullTrajectory` option.
|
|
|
|
|
|
|
|
```r
|
|
|
|
bd_tree <- simulate_tree(
|
|
|
|
simuResults = trajbd_tl,
|
|
|
|
deme = c("I1", "I2"),
|
|
|
|
root = "I2", # type of individual at the root of the tree
|
|
|
|
nTrials = 10,
|
|
|
|
isFullTrajectory = TRUE, # deads generate leaves
|
|
|
|
addInfos = TRUE) # additional info for each node
|
|
|
|
```
|
|
|
|
|
|
|
|
```r
|
|
|
|
ape::plot.phylo(bd_tree, root.edge = T, no.margin = F, show.tip.label = F)
|
|
|
|
```
|
|
|
|
|
|
|
|
{width="350" height="400"} |
|
|
\ No newline at end of file |