I am simulating long-term inbreeding using SLiM’s non-Wright-Fisher model. The goal is to track the effects of extreme inbreeding over 100 generations and generate complete chromosome 1 sequences in VCF format for downstream analysis in PLINK.
Simulation DesignMutations and Positioning Issues
Tree Sequence to VCF Conversion Issues
Reproduction and Population Structure Errors
--
SLiM forward genetic simulation: http://messerlab.org/slim/
---
You received this message because you are subscribed to the Google Groups "slim-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to slim-discuss...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/slim-discuss/40903448-d143-436f-ae8c-e28bac4fa06bn%40googlegroups.com.
outputVCFSample()
to generate VCF files for the consanguineous individual and all its descendants (but not the entire population). However, I'm encountering the following error:+ "with open('" + filename + ".vcf', 'w') as vcf_[file:\n]file:\n"
+ " ts.write_vcf(vcf_file, position_transform=lambda x: max(1, int(x)))\n";
// Save the script to a file in the system
writeFile(python_script, script_content);
// Execute the script
system("python3 " + python_script);
}
}
}
}
Could you help me to fix it????
Hi Ben,
Thank you very much! I’ll take a step back and revisit the basics as you suggested. To be honest, I didn’t attend the SLiM workshop, so that’s probably a good place to start. I really appreciate your advice!
Best regards,
Francisco
Dear Ben,
Thank you for all your suggestions! I thoroughly reviewed the SLiM materials and successfully completed the script.
However, I’ve encountered a problem that I haven’t been able to resolve on my own. I managed to fix all previous issues, but now, when I try to run the simulation, it gets killed due to insufficient memory (a typical OOM error). I have allocated 48 GB of RAM and 32 GB of swap to my WSL2 environment, but it’s still not enough.
I am simulating 300K SNPs on chromosome 1 over 100 generations, and I believe I need to make my script more memory-efficient.
Could you provide any advice on optimizing it? Here is my script:
// Step 1: Initialize the model and parameters
initialize() {
initializeSLiMModelType("nonWF");
defineConstant("VCF_INTERVAL", 50);
defineConstant("TOTAL_GENERATIONS", 100);
defineConstant("CHROMOSOME_LENGTH", 248956422);
defineConstant("NUM_INITIAL_SNPS", 300000);
// Define population names and sizes
defineConstant("POPULATION_IDS", c("p3", "p4", "p5"));
defineConstant("POPULATION_SIZES", c(10));
// Mutation and recombination settings
initializeMutationRate(1e-8);
initializeMutationType("m1", 0.5, "f", 0);
initializeGenomicElementType("g1", m1, 1.0);
initializeGenomicElement(g1, 0, CHROMOSOME_LENGTH - 1);
initializeRecombinationRate(1e-8);
}
// Step 2: Create the initial population and introduce 300K SNPs efficiently
1 early() {
sim.addSubpop("p1", 2); // Create a population with two individuals (siblings)
positions = asInteger(runif(NUM_INITIAL_SNPS, 1, CHROMOSOME_LENGTH));
for (pos in positions) {
p1.individuals.genomes.addNewMutation(m1, pos, 0);
}
// Create a subpopulation for inbred descendants
sim.addSubpop("p2", 0);
}
// Step 3: Generate the inbred descendant through forced reproduction
2:2 reproduction(p1) {
inds = p1.individuals;
brother1 = inds[0];
brother2 = inds[1];
// Mate the siblings and add their descendant to subpopulation p2
p2.addCrossed(brother1, brother2);
}
// Step 4: Create populations of different sizes and migrate the inbred descendant
3 early() {
for (i in 0:(size(POPULATION_IDS) - 1)) {
pop_name = POPULATION_IDS[i];
pop_size = POPULATION_SIZES[i];
sim.addSubpop(pop_name, pop_size);
// Transfer only a limited number of inbred descendants
if (p2.individualCount > 0) {
migrating_inds = sample(p2.individuals, min(10, p2.individualCount), replace=F);
sim.subpopulations[i + 2].takeMigrants(migrating_inds);
}
}
}
// Step 5: Control reproduction to prevent excessive growth
4:TOTAL_GENERATIONS reproduction() {
for (i in 0:(size(POPULATION_IDS) - 1)) {
pop = sim.subpopulations[i + 2]; // p3, p4, p5
target_size = POPULATION_SIZES[i];
// If the population has reached its target size, stop reproduction
if (pop.individualCount >= target_size) {
next;
}
inds = pop.individuals;
num_offspring = min(asInteger(pop.individualCount / 2), target_size - pop.individualCount);
for (j in seqLen(num_offspring)) {
parent1 = inds[asInteger(runif(1, 0, size(inds)))];
parent2 = inds[asInteger(runif(1, 0, size(inds)))];
if (parent1 != parent2) {
pop.addCrossed(parent1, parent2);
}
}
}
}
// Step 6: Efficient VCF Export (single file)
4:TOTAL_GENERATIONS late() {
// Export VCF every 100 generations
if (sim.cycle % VCF_INTERVAL == 0) {
all_inds = c();
for (pop in sim.subpopulations) {
all_inds = c(all_inds, pop.individuals);
}
// Single file export for all individuals
sim.outputVCF(filePath="/home/rembukai/BIOSOFT/SIMULATIONS/VCF/combined_output.vcf");
}
}
Best regards,
Francisco.To view this discussion visit https://groups.google.com/d/msgid/slim-discuss/72dce80d-f3c3-4392-9269-9c086f5f3d84n%40googlegroups.com.