### SLiM Initial Population Setup Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 15.13 - Range expansion in a stepping-stone model I.txt Creates the initial population by adding subpopulations. The first subpopulation is initialized with 100 individuals, while others start empty. ```SLiM 1 early() { // create an initial population of 100 individuals, the rest empty for (i in seqLen(N)) sim.addSubpop(i, (i == 0) ? 100 else 0); } ``` -------------------------------- ### SLiM Early Population Setup Source: https://github.com/messerlab/slim/blob/master/SLiMgui/Recipes/Recipe 9.6.2 - A sweep from standing variation at a predetermined locus.txt Sets up the initial population size and saves the simulation ID. ```slim 1 early() { // save this run's identifier, used to save and restore defineConstant("simID", getSeed()); sim.addSubpop("p1", 500); } ``` -------------------------------- ### Early Stage: Setup and Initial State Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 14.13 - Modeling biallelic loci with a mutation() callback II.txt Initializes the subpopulation, creates permanent m2 mutation objects, and then removes them to start all individuals in the 'aa' state. It also sets up logging for mutation frequencies. ```slim 1 early() { sim.addSubpop("p1", 100); // create the permanent m2 mutation objects we will use target = p1.haplosomes[0]; target.addNewDrawnMutation(m2, 0:99); defineConstant("MUT", target.mutations); // then remove them; start with "aa" for all individuals target.removeMutations(); // log results log = community.createLogFile("freq.csv", logInterval=10); log.addTick(); log.addMeanSDColumns("freq", "sim.mutationFrequencies(NULL, MUT);"); } ``` -------------------------------- ### SLiM Simulation Initialization and Setup Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 14.16 - Visualizing linkage disequilibrium.txt Initializes the SLiM simulation environment, including setting the random seed, defining genome length, mutation rates, genomic elements, and recombination rate. This setup is crucial before running any simulation. ```SLiM initialize() { setSeed(2180149919968428688); defineConstant("L", 1e7); initializeMutationRate(1e-7); initializeMutationType("m1", 0.5, "f", 0.0); initializeMutationType("m2", 1.0, "f", 0.1).color="red"; // used for MUT1 initializeGenomicElementType("g1", m1, 1.0); initializeGenomicElement(g1, 0, L-1); initializeRecombinationRate(1e-8); } 1 early() { sim.addSubpop("p1", 1000); } 5000 late() { // create the MUT1 mutation that we will track over time mut1 = sample(p1.haplosomes, 1).addNewDrawnMutation(m2, asInteger(L/2)); defineGlobal("MUT1", mut1); } ``` -------------------------------- ### Initial Population Setup Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 20.5 - A continuous-space host-parasitoid model.txt Sets up the initial subpopulations for hosts and parasitoids, including their spatial bounds and initial positions. ```SLiM ticks all 1 early() { host.addSubpop("p1", N0_host); p1.setSpatialBounds(c(0, 0, SIDE, SIDE)); p1.individuals.setSpatialPosition(p1.pointUniform(N0_host)); parasitoid.addSubpop("p2", N0_parasitoid); p2.setSpatialBounds(c(0, 0, SIDE, SIDE)); p2.individuals.setSpatialPosition(p2.pointUniform(N0_parasitoid)); } ``` -------------------------------- ### Early Simulation Setup Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 9.2 - Making sweeps conditional on fixation.txt Initializes the subpopulation and saves the simulation ID at the beginning of the run. ```slim 1 early() { // save this run's identifier, used to save and restore defineConstant("simID", getSeed()); sim.addSubpop("p1", 500); } ``` -------------------------------- ### Early Tick Population Setup Source: https://github.com/messerlab/slim/blob/master/SLiMgui/Recipes/Recipe 20.3 - A deterministic host-parasitoid model.txt Sets up the initial subpopulations for host ('p1') and parasitoid ('p2') at the beginning of the simulation (tick 1). This establishes the starting population sizes based on pre-defined constants. ```SLiM ticks all early() { host.addSubpop("p1", N0_host); parasitoid.addSubpop("p2", N0_parasitoid); } ``` -------------------------------- ### Initial Population Setup Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 16.2 - Following a pedigree.txt Sets up the initial subpopulation with a specified size and assigns initial tags to individuals. ```SLiM 1 early() { sim.addSubpop("p1", 10); // provide initial tags matching the original model p1.individuals.tag = 1:10; } ``` -------------------------------- ### Initial Setup and Logging Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 20.8 - Within-host reproduction in a host-pathogen model.txt Sets up the initial monkey population, introduces the first infections, and creates a log file to record simulation progress. ```SLiM ticks all 1 early() { monkey.addSubpop("p1", K_MONKEY); // choose initial hosts carrying the infection initial_hosts = p1.sampleIndividuals(5, replace=F); pathogen.tag = 3; for (initial_host in initial_hosts) { // make a pathogen subpop for the host pathogen_subpop = pathogen.addSubpop(pathogen.tag, 1); pathogen_subpop.tag = initial_host.pedigreeID; pathogen.tag = pathogen.tag + 1; } // log some basic output logfile = community.createLogFile("host_pathogen_log.csv", logInterval=1); logfile.addTick(); logfile.addSubpopulationSize(p1); logfile.addPopulationSize(pathogen); logfile.addCustomColumn("host_count", "pathogen.subpopulations.size();"); logfile.addMeanSDColumns("monkeyAge", "p1.individuals.age;"); } ``` -------------------------------- ### Install SLiMgui Executable Source: https://github.com/messerlab/slim/blob/master/CMakeLists.txt Installs the built SLiMgui executable to the 'bin' directory. ```cmake install(TARGETS ${TARGET_NAME_SLIMGUI} DESTINATION bin) ``` -------------------------------- ### SLiM Early Population Setup Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 16.7 - Tracking separate sexes in script, nonWF style.txt Initializes the subpopulation with a carrying capacity and assigns random sexes to individuals at the start of the simulation. ```SLiM 1 early() { sim.addSubpop("p1", K); // assign random sexes (T = male, F = female) p1.individuals.tagL0 = (runif(p1.individualCount) <= 0.5); } ``` -------------------------------- ### Build and Install Arch Linux Package Source: https://github.com/messerlab/slim/wiki/Arch-Linux-packaging Builds and installs the SLiM package, running CLI tests beforehand. This process may take a significant amount of time. ```bash makepkg -si ``` -------------------------------- ### Install SLiM using MSYS2 Source: https://github.com/messerlab/slim/blob/master/README.md Install SLiM and SLiMgui using the pacman package manager on MSYS2. Ensure MSYS2 is updated before installation. ```bash pacman -S mingw-w64-x86_64-slim-simulator ``` -------------------------------- ### Early Stage Simulation Setup Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 11.1 - Assortative mating.txt Initializes subpopulations and sets migration rates between them. This function runs at the beginning of the simulation. ```slim 1 early() { sim.setValue("FST", 0.0); sim.addSubpop("p1", 500); sim.addSubpop("p2", 500); p1.setMigrationRates(p2, 0.1); p2.setMigrationRates(p1, 0.1); } ``` -------------------------------- ### Set up Initial Population Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 17.6 - Divergence due to phenotypic competition with an interaction() callback.txt Creates the initial subpopulation named 'p1' with 500 individuals at the start of the simulation. ```slim 1 late() { sim.addSubpop("p1", 500); } ``` -------------------------------- ### CMake Build with GUI Enabled Source: https://github.com/messerlab/slim/blob/master/CMakeLists.txt Builds SLiM with its Qt5-based GUI enabled. Requires Qt5 libraries to be installed. ```bash cd build cmake -D BUILD_SLIMGUI=ON ../SLiM make -j10 ``` -------------------------------- ### Initial Population Setup Source: https://github.com/messerlab/slim/blob/master/SLiMgui/Recipes/Recipe 16.11 - Life-long monogamous mating.txt Creates the initial subpopulation with a defined carrying capacity and assigns random ages and an 'unmated' tag to all individuals. ```SLiM 1 first() { sim.addSubpop("p1", K); p1.individuals.age = rdunif(K, min=0, max=15); // initial variation in age p1.individuals.tag = -1; // mark all individuals as unmated } ``` -------------------------------- ### Early Stage: Subpopulation and Migration Setup Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 12.3 - Simulating gene drive.txt Initializes subpopulations and sets migration rates between them. This function runs at the beginning of the simulation (generation 1). ```SLiM 1 early() { for (i in 0:5) sim.addSubpop(i, 500); for (i in 1:5) sim.subpopulations[i].setMigrationRates(i-1, 0.001); for (i in 0:4) sim.subpopulations[i].setMigrationRates(i+1, 0.1); } ``` -------------------------------- ### Single-line comment example Source: https://github.com/messerlab/slim/blob/master/QtSLiM/help/EidosHelpStatements.html Illustrates how to use single-line comments starting with '//' in Eidos code. ```Eidos 1 + 1 == 2; // this is true ``` -------------------------------- ### SLiM Initialization and Setup Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 9.11 - Effective population size versus census population size.txt Sets up global parameters, mutation rates, genomic elements, and recombination rates for the SLiM simulation. Initializes SLiM options to keep pedigrees. ```SLiM initialize() { defineGlobal("N", 1000); defineGlobal("L", 1e7); defineGlobal("MU", 1e-7); defineGlobal("R", 1e-8); defineGlobal("S", 2.0); initializeSLiMOptions(keepPedigrees=T); initializeMutationRate(MU); initializeMutationType("m1", 0.5, "f", 0.0); // neutral initializeMutationType("m2", 0.5, "f", S); // sweep m2.convertToSubstitution = F; initializeGenomicElementType("g1", m1, 1.0); initializeGenomicElement(g1, 0, L-1); initializeRecombinationRate(R); } ``` -------------------------------- ### Initial Setup and Logging Source: https://github.com/messerlab/slim/blob/master/SLiMgui/Recipes/Recipe 20.8 - Within-host reproduction in a host-pathogen model.txt Sets up the initial monkey population, selects initial hosts for infection, assigns pathogen subpopulations, and creates a log file to record population sizes and other metrics over time. ```SLiM ticks all 1 early() { monkey.addSubpop("p1", K_MONKEY); // choose initial hosts carrying the infection initial_hosts = p1.sampleIndividuals(5, replace=F); pathogen.tag = 3; for (initial_host in initial_hosts) { // make a pathogen subpop for the host pathogen_subpop = pathogen.addSubpop(pathogen.tag, 1); pathogen_subpop.tag = initial_host.pedigreeID; pathogen.tag = pathogen.tag + 1; } // log some basic output logfile = community.createLogFile("host_pathogen_log.csv", logInterval=1); logfile.addTick(); logfile.addSubpopulationSize(p1); logfile.addPopulationSize(pathogen); logfile.addCustomColumn("host_count", "pathogen.subpopulations.size();"); logfile.addMeanSDColumns("monkeyAge", "p1.individuals.age;"); } ``` -------------------------------- ### Get Nucleotide Sequence within a Range Source: https://github.com/messerlab/slim/blob/master/QtSLiM/help/SLiMHelpClasses.html Returns a portion of the nucleotide sequence for the haplosome, constrained by the specified start and end positions. The format parameter controls the output type. ```SLiM nucleotides(start=100, end=200, format="string") ``` -------------------------------- ### Initial Population Setup and Logging Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 20.6 - A coevolutionary host-parasitoid trait-matching model.txt Sets up the initial subpopulations for hosts and parasitoids and creates a log file to record population sizes and trait means/SDs over time. ```SLiM ticks all 1 early() { host.addSubpop("p1", N0_host); parasitoid.addSubpop("p2", N0_parasitoid); log = community.createLogFile("host-parasite log.txt", logInterval=1); log.addTick(); log.addPopulationSize(host); log.addMeanSDColumns("host", "p1.individuals.tagF;"); log.addPopulationSize(parasitoid); log.addMeanSDColumns("parasitoid", "p2.individuals.tagF;"); } ``` -------------------------------- ### SLiM Initialization and Simulation Setup Source: https://github.com/messerlab/slim/blob/master/SLiMgui/Recipes/Recipe 12.4 - Suppressing hermaphroditic selfing.txt This snippet shows the basic initialization of SLiM, including mutation rate, genomic elements, and recombination rate, followed by the creation of a subpopulation. ```SLiM initialize() { initializeMutationRate(1e-7); initializeMutationType("m1", 0.5, "f", 0.0); initializeGenomicElementType("g1", m1, 1.0); initializeGenomicElement(g1, 0, 99999); initializeRecombinationRate(1e-8); } 1 early() { sim.addSubpop("p1", 500); } ``` -------------------------------- ### SLIM Recipe Initialization and Simulation Setup Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 18.4 - Detecting the dip in diversity (analyzing tree heights in Python) I.txt This snippet sets up the simulation parameters, including population size, chromosome length, mutation and recombination rates, genomic element types, and initializes the tree sequence output. It is used to configure the simulation environment for diversity analysis. ```SLIM initialize() { defineConstant("N", 10000); // pop size defineConstant("L", 1e8); // total chromosome length defineConstant("L0", 200e3); // between genes defineConstant("L1", 1e3); // gene length initializeTreeSeq(); initializeMutationRate(1e-7); initializeRecombinationRate(1e-8, L-1); initializeMutationType("m2", 0.5, "g", -(5/N), 1.0); initializeGenomicElementType("g2", m2, 1.0); for (start in seq(from=L0, to=L-(L0+L1), by=(L0+L1))) initializeGenomicElement(g2, start, (start+L1)-1); } 1 early() { sim.addSubpop("p1", N); } 10*N late() { sim.treeSeqOutput("./diversity.trees"); } ``` -------------------------------- ### SLiM Initialization and Mutation Setup Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 18.3 - Simulation conditional upon fixation of a sweep, preserving ancestry I.txt Sets up mutation rates, types (including deleterious and beneficial), genomic elements, and recombination rate. This is a prerequisite for running the simulation. ```slim initialize() { initializeMutationRate(1e-7); initializeMutationType("m1", 0.5, "f", 0.0); initializeMutationType("m2", 0.5, "g", -0.01, 1.0); // deleterious initializeMutationType("m3", 1.0, "f", 0.05); // introduced initializeGenomicElementType("g1", c(m1, m2), c(0.9, 0.1)); initializeGenomicElement(g1, 0, 99999); initializeRecombinationRate(1e-8); } ``` -------------------------------- ### Example Benchmark Runner Output Source: https://github.com/messerlab/slim/blob/master/simd_benchmarks/README.md Example output from the SIMD Benchmark Runner script, showing Eidos math function and SLiM simulation benchmark results. ```bash $ simd_benchmarks/run_benchmarks.sh ============================================ SIMD Benchmark Runner ============================================ SLiM root: /home/adkern/SLiM Runs per benchmark: 3 Building with SIMD enabled... Done. Building with SIMD disabled... Done. ============================================ Eidos Math Function Benchmarks ============================================ SIMD Build: Running Eidos benchmark (SIMD)... sqrt(): 0.105 sec abs(): 0.171 sec floor(): 0.164 sec ceil(): 0.166 sec round(): 0.164 sec trunc(): 0.165 sec sum(): 0.032 sec product(): 0.003 sec (1000 elements, 10000 iters) Scalar Build: Running Eidos benchmark (Scalar)... sqrt(): 0.108 sec abs(): 0.166 sec floor(): 0.231 sec ceil(): 0.246 sec round(): 0.473 sec trunc(): 0.246 sec sum(): 0.166 sec product(): 0.017 sec (1000 elements, 10000 iters) ============================================ SLiM Simulation Benchmark (N=5000, 5000 generations, selection) ============================================ Running 3 iterations each... SIMD Build: 12.756s (avg) Scalar Build: 12.316s (avg) Speedup: .96x ============================================ Benchmark complete ============================================ ``` -------------------------------- ### Initialize SLiM Options and Parameters Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 17.10 - A simple biogeographic landscape model.txt Sets up the simulation environment, including dimensionality, mutation rate, genomic elements, and interaction types for spatial competition and mate choice. ```SLiM initialize() { initializeSLiMOptions(dimensionality="xy"); initializeMutationRate(1e-7); initializeMutationType("m1", 0.5, "f", 0.0); initializeGenomicElementType("g1", m1, 1.0); initializeGenomicElement(g1, 0, 99999); initializeRecombinationRate(1e-8); // spatial competition initializeInteractionType(1, "xy", reciprocal=T, maxDistance=30.0); i1.setInteractionFunction("n", 5.0, 10.0); // spatial mate choice initializeInteractionType(2, "xy", reciprocal=T, maxDistance=30.0); i2.setInteractionFunction("n", 1.0, 10.0); } ``` -------------------------------- ### Early Simulation Setup and Logging Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 4.2.5 - Basic output, Automatic logging with LogFile.txt Sets up subpopulations, migration rates, and creates a log file to record simulation data, including a custom FST column. ```SLiM 1 early() { sim.addSubpop("p1", 1000); sim.addSubpop("p2", 1000); p1.setMigrationRates(p2, 0.001); p2.setMigrationRates(p1, 0.001); log = community.createLogFile("sim_log.txt", logInterval=10); log.addCycle(); log.addCustomColumn("FST", "calcFST(p1.haplosomes, p2.haplosomes);"); } ``` -------------------------------- ### MutationEffect Callback Example Source: https://github.com/messerlab/slim/blob/master/QtSLiM/help/SLiMHelpCallbacks.html A mutationEffect callback example that sets a neutral relative fitness (1.0) for mutations of type m2 in subpopulation p3 between ticks 1000 and 2000. This demonstrates spatial heterogeneity in selection. ```Eidos 1000:2000 mutationEffect(m2, p3) { 1.0; } ``` -------------------------------- ### Setup for Live Plotting Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 14.7 - Live plotting with R using system().txt Initializes a subpopulation and sets up a temporary file path for saving plot images. If running in SLiMgui, it opens the plot document. ```SLiM 1 early() { sim.addSubpop("p1", 5000); sim.setValue("fixed", NULL); defineConstant("pngPath", writeTempFile("plot_", ".png", "")); // If we're running in SLiM GUI, open a plot window if (exists("slimgui")) s slimgui.openDocument(pngPath); } ``` -------------------------------- ### Subpopulation First Male Index Property Source: https://github.com/messerlab/slim/blob/master/QtSLiM/help/SLiMHelpClasses.html Gets the index of the first male in the subpopulation. ```SLiM firstMaleIndex => (integer$) ``` -------------------------------- ### Initialize SLiM Simulation Parameters Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 17.11 - Local adaptation on a heterogeneous landscape map.txt Sets up the simulation environment, including dimensionality, mutation types, genomic elements, and interaction parameters for competition and mate choice. ```SLiM initialize() { defineConstant("SIGMA_C", 0.1); defineConstant("SIGMA_K", 0.5); defineConstant("SIGMA_M", 0.1); defineConstant("N", 500); initializeSLiMOptions(dimensionality="xyz"); initializeMutationRate(1e-6); initializeMutationType("m1", 0.5, "f", 0.0); // neutral initializeMutationType("m2", 0.5, "n", 0.0, 1.0); // QTL m2.convertToSubstitution = F; initializeGenomicElementType("g1", c(m1, m2), c(1, 0.1)); initializeGenomicElement(g1, 0, 1e5 - 1); initializeRecombinationRate(1e-8); // competition initializeInteractionType(1, "xyz", reciprocal=T, maxDistance=SIGMA_C * 3); i1.setInteractionFunction("n", 1.0, SIGMA_C); // mate choice initializeInteractionType(2, "xyz", reciprocal=T, maxDistance=SIGMA_M * 3); i2.setInteractionFunction("n", 1.0, SIGMA_M); } mutationEffect(m2) { return 1.0; } ``` -------------------------------- ### Get Maximum Available Threads Source: https://github.com/messerlab/slim/blob/master/QtSLiM/help/EidosHelpFunctions.html Returns the maximum number of threads that can be utilized by the system. ```C++ parallelGetMaxThreads() ``` -------------------------------- ### Initialize SLiM Simulation Options Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 17.3 - Boundaries and boundary conditions IV (reprising boundaries).txt Sets up the simulation environment for a 2D spatial model and defines mutation parameters. ```SLiM initialize() { initializeSLiMOptions(dimensionality="xy"); initializeMutationRate(1e-7); initializeMutationType("m1", 0.5, "f", 0.0); initializeGenomicElementType("g1", m1, 1.0); initializeGenomicElement(g1, 0, 99999); initializeRecombinationRate(1e-8); initializeInteractionType(1, "xy", reciprocal=T, maxDistance=0.3); // competition i1.setInteractionFunction("n", 3.0, 0.1); } ``` -------------------------------- ### Get Length of a Value Source: https://github.com/messerlab/slim/blob/master/QtSLiM/help/EidosHelpFunctions.html Returns the length of a given value (e.g., a vector or list). ```Eidos length(x) ``` -------------------------------- ### Initialize Subpopulations and Logging Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 20.7 - A coevolutionary host-parasite matching-allele model.txt Sets up the initial subpopulations for host and parasite, creates a log file, and adds custom columns to track nucleotide frequencies. ```SLiM ticks all 1 early() { host.addSubpop("p0", 1000); parasite.addSubpop("p1", 1000); log = community.createLogFile("host-parasite log.txt", logInterval=1); log.addTick(); log.addCustomColumn("hA", "nucleotideFreq(host, 'A');"); log.addCustomColumn("hC", "nucleotideFreq(host, 'C');"); log.addCustomColumn("hG", "nucleotideFreq(host, 'G');"); log.addCustomColumn("hT", "nucleotideFreq(host, 'T');"); log.addCustomColumn("pA", "nucleotideFreq(parasite, 'A');"); log.addCustomColumn("pC", "nucleotideFreq(parasite, 'C');"); log.addCustomColumn("pG", "nucleotideFreq(parasite, 'G');"); log.addCustomColumn("pT", "nucleotideFreq(parasite, 'T');"); } ``` -------------------------------- ### Initialize Population Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 13.4 - A quantitative genetics model with heritability.txt Adds a subpopulation named 'p1' with 1000 individuals at the start of the simulation. ```slim 1 late() { sim.addSubpop("p1", 1000); } ``` -------------------------------- ### Early Stage: Setup and Initial Population Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 14.13 - Modeling biallelic loci with a mutation() callback I.txt Creates the initial population, defines canonical mutation objects for 'm2' and 'm3', and sets the population to be homozygous for the 'm3' allele at all positions. Sets up logging for mutation frequencies. ```slim 1 early() { sim.addSubpop("p1", 100); // create the canonical mutation objects target = p1.haplosomes[0]; target.addNewDrawnMutation(m2, 0:99); defineConstant("MUT2", target.mutations); target.removeMutations(); target.addNewDrawnMutation(m3, 0:99); defineConstant("MUT3", target.mutations); target.removeMutations(); // start homozygous "aa" at every position p1.haplosomes.addMutations(MUT3); // log results log = community.createLogFile("freq.csv", logInterval=10); log.addTick(); log.addMeanSDColumns("freq", "sim.mutationFrequencies(NULL, MUT2);"); } ``` -------------------------------- ### Build SLiMgui Option Source: https://github.com/messerlab/slim/blob/master/CMakeLists.txt Option to build the Qt-based GUI for SLiM. This requires Qt to be installed. ```cmake option(BUILD_SLIMGUI "Build the Qt-based GUI for SLiM" OFF) ``` -------------------------------- ### Mutation Callback Example (No Restriction) Source: https://github.com/messerlab/slim/blob/master/QtSLiM/help/SLiMHelpCallbacks.html A basic mutation callback that is called for every auto-generated mutation. ```SLiM mutation() { ... } ``` -------------------------------- ### Initial Population Setup Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 16.8 - Modeling haplodiploidy with addRecombinant().txt Creates the initial subpopulations for males (haploid) and females (diploid) and migrates males into the female subpopulation. It also removes the now-empty male subpopulation. ```SLiM 1 early() { // make an initial population with the right genetics mCount = asInteger(K * P_OFFSPRING_MALE); fCount = K - mCount; sim.addSubpop("p1", mCount, sexRatio=1.0, haploid=T); // males sim.addSubpop("p2", fCount, sexRatio=0.0, haploid=F); // females p1.takeMigrants(p2.individuals); p2.removeSubpopulation(); } ``` -------------------------------- ### Add Subpopulation Source: https://github.com/messerlab/slim/blob/master/SLiMgui/Recipes/Recipe 14.2 - Mortality-based fitness I.txt Adds an initial subpopulation named 'p1' with 500 individuals at the start of the simulation. ```SLiM sim.addSubpop("p1", 500); ``` -------------------------------- ### Set Up Early Population Structure Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 9.7 - Adaptive introgression.txt Defines the number of subpopulations and migration rates between them at the start of the simulation. ```SLiM 1 early() { subpopCount = 10; for (i in 1:subpopCount) sim.addSubpop(i, 500); for (i in 2:subpopCount) sim.subpopulations[i-1].setMigrationRates(i-1, 0.01); for (i in 1:(subpopCount-1)) sim.subpopulations[i-1].setMigrationRates(i+1, 0.2); } ``` -------------------------------- ### Initialize Simulation Environment Source: https://github.com/messerlab/slim/blob/master/SLiMgui/Recipes/Recipe 6.4 - Genomic structure, Part IV (Custom display colors in SLiMgui).txt Sets up the initial simulation environment by clearing chromosome color substitutions and adding a subpopulation. This is typically done at the beginning of a simulation. ```SLiM 1 early() { sim.chromosomes.colorSubstitution = ""; sim.addSubpop("p1", 5000); } ``` -------------------------------- ### Initialize Population Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 9.5.1 - A soft sweep from recurrent de novo mutations in a large population.txt Creates the primary subpopulation 'p1' with a size of 100,000 individuals at the start of the simulation. ```SLiM sim.addSubpop("p1", 100000); ``` -------------------------------- ### SLiM Early Stage Population Setup Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 18.3 - Simulation conditional upon fixation of a sweep, preserving ancestry I.txt Initializes the simulation ID using the random seed and sets up the initial population size. This runs at the beginning of the simulation. ```slim 1 early() { defineConstant("simID", getSeed()); sim.addSubpop("p1", 500); } ``` -------------------------------- ### Initialize SLiM Simulation Parameters Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 19.14 - Modeling identity by state (IBS) (uniquing mutations with a mutation() callback).txt Sets up the simulation environment, including nucleotide-based operations, ancestral nucleotides, mutation types, genomic elements, and recombination rates. ```slim initialize() { initializeSLiMOptions(nucleotideBased=T); initializeAncestralNucleotides(randomNucleotides(100)); initializeMutationTypeNuc("m1", 0.5, "f", 0.0); initializeGenomicElementType("g1", m1, 1.0, mmJukesCantor(1e-4 / 3)); initializeGenomicElement(g1, 0, 99); initializeRecombinationRate(1e-3); } ``` -------------------------------- ### Mutation Callback Example (Specific Subpopulation) Source: https://github.com/messerlab/slim/blob/master/QtSLiM/help/SLiMHelpCallbacks.html A mutation callback restricted to mutations originating from a specific subpopulation. ```SLiM mutation(, p1) { ... } ``` -------------------------------- ### Mutation Callback Example (Specific Mutation Type) Source: https://github.com/messerlab/slim/blob/master/QtSLiM/help/SLiMHelpCallbacks.html A mutation callback restricted to a specific mutation type. ```SLiM mutation(m1) { ... } ``` -------------------------------- ### Initialize SLiM Options and Parameters Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 17.3 - Boundaries and boundary conditions I (stopping boundaries).txt Sets up the simulation environment, including dimensionality, mutation rate, genomic elements, and recombination rate. It also defines interaction types and their spatial functions. ```SLiM initializeSLiMOptions(dimensionality="xy"); initializeMutationRate(1e-7); initializeMutationType("m1", 0.5, "f", 0.0); initializeGenomicElementType("g1", m1, 1.0); initializeGenomicElement(g1, 0, 99999); initializeRecombinationRate(1e-8); initializeInteractionType(1, "xy", reciprocal=T, maxDistance=0.3); // competition i1.setInteractionFunction("n", 3.0, 0.1); ``` -------------------------------- ### Return statement example in SLiM context Source: https://github.com/messerlab/slim/blob/master/QtSLiM/help/EidosHelpStatements.html Demonstrates the use of the return statement to break out of nested loops. ```Eidos return 5; ``` -------------------------------- ### Initial Population Setup Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 16.3 - Modeling clonal haploid bacteria with horizontal gene transfer.txt Sets up the initial population with two individuals and introduces distinct beneficial mutations at specific genomic locations. This is part of the early simulation phase. ```SLiM 1 early() { // start from two bacteria with different beneficial mutations sim.addSubpop("p1", 2); h = p1.individuals.haplosomes; h[0].addNewDrawnMutation(m2, asInteger(L * 0.25)); h[1].addNewDrawnMutation(m2, asInteger(L * 0.75)); } ``` -------------------------------- ### Add Subpopulation and Start Simulation Source: https://github.com/messerlab/slim/blob/master/SLiMgui/Recipes/Recipe 8.1.2 - Reproduction, Sex ratios I.txt Adds an initial subpopulation to the simulation and defines the point at which the simulation should end. ```SLiM 1 early() { sim.addSubpop("p1", 500, 0.6); } 10000 early() { sim.simulationFinished(); } ``` -------------------------------- ### Initialize Population and Simulation End Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 6.4 - Genomic structure, Part IV (Custom display colors in SLiMgui).txt Sets up the initial population for the simulation and defines the condition for the simulation to finish. The color substitution for chromosomes is cleared to ensure default display behavior. ```SLiM 1 early() { sim.chromosomes.colorSubstitution = ""; sim.addSubpop("p1", 5000); } 10000 early() { sim.simulationFinished(); } ``` -------------------------------- ### Initialize SLiM Model Parameters Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 13.4 - A quantitative genetics model with heritability.txt Sets up the simulation environment, including heritability, mutation rates, mutation types (neutral and QTL), genomic elements, and recombination rate. ```slim initialize() { defineConstant("h2", 0.1); // target heritability initializeMutationRate(1e-6); initializeMutationType("m1", 0.5, "f", 0.0); // neutral initializeMutationType("m2", 0.5, "n", 0.0, 1.0); // QTL m2.convertToSubstitution = F; initializeGenomicElementType("g1", c(m1, m2), c(1, 0.01)); initializeGenomicElement(g1, 0, 1e5 - 1); initializeRecombinationRate(1e-8); } ``` -------------------------------- ### Initialize SLiM Model and Constants Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 15.8 - Evolutionary rescue after environmental change.txt Sets up the simulation environment, defines constants for population size, environmental optima, and change time, and initializes mutation types, genomic elements, and basic evolutionary parameters. ```SLiM initialize() { initializeSLiMModelType("nonWF"); defineConstant("K", 500); defineConstant("opt1", 0.0); defineConstant("opt2", 10.0); defineConstant("Tdelta", 10000); initializeMutationType("m1", 0.5, "n", 0.0, 1.0); // QTL initializeGenomicElementType("g1", m1, 1.0); initializeGenomicElement(g1, 0, 99999); initializeMutationRate(1e-7); initializeRecombinationRate(1e-8); } ``` -------------------------------- ### Mutation Callback Example (Specific Type and Subpopulation) Source: https://github.com/messerlab/slim/blob/master/QtSLiM/help/SLiMHelpCallbacks.html A mutation callback restricted to a specific mutation type and subpopulation. ```SLiM mutation(m1, p1) { ... } ``` -------------------------------- ### Initialization and Spatial Setup Source: https://github.com/messerlab/slim/blob/master/SLiMgui/Recipes/Recipe 17.3 - Boundaries and boundary conditions I (stopping boundaries).txt Initializes SLiM options, mutation, genomic elements, recombination, and interaction types for a 2D spatial simulation. Sets up the initial population with random spatial positions. ```slim initialize() { initializeSLiMOptions(dimensionality="xy"); initializeMutationRate(1e-7); initializeMutationType("m1", 0.5, "f", 0.0); initializeGenomicElementType("g1", m1, 1.0); initializeGenomicElement(g1, 0, 99999); initializeRecombinationRate(1e-8); initializeInteractionType(1, "xy", reciprocal=T, maxDistance=0.3); // competition i1.setInteractionFunction("n", 3.0, 0.1); } 1 late() { sim.addSubpop("p1", 500); // Initial positions are random within spatialBounds p1.individuals.setSpatialPosition(p1.pointUniform(500)); } 1: late() { i1.evaluate(p1); } ``` -------------------------------- ### Block comment example Source: https://github.com/messerlab/slim/blob/master/QtSLiM/help/EidosHelpStatements.html Shows how to use block comments delimited by '/*' and '*/' for multi-line comments or code disabling. ```Eidos /* This computes the factorial x!, which is the product of all values from 1 to x, for any positive integer x. */ x_factorial = product(1:x); ``` -------------------------------- ### For Loop for Calculating Squares Source: https://github.com/messerlab/slim/blob/master/QtSLiM/help/EidosHelpStatements.html Iterates through a sequence of numbers and prints the square of each element. This is an example of a 'for each' style loop. ```Eidos > my_sequence = 1:4; for (element in my_sequence) print("The square of " + element + " is " + element^2); ``` -------------------------------- ### SLiM Logging Setup Source: https://github.com/messerlab/slim/blob/master/QtSLiM/recipes/Recipe 15.13 - Range expansion in a stepping-stone model I.txt Configures a log file to record simulation progress. It logs cycle number, population size, mean and standard deviation of population size, and migrant counts. ```SLiM 1 late() { // set up a log file log = community.createLogFile("sim_log.txt", sep="\t", logInterval=10); log.addCycle(); log.addPopulationSize(); log.addMeanSDColumns("size", "sim.subpopulations.individualCount;"); log.addCustomColumn("pop_migrants", "sum(sim.subpopulations.individuals.migrant);"); log.addMeanSDColumns("migrants", "sapply(sim.subpopulations, 'sum(applyValue.individuals.migrant);');"); } ``` -------------------------------- ### Eidos if Statement Example Source: https://github.com/messerlab/slim/blob/master/QtSLiM/help/EidosHelpStatements.html Demonstrates a simple if statement with a condition that evaluates to true. The condition must be a scalar value. ```Eidos if (2^2^2^2^2 > 10000) "exponentiation is da bomb!" ```