Package: slendr 1.5.0.9000

Martin Petr

slendr: A Simulation Framework for Spatiotemporal Population Genetics

A framework for simulating spatially explicit genomic data which leverages real cartographic information for programmatic and visual encoding of spatiotemporal population dynamics on real geographic landscapes. Population genetic models are then automatically executed by the 'SLiM' software by Haller et al. (2019) <doi:10.1093/molbev/msy228> behind the scenes, using a custom built-in simulation 'SLiM' script. Additionally, fully abstract spatial models not tied to a specific geographic location are supported, and users can also simulate data from standard, non-spatial, random-mating models. These can be simulated either with the 'SLiM' built-in back-end script, or using an efficient coalescent population genetics simulator 'msprime' by Baumdicker et al. (2022) <doi:10.1093/genetics/iyab229> with a custom-built 'Python' script bundled with the R package. Simulated genomic data is saved in a tree-sequence format and can be loaded, manipulated, and summarised using tree-sequence functionality via an R interface to the 'Python' module 'tskit' by Kelleher et al. (2019) <doi:10.1038/s41588-019-0483-y>. Complete model configuration, simulation and analysis pipelines can be therefore constructed without a need to leave the R environment, eliminating friction between disparate tools for population genetic simulations and data analysis.

Authors:Martin Petr [aut, cre]

slendr_1.5.0.9000.tar.gz
slendr_1.5.0.9000.zip(r-4.7)slendr_1.5.0.9000.zip(r-4.6)slendr_1.5.0.9000.zip(r-4.5)
slendr_1.5.0.9000.tgz(r-4.6-any)slendr_1.5.0.9000.tgz(r-4.5-any)
slendr_1.5.0.9000.tar.gz(r-4.7-any)slendr_1.5.0.9000.tar.gz(r-4.6-any)
slendr_1.5.0.9000.tgz(r-4.6-emscripten)
manual.pdf |manual.html
DESCRIPTION |NEWS
card.svg |card.png
slendr/json (API)

# Install 'slendr' in R:
install.packages('slendr', repos = c('https://bodkan.r-universe.dev', 'https://cloud.r-project.org'))

Bug tracker:https://github.com/bodkan/slendr/issues

On CRAN:

Conda:

popgenpopulation-geneticssimulationsspatial-statistics

9.50 score 64 stars 150 scripts 496 downloads 71 exports 60 dependencies

Last updated from:91915ea414. Checks:7 WARNING, 2 OK. Indexed: yes.

TargetResultTimeFilesSyslog
linux-devel-x86_64WARNING204
source / vignettesOK226
linux-release-x86_64WARNING208
macos-release-arm64WARNING121
macos-oldrel-arm64WARNING110
windows-develWARNING168
windows-releaseWARNING140
windows-oldrelWARNING142
wasm-releaseOK171

Exports:%>%animate_modelareaas.phylo.slendr_phylocheck_dependenciescheck_envclear_envcompile_modeldistanceexpand_rangeexplore_modelextract_parametersgene_flowget_pythoninit_envjoinmovemsprimeoverlapplot_mapplot_modelpopulationprint.slendr_tsread_modelregionreprojectresizeschedule_samplingset_dispersalset_rangesetup_envshrink_rangeslimsubstitute_valuessubtractts_afsts_ancestorsts_coalescedts_descendantsts_divergencets_diversityts_drawts_edgests_eigenstratts_extendts_f2ts_f3ts_f4ts_f4ratiots_fstts_genotypests_ibdts_loadts_metadatats_mutatets_namests_nodests_phylots_readts_recapitatets_samplests_savets_segregatingts_simplifyts_tablets_tajimats_tractsts_treets_vcfts_writeworld

Dependencies:apebackportsbitbit64checkmateclicliprcpp11crayondigestdplyrfarverfsgenericsggplot2ggrepelgluegtableherehmsijtiffisobandjsonlitelabelinglatticelifecyclelubridatemagrittrMatrixnlmepillarpkgconfigpngprettyunitsprogresspurrrR6rappdirsRColorBrewerRcppRcppTOMLreadrreticulaterlangrprojrootS7scalesstrexstringistringrtibbletidyrtidyselecttimechangetzdbutf8vctrsviridisLitevroomwithr

