slim | R Documentation |
This function will execute a SLiM script generated by the compile
function during the compilation of a slendr demographic model.
slim(
model,
sequence_length,
recombination_rate,
samples = NULL,
output = NULL,
burnin = 0,
max_attempts = 1,
spatial = !is.null(model$world),
coalescent_only = TRUE,
method = c("batch", "gui"),
random_seed = NULL,
run = TRUE,
verbose = FALSE,
load = TRUE,
locations = NULL,
slim_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 |
output |
Path to the output tree-sequence file. If |
burnin |
Length of the burnin (in model's time units, i.e. years) |
max_attempts |
How many attempts should be made to place an offspring near one of its parents? Serves to prevent infinite loops on the SLiM backend. Default value is 1. |
spatial |
Should the model be executed in spatial mode? By default, if a world map was specified during model definition, simulation will proceed in a spatial mode. |
coalescent_only |
Should |
method |
How to run the script? ("gui" - open in SLiMgui, "batch" - run on the command line) |
random_seed |
Random seed (if |
run |
Should the SLiM engine be run? If |
verbose |
Write the SLiM output log to the console (default
|
load |
Should the final tree sequence be immediately loaded and returned?
Default is |
locations |
If |
slim_path |
Path to the appropriate SLiM binary (this is useful if the
|
A tree-sequence object loaded via Python-R reticulate interface function ts_load
(internally represented by the Python object tskit.trees.TreeSequence
). Optionally,
depending on the value of the arguments load =
or run =
, nothing or a character
vector, respectively.
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, 5), list(eur, 5), list(chimp, 1))
ancient_samples <- schedule_sampling(model, times = c(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 SLiM back end from a compiled slendr model object and return
# a tree-sequence output
ts <- slim(model, sequence_length = 1e5, recombination_rate = 0, samples = samples)
# automatic loading of a simulated output can be prevented by `load = FALSE`, which can be
# useful when a custom path to a tree-sequence output is given for later downstream analyses
output_file <- tempfile(fileext = ".trees")
slim(model, sequence_length = 1e5, recombination_rate = 0, samples = samples,
output = output_file, load = FALSE)
# ... at a later stage:
ts <- ts_load(output_file, model)
ts
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.