msprime | R Documentation |
This function will execute a built-in msprime script and run a compiled slendr demographic model.
msprime(
model,
sequence_length,
recombination_rate,
samples = NULL,
random_seed = NULL,
verbose = FALSE,
debug = FALSE,
run = TRUE,
path = NULL
)
model |
Model object created by the |
sequence_length |
Total length of the simulated sequence (in base-pairs) |
recombination_rate |
Recombination rate of the simulated sequence (in recombinations per basepair per generation) |
samples |
A data frame of times at which a given number of individuals
should be remembered in the tree-sequence (see |
random_seed |
Random seed (if |
verbose |
Write the log information from the SLiM run to the console
(default |
debug |
Write msprime's debug log to the console (default |
run |
Should the msprime engine be run? If |
path |
Path to the directory where simulation result files will be saved.
If |
A tree-sequence object loaded via Python-R reticulate interface function ts_read
(internally represented by the Python object tskit.trees.TreeSequence
). If the
path
argument was set, it will return the path as a single-element character vector.
init_env()
# load an example model
model <- read_model(path = system.file("extdata/models/introgression", package = "slendr"))
# afr and eur objects would normally be created before slendr model compilation,
# but here we take them out of the model object already compiled for this
# example (in a standard slendr simulation pipeline, this wouldn't be necessary)
afr <- model$populations[["AFR"]]
eur <- model$populations[["EUR"]]
chimp <- model$populations[["CH"]]
# schedule the sampling of a couple of ancient and present-day individuals
# given model at 20 ky, 10 ky, 5ky ago and at present-day (time 0)
modern_samples <- schedule_sampling(model, times = 0, list(afr, 10), list(eur, 100), list(chimp, 1))
ancient_samples <- schedule_sampling(model, times = c(40000, 30000, 20000, 10000), list(eur, 1))
# sampling schedules are just data frames and can be merged easily
samples <- rbind(modern_samples, ancient_samples)
# run a simulation using the msprime back end from a compiled slendr model object
ts <- msprime(model, sequence_length = 1e5, recombination_rate = 0, samples = samples)
# simulated tree-sequence object can be saved to a file using ts_write()...
ts_file <- normalizePath(tempfile(fileext = ".trees"), winslash = "/", mustWork = FALSE)
ts_write(ts, ts_file)
# ... and, at a later point, loaded by ts_read()
ts <- ts_read(ts_file, model)
summary(ts)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.