Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions QtSLiM/help/SLiMHelpClasses.html
Original file line number Diff line number Diff line change
Expand Up @@ -664,11 +664,12 @@
<p class="p6"><span class="s3">Returns the coalescence state for the recorded tree sequence at the last simplification.<span class="Apple-converted-space">  </span>The returned value is a logical singleton flag, </span><span class="s4">T</span><span class="s3"> to indicate that full coalescence was observed at the last tree-sequence simplification (meaning that there is a single ancestral individual that roots all ancestry trees at all sites along the chromosome – although not necessarily the <i>same</i> ancestor at all sites), or </span><span class="s4">F</span><span class="s3"> if full coalescence was not observed.<span class="Apple-converted-space">  </span>For simple models, reaching coalescence may indicate that the model has reached an equilibrium state, but this may not be true in models that modify the dynamics of the model during execution by changing migration rates, introducing new mutations programmatically, dictating non-random mating, etc., so be careful not to attach more meaning to coalescence than it is due; some models may require burn-in beyond coalescence to reach equilibrium, or may not have an equilibrium state at all.<span class="Apple-converted-space">  </span>Also note that some actions by a model, such as adding a new subpopulation, may cause the coalescence state to revert from </span><span class="s4">T</span><span class="s3"> back to </span><span class="s4">F</span><span class="s3"> (at the next simplification), so a return value of </span><span class="s4">T</span><span class="s3"> may not necessarily mean that the model is coalesced at the present moment – only that it <i>was</i> coalesced at the last simplification.</span></p>
<p class="p6"><span class="s3">This method may only be called if tree sequence recording has been turned on with </span><span class="s4">initializeTreeSeq()</span><span class="s3">; in addition, </span><span class="s4">checkCoalescence=T</span><span class="s3"> must have been supplied to </span><span class="s4">initializeTreeSeq()</span><span class="s3">, so that the necessary work is done during each tree-sequence simplification.<span class="Apple-converted-space">  </span>Since this method does not perform coalescence checking itself, but instead simply returns the coalescence state observed at the last simplification, it may be desirable to call </span><span class="s4">treeSeqSimplify()</span><span class="s3"> immediately before </span><span class="s4">treeSeqCoalesced()</span><span class="s3"> to obtain up-to-date information.<span class="Apple-converted-space">  </span>However, the speed penalty of doing this in every generation would be large, and most models do not need this level of precision; usually it is sufficient to know that the model has coalesced, without knowing whether that happened in the current generation or in a recent preceding generation.</span></p>
<p class="p5"><span class="s3">– (void)treeSeqOutput(string$ path, [logical$ simplify = T], [logical$ includeModel = T], </span>[No$ metadata = NULL]<span class="s3">)</span></p>
<p class="p6"><span class="s3">Outputs the current tree sequence recording tables to the path specified by path.<span class="Apple-converted-space">  </span>This method may only be called if tree sequence recording has been turned on with </span><span class="s4">initializeTreeSeq()</span><span class="s3">.<span class="Apple-converted-space">  </span>If </span><span class="s4">simplify</span><span class="s3"> is </span><span class="s4">T</span><span class="s3"> (the default), simplification will be done immediately prior to output; this is almost always desirable, unless a model wishes to avoid simplification entirely.<span class="Apple-converted-space">  </span>A binary tree sequence file will be written to the specified path; a filename extension of </span><span class="s4">.trees</span><span class="s3"> is suggested for this type of file.</span></p>
<p class="p6">Outputs the current tree sequence recording tables to the path specified by path.<span class="Apple-converted-space">  </span>This method may only be called if tree sequence recording has been turned on with <span class="s1">initializeTreeSeq()</span>.<span class="Apple-converted-space">  </span>If <span class="s1">simplify</span> is <span class="s1">T</span> (the default), simplification will be done immediately prior to output; this is almost always desirable, unless a model wishes to avoid simplification entirely.<span class="Apple-converted-space">  </span>(Note that if simplification is not done, then all genomes since the last simplification will be marked as samples in the resulting tree sequence.)<span class="Apple-converted-space">  </span>A binary tree sequence file will be written to the specified path; a filename extension of <span class="s1">.trees</span> is suggested for this type of file.</p>
<p class="p6"><span class="s3">Normally, the full SLiM script used to generate the tree sequence is written out to the provenance entry of the tree sequence file, to the </span><span class="s4">model</span><span class="s3"> subkey of the </span><span class="s4">parameters</span><span class="s3"> top-level key.<span class="Apple-converted-space">  </span>Supplying </span><span class="s4">F</span><span class="s3"> for </span><span class="s4">includeModel</span><span class="s3"> suppresses output of the full script.</span></p>
<p class="p6">A <span class="s1">Dictionary</span> object containing user-generated metadata may be supplied with the <span class="s1">metadata</span> parameter.<span class="Apple-converted-space">  </span>If present, this dictionary will be serialized as JSON and attached to the saved tree sequence under a key named <span class="s1">user_metadata</span>, within the <span class="s1">SLiM</span> key.<span class="Apple-converted-space">  </span>If <span class="s1">pyslim</span> is used to read the tree sequence in Python, this metadata will automatically be deserialized and made available at <span class="s1">ts.metadata["SLiM"]["user_metadata"]</span>.<span class="Apple-converted-space">  </span>This metadata dictionary is not used by SLiM, or by <span class="s1">pyslim</span>, <span class="s1">tskit</span>, or <span class="s1">msprime</span>; you may use it for any purpose you wish.<span class="Apple-converted-space">  </span>Note that <span class="s1">metadata</span> may actually be any subclass of <span class="s1">Dictionary</span>, such as the <span class="s1">SLiMSim</span> simulation object <span class="s1">sim</span>, or a <span class="s1">LogFile</span> instance.<span class="Apple-converted-space">  </span>However, only the keys and values contained by the object’s <span class="s1">Dictionary</span> superclass state will be serialized into the metadata; properties of the subclass will be ignored.</p>
<p class="p5"><span class="s3">– (void)treeSeqRememberIndividuals(object&lt;Individual&gt; individuals)</span></p>
<p class="p6"><span class="s3">Permanently adds the individuals specified by </span><span class="s4">individuals</span><span class="s3"> to the sample retained across tree sequence table simplification.<span class="Apple-converted-space">  </span>This method may only be called if tree sequence recording has been turned on with </span><span class="s4">initializeTreeSeq()</span><span class="s3">.<span class="Apple-converted-space">  </span>All currently living individuals are always retained across simplification; this method does not need to be called, and indeed should not be called, for that purpose.<span class="Apple-converted-space">  </span>Instead, </span><span class="s4">treeSeqRememberIndividuals()</span><span class="s3"> is for <i>permanently</i> adding particular individuals to the retained sample.<span class="Apple-converted-space">  </span>Typically this would be used, for example, to retain particular individuals that you wanted to be able to trace ancestry back to in later analysis.<span class="Apple-converted-space">  </span>However, this is not the typical usage pattern for tree sequence recording; most models will not need to call this method.</span></p>
<p class="p5"><span class="s3">– (void)treeSeqRememberIndividuals(object&lt;Individual&gt; individuals</span>, [logical$ permanent = T]<span class="s3">)</span></p>
<p class="p6">Mark the individuals specified by <span class="s1">individuals</span> to be retained across tree sequence table simplification.<span class="Apple-converted-space">  </span>This method may only be called if tree sequence recording has been turned on with <span class="s1">initializeTreeSeq()</span>.<span class="Apple-converted-space">  </span>All currently living individuals are always retained across simplification; this method does not need to be called, and indeed should not be called, for that purpose.<span class="Apple-converted-space">  </span>Instead, <span class="s1">treeSeqRememberIndividuals()</span> allows any individual, including dead individuals, to be retained in the final tree sequence.<span class="Apple-converted-space">  </span>Typically this would be used, for example, to retain particular individuals that you wanted to be able to trace ancestry back to in later analysis.<span class="Apple-converted-space">  </span>However, this is not the typical usage pattern for tree sequence recording; most models will not need to call this method.</p>
<p class="p6">If <span class="s1">permanent</span> is <span class="s1">T</span> (the default), then the specified individuals will be permanently remembered: their genomes will be added to the current sample, and they will always be present in the tree sequence.<span class="Apple-converted-space">  </span>Supplying <span class="s1">F</span> for <span class="s1">permanent</span> will instead mark the individuals only for (temporary) retention: their genomes will not be added to the sample, and they will appear in the final tree sequence only if they are genetic ancestors of individuals in the sample.<span class="Apple-converted-space">  </span>Permanent remembering takes priority, such that calling this function with <span class="s1">permanent=F</span> on an individual that has previously been permanently remembered will not remove it from the sample.</p>
<p class="p6"><span class="s3">The metadata (age, location, etc) that are stored in the resulting tree sequence are those values present at either (a) the final generation, if the individual is alive at the end of the simulation, or (b) the last time that the individual was remembered, if not.<span class="Apple-converted-space">  </span>Calling </span><span class="s4">treeSeqRememberIndividuals()</span><span class="s3"> on an individual that is already remembered will cause the archived information about the remembered individual to be updated to reflect the individual’s current state.<span class="Apple-converted-space">  </span>A case where this is particularly important is for the spatial location of individuals in continuous-space models.<span class="Apple-converted-space">  </span>SLiM automatically remembers the individuals that comprise the first generation of any new subpopulation created with </span><span class="s4">addSubpop()</span><span class="s3">, for easy recapitation and other analysis.<span class="Apple-converted-space">  </span>However, since these first-generation individuals are remembered at the moment they are created, their spatial locations have not yet been set up, and will contain garbage – and those garbage values will be archived in their remembered state.<span class="Apple-converted-space">  </span>If you need correct spatial locations of first-generation individuals for your post-simulation analysis, you should call </span><span class="s4">treeSeqRememberIndividuals()</span><span class="s3"> explicitly on the first generation, after setting spatial locations, to update the archived information with the correct spatial positions.</span></p>
<p class="p5"><span class="s3">– (void)treeSeqSimplify(void)</span></p>
<p class="p6"><span class="s3">Triggers an immediate simplification of the tree sequence recording tables.<span class="Apple-converted-space">  </span>This method may only be called if tree sequence recording has been turned on with </span><span class="s4">initializeTreeSeq()</span><span class="s3">.<span class="Apple-converted-space">  </span>A call to this method will free up memory being used by entries that are no longer in the ancestral path of any individual within the current sample (currently living individuals, in other words, plus those explicitly added to the sample with </span><span class="s4">treeSeqRememberIndividuals()</span><span class="s3">), but it can also take a significant amount of time.<span class="Apple-converted-space">  </span>Typically calling this method is not necessary; the automatic simplification performed occasionally by SLiM should be sufficient for most models.</span></p>
Expand Down
30 changes: 22 additions & 8 deletions SLiMgui/SLiMHelpClasses.rtf
Original file line number Diff line number Diff line change
Expand Up @@ -5564,15 +5564,17 @@ This method may only be called if tree sequence recording has been turned on wit
)\
\pard\pardeftab397\li547\ri720\sb60\sa60\partightenfactor0

