
Simulate host and symbiont trees with known co-diversification
Source:R/simulate_codiv_data.R
simulate_codiv_data.RdBuilds a host tree and a symbiont tree assembled from several clades, each with known ground truth, all mapping to the same set of hosts. Use it for a fixed sanity-check or to generate many random datasets to study how tree features affect the scan.
Arguments
- n_hosts
Number of host tips (ignored if
host_treeis supplied)- clades
Optional list of clade specifications, each a list with
codiversifying(logical) and optionallycongruenceandn_per_host. If NULL,n_cladesrandom clades are generated.- n_clades
Number of random clades to generate when
cladesis NULL- prop_codiversifying
Probability a random clade is co-diversifying
- congruence_range
Range to draw random co-diversifying
congruencefrom- n_per_host_range
Integer range to draw random
n_per_hostfrom- bl_noise
Multiplicative branch-length jitter (0 = none)
- host_tree
Optional host tree (phylo); if NULL a random coalescent tree of
n_hoststips is used- seed
Optional random seed
Value
A list with:
host_tree: the host tree (phylo)symbiont_tree: the combined symbiont tree (phylo)links: data frame of Host-Symbiont associationstruth: per-symbiont ground truth (clade, codiversifying, congruence, n_per_host)
Details
Each clade is one monophyletic block of the symbiont tree, controlled by:
codiversifying: whether its topology tracks the host treecongruence: for co-diversifying clades, how closely it tracks the host (1 = identical branching order; lower = more scrambled)n_per_host: symbionts sampled per host (1 = no within-host pseudoreplication; > 1 introduces it)
Examples
# fixed four-clade sanity check
sim <- simulate_codiv_data(
n_hosts = 10,
clades = list(
list(codiversifying = TRUE, congruence = 1.0, n_per_host = 1),
list(codiversifying = TRUE, congruence = 0.6, n_per_host = 4),
list(codiversifying = FALSE, n_per_host = 1),
list(codiversifying = FALSE, n_per_host = 4)
),
seed = 1
)
sim$host_tree
#>
#> Phylogenetic tree with 10 tips and 9 internal nodes.
#>
#> Tip labels:
#> H1, H2, H3, H4, H5, H6, ...
#>
#> Rooted; includes branch length(s).
head(sim$links)
#> Host Symbiont
#> 1 H1 c1_h1
#> 2 H2 c1_h2
#> 3 H3 c1_h3
#> 4 H4 c1_h4
#> 5 H5 c1_h5
#> 6 H6 c1_h6
# many random datasets (vary seed) to study tree-feature effects
rand <- simulate_codiv_data(n_hosts = 15, n_clades = 6, seed = 42)