Extending models with custom SLiM code
Introduction | Disclaimers and caveats | slendr / SLiM "API" | Referring to populations: population() Eidos function | Referring to times: tick() Eidos function | Referring to model times: model_time() Eidos function | Logging: write_log() Eidos function | Saving and re-starting simulation state: save_state() and reset_state() | Global constants | Practical examples | Putting it all together: running a customized slendr simulation | Putting it all together: parametrizing a customized slendr simulation | Programming slendr/SLiM extension snippets directly in R scripts | Customizing genomic architecture (selective sweep simulations)

Last update: 2026-06-26
Started: 2024-05-07

Installation instructions
Quick installation | Software dependencies | sf, stars, rnaturalearth | macOS | Linux | SLiM | Adding SLiM to the $PATH | Fallback options | Python | Failing conda? | Information for Python experts | ModuleNotFoundError: No module named 'tskit' error

Last update: 2026-06-26
Started: 2022-03-21

Introduction and basic tutorial
Motivation | Geospatial data | Installation and setup | Defining the overall world map | Plotting geographic features and population ranges | Defining smaller geographic regions | Defining spatial population boundaries | Polygon population ranges | Circular population ranges | Population movement across a landscape | Spatial population expansion | Plotting multiple slendr objects | Defining gene flow events | Compile the whole model and load it in SLiM | Visualize the entire history of splits and gene flow | Interactive exploration of spatio-temporal models | Running the simulation | More information

Last update: 2026-06-26
Started: 2021-07-16

Programming dispersion dynamics

Last update: 2026-06-26
Started: 2021-07-16

Spatially annotated tree sequences
Introduction | Model specification | Scheduling sampling events and simulation | Extracting spatial tree sequence information | Using the simple features interface | Plotting locations of simulated sampled individuals | Extracting spatio-temporal ancestral relationships | Calculating distances and other statistics using the sf package

Last update: 2026-06-26
Started: 2021-08-03

Standard SLiM and msprime tree sequences
SLiM tree sequences | msprime tree sequences | Spatial SLiM tree sequences | Conclusion

Last update: 2026-06-26
Started: 2022-06-22

Traditional, non-spatial models
Extracting parameters from a model or tree sequences | Named samples

Last update: 2026-06-26
Started: 2021-07-16

Tree-sequence processing and statistics
Setting up Python environment | Model of Neanderthal introgression into Eurasians | Scheduling of sampling events | Named samples | R interface for tskit and pyslim | Loading and processing tree-sequence output files | Visualisation of trees and tree-sequences | Accessing tskit functionality directly | Calculating f-statistics | Estimating Neanderthal ancestry proportions | ADMIXTOOLS analyses | VCF output | Other statistics | $F_{st}$ | Tajima's $D$ | Diversity | Divergence | More information

Last update: 2026-06-26
Started: 2021-07-22

Demes on a regular spatial grid
Simple two-dimensional grid model | Population grid on a real geographic landscape | More customized spatial model

Last update: 2026-01-12
Started: 2021-07-16

Extracting true ancestry tracts
Demographic model | Tree sequence simulation | Extracting ancestry tracts | Summaries of ancestral proportions | "Chromosome painting" of ancestry tracts | Average tract lengths: | Distribution of ancestry tract lengths | Pure msprime tree sequence

Last update: 2026-01-12
Started: 2023-11-27

Simulations using SLiM and msprime engines
Detecting gene flow from msprime and SLiM tree sequences | Defining a model | Compiling the model and simulating data | Comparing the outputs of msprime and SLiM runs of a slendr model | Comparing results of population genetics statistics | Computing allele frequency spectra | Model definition | Conclusion

Last update: 2026-01-12
Started: 2024-11-14

Readme and manuals