\f4\fs20 \cf2 Outputs the current tree sequence recording tables to the path specified by path. This method may only be called if tree sequence recording has been turned on with
\f4\fs20 \cf2 \kerning1\expnd0\expndtw0 Outputs the current tree sequence recording tables to the path specified by path. This method may only be called if tree sequence recording has been turned on with
\f3\fs18 initializeTreeSeq()
\f4\fs20 . If
\f3\fs18 simplify
\f4\fs20 is
\f3\fs18 T
\f4\fs20 (the default), simplification will be done immediately prior to output; this is almost always desirable, unless a model wishes to avoid simplification entirely. A binary tree sequence file will be written to the specified path; a filename extension of
\f4\fs20 (the default), simplification will be done immediately prior to output; this is almost always desirable, unless a model wishes to avoid simplification entirely. (Note that if simplification is not done, then all genomes since the last simplification will be marked as samples in the resulting tree sequence.) A binary tree sequence file will be written to the specified path; a filename extension of
\f3\fs18 .trees
\f4\fs20 is suggested for this type of file.\
\pard\pardeftab397\li547\ri720\sb60\sa60\partightenfactor0
\cf2 \expnd0\expndtw0\kerning0
Normally, the full SLiM script used to generate the tree sequence is written out to the provenance entry of the tree sequence file, to the
\f3\fs18 model
\f4\fs20 subkey of the
Expand Down Expand Up @@ -5617,18 +5619,30 @@ Normally, the full SLiM script used to generate the tree sequence is written out
\pard\pardeftab397\li720\fi-446\ri720\sb180\sa60\partightenfactor0

