|
| 1 | +// Keywords: linkage disequilibrium, LD, custom plotting, recombination, calcLD |
| 2 | + |
| 3 | +initialize() |
| 4 | +{ |
| 5 | + setSeed(2180149919968428688); |
| 6 | + defineConstant("L", 1e7); |
| 7 | + initializeMutationRate(1e-7); |
| 8 | + initializeMutationType("m1", 0.5, "f", 0.0); |
| 9 | + initializeMutationType("m2", 1.0, "f", 0.1).color="red"; // used for MUT1 |
| 10 | + initializeGenomicElementType("g1", m1, 1.0); |
| 11 | + initializeGenomicElement(g1, 0, L-1); |
| 12 | + initializeRecombinationRate(1e-8); |
| 13 | +} |
| 14 | +1 early() |
| 15 | +{ |
| 16 | + sim.addSubpop("p1", 1000); |
| 17 | +} |
| 18 | +5000 late() |
| 19 | +{ |
| 20 | + // create the MUT1 mutation that we will track over time |
| 21 | + mut1 = sample(p1.haplosomes, 1).addNewDrawnMutation(m2, asInteger(L/2)); |
| 22 | + defineGlobal("MUT1", mut1); |
| 23 | +} |
| 24 | + |
| 25 | +5000:10000 late() |
| 26 | +{ |
| 27 | + allMutsMAF = sim.mutations[sim.mutationFrequencies(p1) >= 0.10]; |
| 28 | + muts = sortBy(allMutsMAF, "position"); |
| 29 | + |
| 30 | + if (size(muts) == 0) |
| 31 | + return; |
| 32 | + if (!MUT1.isSegregating) |
| 33 | + { |
| 34 | + catn("The focal mutation fixed or was lost."); |
| 35 | + sim.simulationFinished(); |
| 36 | + return; |
| 37 | + } |
| 38 | + |
| 39 | + ld = calcLD_D(MUT1, muts) * 10; // scale up to make it more visible |
| 40 | + r = calcLD_Rsquared(MUT1, muts, squared=F); |
| 41 | + r2 = calcLD_Rsquared(MUT1, muts); |
| 42 | + p = muts.position; |
| 43 | + |
| 44 | + plot = slimgui.createPlot("LD versus R2", xrange=c(0,L-1), yrange=c(-1,1), |
| 45 | + xlab="tick", ylab="metric", width=800, height=300); |
| 46 | + plot.abline(v=MUT1.position, color="red", lwd=2); |
| 47 | + plot.points(p, ld, symbol=16, color="cornflowerblue", size=0.5, alpha=0.1); |
| 48 | + plot.points(p, r, symbol=16, color="chartreuse3", size=0.5, alpha=0.1); |
| 49 | + plot.points(p, r2, symbol=16, color="black", size=0.5, alpha=0.1); |
| 50 | + |
| 51 | + f = rep(1/201, 201); // running average filter, 201 mutations wide |
| 52 | + plot.lines(p, filter(ld, f, outside=T), color="cornflowerblue", lwd=2); |
| 53 | + plot.lines(p, filter(r, f, outside=T), color="chartreuse3", lwd=2); |
| 54 | + plot.lines(p, filter(r2, f, outside=T), color="black", lwd=2); |
| 55 | + |
| 56 | + plot.addLegend("topRight"); |
| 57 | + plot.legendPointEntry("R2", symbol=16, color="black", size=0.5); |
| 58 | + plot.legendPointEntry("R", symbol=16, color="chartreuse3", size=0.5); |
| 59 | + plot.legendPointEntry("LD*10", symbol=16, color="cornflowerblue", size=0.5); |
| 60 | +} |
0 commit comments