Skip to content

Commit

Permalink
add terminology autofixes, revise recipes and cal...() functions
Browse files Browse the repository at this point in the history
  • Loading branch information
bhaller committed Sep 12, 2024
1 parent 8a31c4c commit bd4038a
Show file tree
Hide file tree
Showing 122 changed files with 494 additions and 367 deletions.
190 changes: 157 additions & 33 deletions QtSLiM/QtSLiMWindow.cpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion QtSLiM/recipes.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<file>recipes/Recipe 4.1 - A basic neutral simulation.txt</file>
<file>recipes/Recipe 4.2.1 - Basic output, Entire population.txt</file>
<file>recipes/Recipe 4.2.2 - Basic output, Random population sample.txt</file>
<file>recipes/Recipe 4.2.3 - Basic output, Sampling individuals rather than genomes.txt</file>
<file>recipes/Recipe 4.2.3 - Basic output, Sampling individuals rather than haplosomes.txt</file>
<file>recipes/Recipe 4.2.4 - Basic output, Substitutions.txt</file>
<file>recipes/Recipe 4.2.5 - Basic output, Automatic logging with LogFile.txt</file>
<file>recipes/Recipe 4.2.6 - Basic output, Custom output with Eidos.txt</file>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ initialize() {
1 early() { sim.addSubpop("p1", 500); }
10000 early() { sim.simulationFinished(); }
mutationEffect(m3) {
if (individual.genome1.countOfMutationsOfType(m2))
if (individual.haplosomesFromParent1.countOfMutationsOfType(m2))
return 0.5;
else if (individual.genome2.countOfMutationsOfType(m2))
else if (individual.haplosomesFromParent2.countOfMutationsOfType(m2))
return 0.5;
else
return effect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ initialize() {
1 early() { sim.addSubpop("p1", 500); }
10000 early() { sim.simulationFinished(); }
mutationEffect(m3) {
if (individual.genome1.countOfMutationsOfType(m2))
if (individual.haplosomesFromParent1.countOfMutationsOfType(m2))
return 0.5;
else if (individual.genome2.countOfMutationsOfType(m2))
else if (individual.haplosomesFromParent2.countOfMutationsOfType(m2))
return 0.5;
else
return effect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ initialize() {
}
1 early() { sim.addSubpop("p1", 500); }
1 late() {
target = sample(p1.genomes, 100);
target = sample(p1.haplosomes, 100);
target.addNewDrawnMutation(m2, 10000);
}
1: late() {
Expand Down
4 changes: 2 additions & 2 deletions QtSLiM/recipes/Recipe 11.1 - Assortative mating.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ initialize() {
p2.setMigrationRates(p1, 0.1);
}
1000 late() {
target = sample(p1.genomes, 1);
target = sample(p1.haplosomes, 1);
target.addNewDrawnMutation(m2, 10000);
}
mutationEffect(m2, p2) { return 0.2; }
Expand All @@ -40,7 +40,7 @@ mutationEffect(m2, p2) { return 0.2; }
return weights * sourceSubpop.getValue("weights2");
}
10000: late() {
FST = calcFST(p1.genomes, p2.genomes);
FST = calcFST(p1.haplosomes, p2.haplosomes);
sim.setValue("FST", sim.getValue("FST") + FST);
}
19999 late() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ initialize() {
cat("m2 mutation count: " + sim.countOfMutationsOfType(m2) + "\n");
}
modifyChild(p1) {
pollenSMuts = child.genome2.mutationsOfType(m2);
styleSMuts1 = parent1.genome1.mutationsOfType(m2);
styleSMuts2 = parent1.genome2.mutationsOfType(m2);
pollenSMuts = child.haplosomesFromParent2.mutationsOfType(m2);
styleSMuts1 = parent1.haplosomesFromParent1.mutationsOfType(m2);
styleSMuts2 = parent1.haplosomesFromParent2.mutationsOfType(m2);
if (identical(pollenSMuts, styleSMuts1))
if (runif(1) < 0.99)
return F;
Expand Down
8 changes: 4 additions & 4 deletions QtSLiM/recipes/Recipe 12.2 - Lethal epistasis I.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ initialize() {
sim.addSubpop("p1", 500);
}
1 late() {
sample(p1.genomes, 20).addNewDrawnMutation(m2, 10000); // add A
sample(p1.genomes, 20).addNewDrawnMutation(m3, 20000); // add B
sample(p1.haplosomes, 20).addNewDrawnMutation(m2, 10000); // add A
sample(p1.haplosomes, 20).addNewDrawnMutation(m3, 20000); // add B
}
modifyChild() {
hasMutA = any(child.genomes.countOfMutationsOfType(m2) > 0);
hasMutB = any(child.genomes.countOfMutationsOfType(m3) > 0);
hasMutA = any(child.haplosomes.countOfMutationsOfType(m2) > 0);
hasMutB = any(child.haplosomes.countOfMutationsOfType(m3) > 0);
if (hasMutA & hasMutB)
return F;
return T;
Expand Down
8 changes: 4 additions & 4 deletions QtSLiM/recipes/Recipe 12.2 - Lethal epistasis II.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ initialize() {
sim.addSubpop("p1", 500);
}
1 late() {
sample(p1.genomes, 20).addNewDrawnMutation(m2, 10000); // add A
sample(p1.genomes, 20).addNewDrawnMutation(m3, 20000); // add B
sample(p1.haplosomes, 20).addNewDrawnMutation(m2, 10000); // add A
sample(p1.haplosomes, 20).addNewDrawnMutation(m3, 20000); // add B
}
modifyChild() {
mutACount = sum(child.genomes.countOfMutationsOfType(m2));
mutBCount = sum(child.genomes.countOfMutationsOfType(m3));
mutACount = sum(child.haplosomes.countOfMutationsOfType(m2));
mutBCount = sum(child.haplosomes.countOfMutationsOfType(m3));
if ((mutACount == 2) & (mutBCount == 2))
return F;
return T;
Expand Down
10 changes: 5 additions & 5 deletions QtSLiM/recipes/Recipe 12.3 - Simulating gene drive.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ initialize() {
sim.subpopulations[i].setMigrationRates(i+1, 0.1);
}
100 late() {
p0.genomes[0:49].addNewDrawnMutation(m2, 10000);
p0.haplosomes[0:49].addNewDrawnMutation(m2, 10000);
}
100:10000 late() {
if (sim.countOfMutationsOfType(m2) == 0)
Expand All @@ -34,12 +34,12 @@ mutationEffect(m2) {
mut = sim.mutationsOfType(m2);
if (size(mut) == 1)
{
hasMutOnChromosome1 = child.genome1.containsMutations(mut);
hasMutOnChromosome2 = child.genome2.containsMutations(mut);
hasMutOnChromosome1 = child.haplosomesFromParent1.containsMutations(mut);
hasMutOnChromosome2 = child.haplosomesFromParent2.containsMutations(mut);
if (hasMutOnChromosome1 & !hasMutOnChromosome2)
child.genome2.addMutations(mut);
child.haplosomesFromParent2.addMutations(mut);
else if (hasMutOnChromosome2 & !hasMutOnChromosome1)
child.genome1.addMutations(mut);
child.haplosomesFromParent1.addMutations(mut);
}
return T;
}
2 changes: 1 addition & 1 deletion QtSLiM/recipes/Recipe 13.1 - Polygenic selection.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ initialize() {
}
1 early() { sim.addSubpop("p1", 500); }
fitnessEffect() {
phenotype = sum(individual.genomes.countOfMutationsOfType(m2));
phenotype = sum(individual.haplosomes.countOfMutationsOfType(m2));
return 1.5 - (phenotype - 10.0)^2 * 0.005;
}
5000 late() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ initialize() {
community.registerEarlyEvent("s2", s1.source, 2, 2);

// optional: give m2 mutations to everyone, as standing variation
g = sim.subpopulations.genomes;
g = sim.subpopulations.haplosomes;

for (q in Q)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ late() {
for (ind in sim.subpopulations.individuals)
{
// construct phenotypes from additive effects of QTL mutations
muts = ind.genomes.mutationsOfType(m2);
muts = ind.haplosomes.mutationsOfType(m2);
phenotype0 = size(muts) ? sum(muts.getValue("e0")) else 0.0;
phenotype1 = size(muts) ? sum(muts.getValue("e1")) else 0.0;
ind.setValue("phenotype0", phenotype0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ mateChoice() {
}
1000 late() {
// Print mean heterozygosity across the population
heterozygosity = calcHeterozygosity(p1.genomes);
heterozygosity = calcHeterozygosity(p1.haplosomes);
cat("Mean heterozygosity = " + heterozygosity + "\n");
}
16 changes: 8 additions & 8 deletions QtSLiM/recipes/Recipe 14.11 - Modeling microsatellites.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ initialize() {
sim.addSubpop("p1", 500);

// create some microsatellites at random positions
genomes = sim.subpopulations.genomes;
haplosomes = sim.subpopulations.haplosomes;
positions = rdunif(msatCount, 0, L-1);
repeats = rpois(msatCount, 20) + 5;

for (msatIndex in 0:(msatCount-1))
{
pos = positions[msatIndex];
mut = genomes.addNewDrawnMutation(m2, pos);
mut = haplosomes.addNewDrawnMutation(m2, pos);
mut.tag = repeats[msatIndex];
}

Expand All @@ -37,14 +37,14 @@ initialize() {
}
modifyChild() {
// mutate microsatellites with rate msatMu
for (genome in child.genomes)
for (haplosome in child.haplosomes)
{
mutCount = rpois(1, msatMu * msatCount);

if (mutCount)
{
mutSites = sample(msatPositions, mutCount);
msats = genome.mutationsOfType(m2);
msats = haplosome.mutationsOfType(m2);

for (mutSite in mutSites)
{
Expand All @@ -66,15 +66,15 @@ modifyChild() {

if (matchingMut.size() == 1)
{
genome.removeMutations(msat);
genome.addMutations(matchingMut);
haplosome.removeMutations(msat);
haplosome.addMutations(matchingMut);
next;
}
}

// make a new mutation with the new repeat count
genome.removeMutations(msat);
msat = genome.addNewDrawnMutation(m2, mutSite);
haplosome.removeMutations(msat);
msat = haplosome.addNewDrawnMutation(m2, mutSite);
msat.tag = repeats;
}
}
Expand Down
26 changes: 13 additions & 13 deletions QtSLiM/recipes/Recipe 14.12 - Modeling transposable elements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,22 @@ initialize() {
sim.tag = 0; // the next unique tag value to use for TEs

// create some transposons at random positions
genomes = sim.subpopulations.genomes;
haplosomes = sim.subpopulations.haplosomes;
positions = rdunif(teInitialCount, 0, L-1);

for (teIndex in 0:(teInitialCount-1))
{
pos = positions[teIndex];
mut = genomes.addNewDrawnMutation(m2, pos);
mut = haplosomes.addNewDrawnMutation(m2, pos);
mut.tag = sim.tag;
sim.tag = sim.tag + 1;
}
}
modifyChild() {
// disable transposons with rate teDisableP
for (genome in child.genomes)
for (haplosome in child.haplosomes)
{
tes = genome.mutationsOfType(m2);
tes = haplosome.mutationsOfType(m2);
teCount = tes.size();
mutatedCount = teCount ? rpois(1, teCount * teDisableP) else 0;

Expand All @@ -59,14 +59,14 @@ modifyChild() {
if (size(disabledTE))
{
// use the existing disabled TE mutation
genome.removeMutations(te);
genome.addMutations(disabledTE);
haplosome.removeMutations(te);
haplosome.addMutations(disabledTE);
next;
}

// make a new disabled TE mutation with the right tag
genome.removeMutations(te);
disabledTE = genome.addNewDrawnMutation(m3, te.position);
haplosome.removeMutations(te);
disabledTE = haplosome.addNewDrawnMutation(m3, te.position);
disabledTE.tag = te.tag;
}
}
Expand All @@ -78,9 +78,9 @@ late() {
// make active transposons copy themselves with rate teJumpP
for (individual in sim.subpopulations.individuals)
{
for (genome in individual.genomes)
for (haplosome in individual.haplosomes)
{
tes = genome.mutationsOfType(m2);
tes = haplosome.mutationsOfType(m2);
teCount = tes.size();
jumpCount = teCount ? rpois(1, teCount * teJumpP) else 0;

Expand All @@ -92,7 +92,7 @@ late() {
{
// make a new TE mutation
pos = rdunif(1, 0, L-1);
jumpTE = genome.addNewDrawnMutation(m2, pos);
jumpTE = haplosome.addNewDrawnMutation(m2, pos);
jumpTE.tag = sim.tag;
sim.tag = sim.tag + 1;
}
Expand All @@ -104,7 +104,7 @@ late() {
// print information on each TE, including the fraction of it disabled
all_tes = sortBy(sim.mutationsOfType(m2), "position");
all_disabledTEs = sortBy(sim.mutationsOfType(m3), "position");
genomeCount = size(sim.subpopulations.genomes);
haplosomeCount = size(sim.subpopulations.haplosomes);

catn("Active TEs:");
for (te in all_tes)
Expand All @@ -126,7 +126,7 @@ late() {

total = active + disabled;

cat("frequency " + format("%0.3f", total / genomeCount) + ", ");
cat("frequency " + format("%0.3f", total / haplosomeCount) + ", ");
catn(round(active / total * 100) + "% active");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ initialize() {
sim.addSubpop("p1", 100);

// create the canonical mutation objects
target = p1.genomes[0];
target = p1.haplosomes[0];
target.addNewDrawnMutation(m2, 0:99);
defineConstant("MUT2", target.mutations);
target.removeMutations();
Expand All @@ -33,7 +33,7 @@ initialize() {
target.removeMutations();

// start homozygous "aa" at every position
p1.genomes.addMutations(MUT3);
p1.haplosomes.addMutations(MUT3);

// log results
log = community.createLogFile("freq.csv", logInterval=10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ initialize() {
sim.addSubpop("p1", 100);

// create the permanent m2 mutation objects we will use
target = p1.genomes[0];
target = p1.haplosomes[0];
target.addNewDrawnMutation(m2, 0:99);
defineConstant("MUT", target.mutations);

Expand All @@ -37,7 +37,7 @@ initialize() {
mutation(m3) {
// if we already have an m2 mutation at the site, allow
// the new m3 mutation; we will remove the stack below
if (genome.containsMarkerMutation(m2, mut.position))
if (haplosome.containsMarkerMutation(m2, mut.position))
return T;

// no m2 mutation is present, so unique down
Expand All @@ -51,18 +51,18 @@ late() {
// if so, we have m2/m3 stacked mutations to remove
if (m3muts.length() > 0)
{
genomes = sim.subpopulations.genomes;
counts = genomes.countOfMutationsOfType(m3);
hasStacked = genomes[counts > 0];
haplosomes = sim.subpopulations.haplosomes;
counts = haplosomes.countOfMutationsOfType(m3);
hasStacked = haplosomes[counts > 0];

for (genome in hasStacked)
for (haplosome in hasStacked)
{
stacked_m3 = genome.mutationsOfType(m3);
stacked_m3 = haplosome.mutationsOfType(m3);
stackPositions = stacked_m3.position;
all_m2 = genome.mutationsOfType(m2);
all_m2 = haplosome.mutationsOfType(m2);
s = (match(all_m2.position, stackPositions) >= 0);
stacked_m2 = all_m2[s];
genome.removeMutations(c(stacked_m3, stacked_m2));
haplosome.removeMutations(c(stacked_m3, stacked_m2));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ initialize() {
if (parts[0] != "positions:") stop("Missing positions.");
positions = asFloat(parts[1:(size(parts)-1)]);

// create all mutations in a genome in a dummy subpopulation
// create all mutations in a haplosome in a dummy subpopulation
sim.addSubpop("p2", 1);
g = p2.genomes[0];
L = sim.chromosome.lastPosition;
g = p2.haplosomes[0];
L = sim.chromosomes.lastPosition;
intPositions = asInteger(round(positions * L));
muts = g.addNewMutation(m1, 0.0, intPositions);

// add the appropriate mutations to each genome
for (g in p1.genomes)
// add the appropriate mutations to each haplosome
for (g in p1.haplosomes)
{
f = asLogical(asInteger(strsplit(lines[index], "")));
index = index + 1;
Expand Down
Loading

0 comments on commit bd4038a

Please sign in to comment.