\f3\fs18 \cf2 \expnd0\expndtw0\kerning0
\'96\'a0(void)treeSeqRememberIndividuals(object<Individual>\'a0individuals)\
\'96\'a0(void)treeSeqRememberIndividuals(object<Individual>\'a0individuals\kerning1\expnd0\expndtw0 , [logical$\'a0permanent\'a0=\'a0T]\expnd0\expndtw0\kerning0
)\
\pard\pardeftab397\li547\ri720\sb60\sa60\partightenfactor0

\f4\fs20 \cf2 Permanently adds the individuals specified by
\f4\fs20 \cf2 \kerning1\expnd0\expndtw0 Mark the individuals specified by
\f3\fs18 individuals
\f4\fs20 to the sample retained across tree sequence table simplification. This method may only be called if tree sequence recording has been turned on with
\f4\fs20 to be retained across tree sequence table simplification. This method may only be called if tree sequence recording has been turned on with
\f3\fs18 initializeTreeSeq()
\f4\fs20 . All currently living individuals are always retained across simplification; this method does not need to be called, and indeed should not be called, for that purpose. Instead,
\f3\fs18 treeSeqRememberIndividuals()
\f4\fs20 is for
\f1\i permanently
\f4\i0 adding particular individuals to the retained sample. Typically this would be used, for example, to retain particular individuals that you wanted to be able to trace ancestry back to in later analysis. However, this is not the typical usage pattern for tree sequence recording; most models will not need to call this method.\
\f4\fs20 allows any individual, including dead individuals, to be retained in the final tree sequence. Typically this would be used, for example, to retain particular individuals that you wanted to be able to trace ancestry back to in later analysis. However, this is not the typical usage pattern for tree sequence recording; most models will not need to call this method.\
If
\f3\fs18 permanent
\f4\fs20 is
\f3\fs18 T
\f4\fs20 (the default), then the specified individuals will be permanently remembered: their genomes will be added to the current sample, and they will always be present in the tree sequence. Supplying
\f3\fs18 F
\f4\fs20 for
\f3\fs18 permanent
\f4\fs20 will instead mark the individuals only for (temporary) retention: their genomes will not be added to the sample, and they will appear in the final tree sequence only if they are genetic ancestors of individuals in the sample. Permanent remembering takes priority, such that calling this function with
\f3\fs18 permanent=F
\f4\fs20 on an individual that has previously been permanently remembered will not remove it from the sample.\
\pard\pardeftab397\li547\ri720\sb60\sa60\partightenfactor0
\cf2 \expnd0\expndtw0\kerning0
The metadata (age, location, etc) that are stored in the resulting tree sequence are those values present at either (a) the final generation, if the individual is alive at the end of the simulation, or (b) the last time that the individual was remembered, if not. Calling
\f3\fs18 treeSeqRememberIndividuals()
\f4\fs20 on an individual that is already remembered will cause the archived information about the remembered individual to be updated to reflect the individual\'92s current state. A case where this is particularly important is for the spatial location of individuals in continuous-space models. SLiM automatically remembers the individuals that comprise the first generation of any new subpopulation created with
Expand Down
3 changes: 1 addition & 2 deletions core/slim_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,7 @@ extern EidosValue_String_SP gStaticEidosValue_StringT;

