This function loads a tree sequence file simulated from a given slendr model. Optionally, the tree sequence can be recapitated and simplified.
Arguments
- file
A path to the tree-sequence file (either originating from a slendr model or a standard non-slendr tree sequence).
- model
Optional
slendr_model
object which produced the tree-sequencefile
. Used for adding various annotation data and metadata to the standard tskit tree-sequence object.
Value
Tree-sequence object of the class slendr_ts
, which serves as
an interface point for the Python module tskit using slendr functions with
the ts_
prefix.
Details
The loading, recapitation and simplification is performed using the Python module pyslim which serves as a link between tree sequences generated by SLiM and the tskit module for manipulation of tree sequence data. All of these steps have been modelled after the official pyslim tutorial and documentation available at: https://tskit.dev/pyslim/docs/latest/tutorial.html.
The recapitation and simplification steps can also be performed individually
using the functions ts_recapitate
and
ts_simplify
.
See also
ts_nodes
for extracting useful information about
individuals, nodes, coalescent times and geospatial locations of nodes on a
map
Examples
check_dependencies(python = TRUE, quit = TRUE) # dependencies must be present
init_env()
#> The interface to all required Python modules has been activated.
# load an example model with an already simulated tree sequence
slendr_ts <- system.file("extdata/models/introgression_slim.trees", package = "slendr")
model <- read_model(path = system.file("extdata/models/introgression", package = "slendr"))
# load tree sequence generated by a given model
ts <- ts_read(slendr_ts, model)
# even tree sequences generated by non-slendr models can be
msprime_ts <- system.file("extdata/models/msprime.trees", package = "slendr")
ts <- ts_read(msprime_ts)
# load tree sequence and immediately simplify it only to sampled individuals
# (note that the example tree sequence is already simplified so this operation
# does not do anything in this case)
ts <- ts_read(slendr_ts, model = model) %>% ts_simplify(keep_input_roots = TRUE)
# load tree sequence and simplify it to a subset of sampled individuals
ts_small <- ts_simplify(ts, simplify_to = c("CH_1", "NEA_1", "NEA_2",
"AFR_1", "AFR_2", "EUR_1", "EUR_2"))
# load tree sequence, recapitate it and simplify it
ts <- ts_read(slendr_ts, model) %>%
ts_recapitate(recombination_rate = 1e-8, Ne = 10000, random_seed = 42) %>%
ts_simplify()
# load tree sequence, recapitate it, simplify it and overlay neutral mutations
ts <- ts_read(slendr_ts, model) %>%
ts_recapitate(recombination_rate = 1e-8, Ne = 10000, random_seed = 42) %>%
ts_simplify() %>%
ts_mutate(mutation_rate = 1e-8)
ts
#> ╔═════════════════════════╗
#> ║TreeSequence ║
#> ╠═══════════════╤═════════╣
#> ║Trees │ 68║
#> ╟───────────────┼─────────╢
#> ║Sequence Length│ 500000║
#> ╟───────────────┼─────────╢
#> ║Time Units │ ticks║
#> ╟───────────────┼─────────╢
#> ║Sample Nodes │ 26║
#> ╟───────────────┼─────────╢
#> ║Total Size │210.9 KiB║
#> ╚═══════════════╧═════════╝
#> ╔═══════════╤════╤════════╤════════════╗
#> ║Table │Rows│Size │Has Metadata║
#> ╠═══════════╪════╪════════╪════════════╣
#> ║Edges │ 293│ 9.2 KiB│ No║
#> ╟───────────┼────┼────────┼────────────╢
#> ║Individuals│ 70│ 8.6 KiB│ Yes║
#> ╟───────────┼────┼────────┼────────────╢
#> ║Migrations │ 0│ 8 Bytes│ No║
#> ╟───────────┼────┼────────┼────────────╢
#> ║Mutations │2186│80.2 KiB│ No║
#> ╟───────────┼────┼────────┼────────────╢
#> ║Nodes │ 84│ 3.8 KiB│ Yes║
#> ╟───────────┼────┼────────┼────────────╢
#> ║Populations│ 6│ 2.7 KiB│ Yes║
#> ╟───────────┼────┼────────┼────────────╢
#> ║Provenances│ 6│48.2 KiB│ No║
#> ╟───────────┼────┼────────┼────────────╢
#> ║Sites │2181│53.3 KiB│ No║
#> ╚═══════════╧════╧════════╧════════════╝
#>