Help Manual

Help pageTopics
Animate the simulated population dynamicsanimate_model
Calculate the area covered by the given slendr objectarea
Check that the required dependencies are available for slendr to workcheck_dependencies
Check that the active Python environment is setup for slendrcheck_env
Remove the automatically created slendr Python environmentclear_env
Compile a slendr demographic modelcompile_model
Calculate the distance between a pair of spatial boundariesdistance
Expand the population rangeexpand_range
Open an interactive browser of the spatial modelexplore_model
Extract information from a compiled model or a simulated tree sequenceextract_parameters
Define a gene-flow event between two populationsgene_flow
Get a path to internal Python interpreter of slendrget_python
Activate the Python environment of slendrinit_env
Merge two spatial 'slendr' objects into onejoin
Move the population to a new location in a given amount of timemove
Run a slendr model in msprimemsprime
Generate the overlap of two 'slendr' objectsoverlap
Plot 'slendr' geographic features on a mapplot_map
Plot demographic history encoded in a slendr modelplot_model
Define a populationpopulation
Print a short summary of a 'slendr' objectprint.slendr_map print.slendr_model print.slendr_pop print.slendr_region
Print tskit's summary table of the Python tree-sequence objectprint.slendr_ts
Read a previously serialized model configurationread_model
Define a geographic regionregion
Reproject coordinates between coordinate systemsreproject
Change the population sizeresize
Define sampling events for a given set of populationsschedule_sampling
Change dispersal parametersset_dispersal
Update the population rangeset_range
Setup a dedicated Python virtual environment for slendrsetup_env
Shrink the population rangeshrink_range
Run a slendr model in SLiMslim
Substitute values of parameters in a SLiM extension templatesubstitute_values
Generate the difference between two 'slendr' objectssubtract
Summarise the contents of a 'ts_nodes' resultsummary.slendr_nodes
Compute the allele frequency spectrum (AFS)ts_afs
Extract (spatio-)temporal ancestral history for given nodes/individualsts_ancestors
Check that all trees in the tree sequence are fully coalescedts_coalesced
Extract all descendants of a given tree-sequence nodets_descendants
Calculate pairwise divergence between sets of individualsts_divergence
Calculate diversity in given sets of individualsts_diversity
Plot a graphical representation of a single treets_draw
Extract spatio-temporal edge annotation table from a given tree or tree sequencets_edges
Convert genotypes to the EIGENSTRAT file formatts_eigenstrat
Extend the span of sequences covered by ancestral nodes (EXPERIMENTAL)ts_extend
Calculate the f2, f3, f4, and f4-ratio statisticsts_f2 ts_f3 ts_f4 ts_f4ratio
Calculate pairwise statistics between sets of individualsts_fst
Extract genotype table from the tree sequencets_genotypes
Extract Identity-by-Descent (IBD) segments (EXPERIMENTAL)ts_ibd
Read a tree sequence from a filets_load
Extract list with tree sequence metadata saved by SLiMts_metadata
Add mutations to the given tree sequencets_mutate
Extract names of individuals in a tree sequencets_names
Extract combined annotated table of individuals and nodests_nodes
Convert a tree in the tree sequence to an object of the class 'phylo'ts_phylo
Read a tree sequence from a filets_read
Recapitate the tree sequencets_recapitate
Extract names and times of individuals of interest in the current tree sequence (either all sampled individuals or those that the user simplified to)ts_samples
Write a tree sequence to a filets_save
Calculate the density of segregating sites for the given sets of individualsts_segregating
Simplify the tree sequence down to a given set of individualsts_simplify
Get the table of individuals/nodes/edges/mutations/sites from the tree sequencets_table
Calculate Tajima's D for given sets of individualsts_tajima
Extract ancestry tracts from a tree sequence (EXPERIMENTAL)ts_tracts
Get a tree from a given tree sequencets_tree
Save genotypes from the tree sequence as a VCF filets_vcf
Save a tree sequence to a filets_write
Define a world map for all spatial operationsworld