#define SLIM_TSK_INDIVIDUAL_ALIVE ((uint32_t)(1 << 16))
#define SLIM_TSK_INDIVIDUAL_REMEMBERED ((uint32_t)(1 << 17))
// DEPRECATED:
// #define SLIM_TSK_INDIVIDUAL_FIRST_GEN ((uint32_t)(1 << 18))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petrelharp any reason to keep the old deprecated flag? Is there any potential issue with @hyanwong re-using the same (1 << 18) value for his new flag?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking that up. I was going to ask...

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't think so. Maybe pyslim needs to know what it is to be able to read old trees files, but we don't need it here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides, the flags have similar meanings: "this individual is in the tree sequence just 'cause it happens to still be here", sort of.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I guess pyslim can have logic that says "if this flag is set and the tree sequence version is less than X, then it means "first gen", otherwise it means "retained". SLiM would need that logic too, perhaps, in its tree sequence reading code? Do we do anything with these flags when we read a tree sequence in? Should we?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This last question remains unanswered. @petrelharp, do we need to do anything with this new flag (or with the possible existence of the deprecated SLIM_TSK_INDIVIDUAL_FIRST_GEN flag in an old file, now that we are re-using the same flag value) when we read in a tree sequence? It makes me nervous re-using the same value. If an old tree sequence has individuals marked with SLIM_TSK_INDIVIDUAL_FIRST_GEN, would they then be marked as "retained" when we read that old tree sequence in the new SLiM? And if so, is that OK, or should we worry about it? There are lots of people still using old versions of SLiM, so this is a real concern. (Somebody recently published a paper that cited SLiM 1.8!)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, let's see:

  • SLiM does not use the SLIM_TSK_INDIVIDUAL_FIRST_GEN flag for anything; we know this because it's actually commented out of the source code.
  • pyslim does not use it for anything either, although this method exists to help people find the FIRST_GEN individuals.

So: tree sequences produced by old versions of SLiM will have the FIRST_GEN individuals in the tree sequence. These are read into SLiM no problem. And, these are read into pyslim, and retain the FIRST_GEN flags, but the only thing this affects is how people use the tree sequence: sometimes they'd get confused about why there's individuals that aren't alive at the end of the simulation. It doesn't affect how anything works, or even any recommended workflows.

If we re-use the flag, but rename it RETAINED, then what will happen if we use an old tree sequence with the FIRST_GEN flag? Well, in SLiM those FIRST_GEN individuals will act as if they were RETAIN'ed. Which is fine, since they actually were (just for a different reason). And again, in pyslim, we don't actually use the REMEMBERED flag for anything, so this won't mess anything up.

So - I think this is fine - we can re-use the flag, and given that the two flags actually mean more or less the same thing (that the individual doesn't necessarily have nodes that are samples), we should re-use it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hurrah. Merge away!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Thanks for the reassurance; this makes sense. I'll merge now.

#define SLIM_TSK_INDIVIDUAL_RETAINED ((uint32_t)(1 << 18))

extern const std::string gSLiM_tsk_metadata_schema;
extern const std::string gSLiM_tsk_edge_metadata_schema;
Expand Down
Loading