check_dependencies(python = TRUE, quit = TRUE) # dependencies must be present
init_env()
# load an example model with an already simulated tree sequence
path <- system.file("extdata/models/introgression", package = "slendr")
model <- read_model(path)
# afr, eur, and nea 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"]]
nea <- model$populations[["NEA"]]
# schedule the recording of 10 African and 100 European individuals from a
# given model at 20 ky, 10 ky, 5ky ago and at present-day (time 0)
schedule_amh <- schedule_sampling(
model, times = c(20000, 10000, 5000, 0),
list(afr, 10), list(eur, 100)
)
# schedule the recording of the Vindija Neanderthal genome
schedule_nea <- schedule_sampling(model, times = 40000, list(nea, 1, "Vindija"))
# the result of `schedule_sampling` is a simple data frame (note that the locations
# of sampling locations have `NA` values because the model is non-spatial)
schedule <- rbind(schedule_amh, schedule_nea)
schedule
# simulate a tree sequence
ts <- msprime(model, sequence_length = 1e6, recombination_rate = 1e-8, samples = schedule)
# inspect the recorded table of samples
ts_samples(ts)
Run the code above in your browser using DataLab