From 7e9194d2857bce3e7fe595d24ab6e0601e350324 Mon Sep 17 00:00:00 2001 From: Ben Haller Date: Tue, 25 Jul 2023 22:18:38 -0400 Subject: [PATCH] fix #333: record tag/tagF values in .trees (fixed as doc bug) --- ...ation of a sweep, preserving ancestry I.txt | 7 +++---- ...tion of a sweep, preserving ancestry II.txt | 18 ++++++++++++++---- ...ation of a sweep, preserving ancestry I.txt | 7 +++---- ...tion of a sweep, preserving ancestry II.txt | 18 ++++++++++++++---- VERSIONS | 1 + 5 files changed, 35 insertions(+), 16 deletions(-) diff --git a/QtSLiM/recipes/Recipe 17.3 - Simulation conditional upon fixation of a sweep, preserving ancestry I.txt b/QtSLiM/recipes/Recipe 17.3 - Simulation conditional upon fixation of a sweep, preserving ancestry I.txt index 6fe43a79a..d274adcaa 100644 --- a/QtSLiM/recipes/Recipe 17.3 - Simulation conditional upon fixation of a sweep, preserving ancestry I.txt +++ b/QtSLiM/recipes/Recipe 17.3 - Simulation conditional upon fixation of a sweep, preserving ancestry I.txt @@ -16,7 +16,8 @@ initialize() { 1000 late() { target = sample(p1.genomes, 1); target.addNewDrawnMutation(m3, 10000); - sim.outputFull(tempdir() + "slim_" + simID + ".txt"); + defineConstant("PATH", tempdir() + "slim_" + simID + ".trees"); + sim.outputFull(PATH); } 1000:100000 late() { if (sim.countOfMutationsOfType(m3) == 0) { @@ -25,9 +26,7 @@ initialize() { sim.simulationFinished(); } else { cat(simID + ": LOST - RESTARTING\n"); - - sim.readFromPopulationFile(tempdir() + "slim_" + simID + ".txt"); - setSeed(rdunif(1, 0, asInteger(2^62) - 1)); + sim.readFromPopulationFile(PATH); } } } diff --git a/QtSLiM/recipes/Recipe 17.3 - Simulation conditional upon fixation of a sweep, preserving ancestry II.txt b/QtSLiM/recipes/Recipe 17.3 - Simulation conditional upon fixation of a sweep, preserving ancestry II.txt index eb78edf9f..1a9db077d 100644 --- a/QtSLiM/recipes/Recipe 17.3 - Simulation conditional upon fixation of a sweep, preserving ancestry II.txt +++ b/QtSLiM/recipes/Recipe 17.3 - Simulation conditional upon fixation of a sweep, preserving ancestry II.txt @@ -1,6 +1,7 @@ // Keywords: tree-sequence recording, tree sequence recording, conditional sweep initialize() { + initializeSLiMOptions(keepPedigrees=T); initializeTreeSeq(); initializeMutationRate(1e-8); initializeMutationType("m2", 0.5, "g", -0.01, 1.0); // deleterious @@ -14,9 +15,16 @@ initialize() { sim.addSubpop("p1", 500); } 1000 late() { + // assign tag values to be preserved + inds = sortBy(sim.subpopulations.individuals, "pedigreeID"); + tags = rdunif(size(inds), 0, 100000); + inds.tag = tags; + metadataDict = Dictionary("tags", tags); + target = sample(p1.genomes, 1); target.addNewDrawnMutation(m3, 10000); - sim.treeSeqOutput(tempdir() + "slim_" + simID + ".trees"); + defineConstant("PATH", tempdir() + "slim_" + simID + ".trees"); + sim.treeSeqOutput(PATH, metadata=metadataDict); } 1000:100000 late() { if (sim.countOfMutationsOfType(m3) == 0) { @@ -26,9 +34,11 @@ initialize() { sim.simulationFinished(); } else { cat(simID + ": LOST - RESTARTING\n"); - - sim.readFromPopulationFile(tempdir() + "slim_" + simID + ".trees"); - setSeed(rdunif(1, 0, asInteger(2^62) - 1)); + sim.readFromPopulationFile(PATH); + metadataDict = treeSeqMetadata(PATH); + tags = metadataDict.getValue("tags"); + inds = sortBy(sim.subpopulations.individuals, "pedigreeID"); + inds.tag = tags; } } } diff --git a/SLiMgui/Recipes/Recipe 17.3 - Simulation conditional upon fixation of a sweep, preserving ancestry I.txt b/SLiMgui/Recipes/Recipe 17.3 - Simulation conditional upon fixation of a sweep, preserving ancestry I.txt index 6fe43a79a..d274adcaa 100644 --- a/SLiMgui/Recipes/Recipe 17.3 - Simulation conditional upon fixation of a sweep, preserving ancestry I.txt +++ b/SLiMgui/Recipes/Recipe 17.3 - Simulation conditional upon fixation of a sweep, preserving ancestry I.txt @@ -16,7 +16,8 @@ initialize() { 1000 late() { target = sample(p1.genomes, 1); target.addNewDrawnMutation(m3, 10000); - sim.outputFull(tempdir() + "slim_" + simID + ".txt"); + defineConstant("PATH", tempdir() + "slim_" + simID + ".trees"); + sim.outputFull(PATH); } 1000:100000 late() { if (sim.countOfMutationsOfType(m3) == 0) { @@ -25,9 +26,7 @@ initialize() { sim.simulationFinished(); } else { cat(simID + ": LOST - RESTARTING\n"); - - sim.readFromPopulationFile(tempdir() + "slim_" + simID + ".txt"); - setSeed(rdunif(1, 0, asInteger(2^62) - 1)); + sim.readFromPopulationFile(PATH); } } } diff --git a/SLiMgui/Recipes/Recipe 17.3 - Simulation conditional upon fixation of a sweep, preserving ancestry II.txt b/SLiMgui/Recipes/Recipe 17.3 - Simulation conditional upon fixation of a sweep, preserving ancestry II.txt index eb78edf9f..1a9db077d 100644 --- a/SLiMgui/Recipes/Recipe 17.3 - Simulation conditional upon fixation of a sweep, preserving ancestry II.txt +++ b/SLiMgui/Recipes/Recipe 17.3 - Simulation conditional upon fixation of a sweep, preserving ancestry II.txt @@ -1,6 +1,7 @@ // Keywords: tree-sequence recording, tree sequence recording, conditional sweep initialize() { + initializeSLiMOptions(keepPedigrees=T); initializeTreeSeq(); initializeMutationRate(1e-8); initializeMutationType("m2", 0.5, "g", -0.01, 1.0); // deleterious @@ -14,9 +15,16 @@ initialize() { sim.addSubpop("p1", 500); } 1000 late() { + // assign tag values to be preserved + inds = sortBy(sim.subpopulations.individuals, "pedigreeID"); + tags = rdunif(size(inds), 0, 100000); + inds.tag = tags; + metadataDict = Dictionary("tags", tags); + target = sample(p1.genomes, 1); target.addNewDrawnMutation(m3, 10000); - sim.treeSeqOutput(tempdir() + "slim_" + simID + ".trees"); + defineConstant("PATH", tempdir() + "slim_" + simID + ".trees"); + sim.treeSeqOutput(PATH, metadata=metadataDict); } 1000:100000 late() { if (sim.countOfMutationsOfType(m3) == 0) { @@ -26,9 +34,11 @@ initialize() { sim.simulationFinished(); } else { cat(simID + ": LOST - RESTARTING\n"); - - sim.readFromPopulationFile(tempdir() + "slim_" + simID + ".trees"); - setSeed(rdunif(1, 0, asInteger(2^62) - 1)); + sim.readFromPopulationFile(PATH); + metadataDict = treeSeqMetadata(PATH); + tags = metadataDict.getValue("tags"); + inds = sortBy(sim.subpopulations.individuals, "pedigreeID"); + inds.tag = tags; } } } diff --git a/VERSIONS b/VERSIONS index 183e54aea..27861995a 100644 --- a/VERSIONS +++ b/VERSIONS @@ -121,6 +121,7 @@ development head (in the master branch): bug fix in pyslim to announce: https://github.com/tskit-dev/pyslim/issues/307 feature request: #378, add font bigger (command +) and font smaller (command -) menu items and shortcuts, so the user doesn't have to open the prefs window; note that with command = the shift key is needed this meant removal of the shortcuts for prettyprint script and reformat script, since they conflicted (well, prettyprint conflicted); probably nobody cares + revised recipe 17.3 to show how to persist tag values from a simulation in the tree-sequence metadata version 4.0.1 (Eidos version 3.0.1):