initialize() {
if (exists("slimgui")) {
defineConstant("IGC_RATE", 2.5e-7);
defineConstant("alpha", 1.3e-8/3);
defineConstant("SD_len", 10000);
defineConstant("N", 15000);
defineConstant("IGC", T);
defineConstant("GEN", 300000);
defineConstant("SEED", 1);
}
if (!exists("IGC_RATE")) defineConstant("IGC_RATE", 2.5e-7);
if (!exists("alpha")) defineConstant("alpha", 1.3e-8/3);
if (!exists("SD_len")) defineConstant("SD_len", 10000);
if (!exists("N")) defineConstant("N", 15000);
if (!exists("IGC")) defineConstant("IGC", T);
if (!exists("GEN")) defineConstant("GEN", 300000);
if (!exists("SEED")) defineConstant("SEED", 1);
initializeSLiMModelType("WF");
initializeSLiMOptions(nucleotideBased=T);
setSeed(SEED);
initializeMutationTypeNuc("m1", 0.5, "n", 0.0, 0.001); // may need to be changed
initializeMutationTypeNuc("m0", 0.5, "f", 0.0);
initializeGenomicElementType("g1", c(m0, m1), c(0.8, 0.2), mmJukesCantor(alpha));
initializeGenomicElementType("g0", m0, 1, mmJukesCantor(alpha));
initializeGenomicElement(g0, 0, SD_len-1);
initializeGenomicElement(g1, SD_len, 2*SD_len-1);
initializeGenomicElement(g0, 2*SD_len, 3*SD_len-1);
initializeGenomicElement(g1, 3*SD_len, 4*SD_len-1);
initializeGenomicElement(g0, 4*SD_len, 5*SD_len-1);
sd = randomNucleotides(SD_len);
seq = randomNucleotides(SD_len) + sd + randomNucleotides(SD_len) + sd + randomNucleotides(SD_len);
initializeAncestralNucleotides(seq);
initializeRecombinationRate(1.2e-8);
}
1 early() {
sim.addSubpop("p1", N);
sim.setValue("next_mut_time", 1);
if (IGC) {
catn("Using IGC");
} else {
catn("Using no IGC");
}
}
1:GEN late() {
if (sim.cycle % 10000 == 0) {
catn("Generation: " + sim.cycle + " / " + GEN);
}
if (IGC) {
// catn("next_mut_time = " + sim.getValue("next_mut_time"));
if (sim.cycle == sim.getValue("next_mut_time")) {
if (runif(1) < IGC_RATE/(IGC_RATE + alpha*3)) {
// catn("IGC happening at t = " + sim.cycle);
// sample a haplotype
ind = p1.sampleIndividuals(1); // To check
hap = ifelse(runif(1) < 0.5, ind.haploidGenome1, ind.haploidGenome2);
igc_tract_len = rgeom(1, 1/250); // Harpak et al., PNAS 2017
left_tract_len = runif(1) * igc_tract_len;
right_tract_len = igc_tract_len - left_tract_len;
mid_coord = round(runif(1, SD_len + left_tract_len + 1, 2*SD_len - right_tract_len - 1)); // make sure IGC tract inside the SD
donor_start = asInteger(SD_len + mid_coord - left_tract_len - 1);
donor_end = asInteger(SD_len + mid_coord + right_tract_len - 1);
acceptor_start = asInteger(3*SD_len + mid_coord - left_tract_len - 1);
acceptor_end = asInteger(3*SD_len + mid_coord + right_tract_len - 1);
genome = hap.nucleotides(format="char");
// choose acceptor paralog
if (runif(1) < 0.5) {
// first paralog is acceptor
genome[donor_start:donor_end] = genome[acceptor_start:acceptor_end];
} else {
// swap donor and acceptor
genome[acceptor_start:acceptor_end] = genome[donor_start:donor_end];
}
}
// next time point igc will happens
sim.setValue("next_mut_time", asInteger(round(sim.getValue("next_mut_time") +
rexp(1, p1.individualCount * 2 * 2 * SD_len * (IGC_RATE + alpha*3)))) + 1);
}
}
}
GEN+1 late() {
date = date();
muts = sim.mutations;
// Count fixed mutations
N_m1_fixed = size(sim.substitutions[sim.substitutions.mutationType == m1]);
catn("Number of fixed mutations with non zero selection coefficient: " + N_m1_fixed);
N_m0_fixed = size(sim.substitutions[sim.substitutions.mutationType == m0]);
catn("Number of fixed mutations with zero selection coefficient: " + N_m0_fixed);
// save selection coef and origin tick
file = "../../result/sim_result/" + date + "_muts_data_s" + SEED + ".csv";
writeFile(file, "Position,SelectionCoeff,OriginTick\n"); // Write header
for (mut in muts) {
line = mut.position + 1 + "," + mut.selectionCoeff + "," + mut.originTick; // position + 1 to match position in vcf
writeFile(file, line, append=T);
}
catn("Mutation data saved to " + file);
// save vcf
if (IGC) {
vcf_path = "../../result/sim_result/" + date + "_sim_igc_s" + SEED + ".vcf";
} else {
vcf_path = "../../result/sim_result/" + date + "_sim_noigc_s" + SEED + ".vcf";
}
p1.haplosomes.outputHaplosomesToVCF(vcf_path);
catn("VCF saved to " + vcf_path);
}
--
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/5a0baef1-b8ae-430e-81e3-f9a8a44eb43bn%40googlegroups.com.
--
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/baa4f1e8-23b1-45bf-931d-551b7ba63e65n%40googlegroups.com.