Repository navigation
Support retain as well as remember - #125
Conversation
454a242 to
8254f04
Compare
| ************************************* | ||
|
|
||
| OK, who and what exactly *is* left in the tree sequence? | ||
| OK, who and what exactly *is* left in the tree sequence after simplification? |
There was a problem hiding this comment.
It migth be confusing to say "after simplification" here: the reader might not know that "simplification" refers to a specific process (the previous paragraph is understandable without thinking of it as a technical term).
There was a problem hiding this comment.
Maybe "who and what exactly is left in the tree sequence after the unnecessary information has been removed?" (or, "has been simplified away"?)
There was a problem hiding this comment.
Good point. On that note, when you mention simplification later on, in tutorial.rst, it's as if you have never mentioned it before. I wonder if, in the tutorial, you should say something like "explicit simplification, in a similar way that the tree sequence is simplified on output, as described in the intro"?
There was a problem hiding this comment.
Good idea, this should be clarified. In the tutorial I'm talking about running-simplify-in-python, not the simplification that happens in SLiM as it goes along. The reason it's like this is because simplification-by-SLiM is something that I think people can safely ignore: it's how things work under the hood, but I find that if we start talking about simplification a lot then people think they have to do it, but things are less error-prone if they don't do it. But clarification would be good.
I'd say we should keep |
| kept in the tree sequence after simplification. In contrast, individuals that are | ||
| merely marked for retention can lose their nodes (as has happened to one of the nodes in | ||
| this case). Furthermore, once all an individuals's nodes are lost, simplification | ||
| removes the individual too, for efficiency reasons. |
There was a problem hiding this comment.
Suggested edit:
"
In the picture above there are two additional individuals pictured in the
tree sequence that were not alive at the end of the simulation. These are still present because they
were remembered, using the treeSeqRememberIndividuals() method. The lower
one (still containing 2 nodes or chromosome) was permanently remembered, which is the
default behaviour. The upper one (with only one node left) was only "retained",
by passing permanent=F when calling treeSeqRememberIndividuals().
As you might expect, permanently remembered individuals and the entire genealogical history of both their nodes are always
kept in the tree sequence, while individuals that are
merely retained will only be present in the tree sequence as long as at least one of their nodes
has not been removed by simplification.
"
Hm. I'm kinda feeling like this is the wrong place for a technical discussion, being the introduction, and maybe "retaining" is a more advanced topic to be explained elsewhere. What do you think? The problem is that the above paragraph still isn't quite there, because the fundamental difference between permanent/not is that
- a permanently remembered individual is guaranteed to always have the entire history of both their chromosomes in the tree sequence
- whereas a retained individual only acts as some extra annotation for its nodes: the only parts of its genomes that are actually recorded in the tree sequence are those on which it's the MRCA of two samples, unless
keep_unaryis on.
How about we remove mention of "retaining" from the Introduction, and make a new section in the Tutorial about it?
There was a problem hiding this comment.
I think it's useful to have it for the picture (because we need a picture for showing the difference between retained and remembered).
Also, if we are removing mention of retaining, should we not also remove a mention of Remembering entirely from the intro, as many people will use pyslim without either Remembering or Retaining?
I wonder if we should make Remembering (+ retaining) a separate section on their own, perhaps in the intro?
| ``tskit`` "nodes" correspond to SLiM "genomes". | ||
| Individuals in SLiM are diploid, so each has two nodes. | ||
| Individuals in SLiM are diploid, so normally, each has two nodes (but see below for | ||
| retained individuals, which can lose one of the nodes during simplification). |
There was a problem hiding this comment.
how about
Individuals in SLiM are diploid, so each has two nodes (but retained individual may have
some removed by simplification: see below).
| about (either "early" or "late"; defaults to "late"). | ||
| :param str remembered_stage: The stage in the SLiM life cycle | ||
| that individuals were Remembered during (defaults to the stage the | ||
| that individuals were Remembered or Retained (defaults to the stage the |
There was a problem hiding this comment.
maybe omit "or Retained" here? Since one retains by calling treeSeqRemember, it seems sufficient; and otherwise it suggests there is a treeSeqRetain method?
| :param str remembered_stage: The stage in the SLiM life cycle that | ||
| individuals were Remembered during. | ||
| :param str remembered_stage: The stage in the SLiM life cycle during which | ||
| individuals were Remembered or Retained. |
Yep - just adding the recipe, and then adding it to example_files should do it. |
|
Want me to have a go at the tests here, while you finish editing the docs? |
If that's easy, yes please! If we are adding |
|
@petrelharp - in 0264a77 I've had a go at rewording The section "What if I'm interested in historical individuals too?" is in the intro, but could, if you prefer, be moved to the tutorial. I'll wait until I've got the go ahead from you before making any more changes or fiddling with the plots, if that's OK? |
| that for simplicity, in this model the individuals that are currently alive are | ||
| all in the final generation, but more generally, individuals alive at a particular time | ||
| should be identified via the :meth:`.SlimTreeSequence.individuals_alive_at()` method (see | ||
| :ref:`sec_extracting_individuals`). |
There was a problem hiding this comment.
this note is getting in to the weeds a bit much - in the diagram it isn't exactly clear who's alive when, or if this is something with overlapping generations or not
There was a problem hiding this comment.
OK. It was in the previous write-up, but I wasn't quite sure where to slide it in. Note that the diagram isn't right yet - I haven't changed anything there.
| they were in (see :ref:`sec_retaining_individuals` if you need to retain this information). | ||
|
|
||
| As well as the actual individuals, many historical *nodes* have been removed too, | ||
| along with the lines linking them to the rest of the genealogy (in tree-sequence-speak the |
There was a problem hiding this comment.
maybe "along with their genealogical relationships"
| lines are known as "edges"). The deleted nodes are simply those that are not needed to | ||
| reconstruct the relationships between the sample nodes. For example we remove nodes | ||
| leading to a dead end (e.g. in individuals who had no offspring). Similarly, as time goes | ||
| on, successive recombination events can gradually reduce the genetic contribution of |
There was a problem hiding this comment.
it's genetic drift rather than recombination events that does this, strictly speaking
There was a problem hiding this comment.
ISWYM, but here I think it's a combination of both. What I'm trying to convey is that even if there are lines of ancestry in the diagram that go through a (coalescent) node, that node may be deleted because the line essentially "belongs to another tree". I'l try to rephrase.
| As we've seen, the tree sequence retains enough of the nodes (genomes) in the past to | ||
| reconstruct the genetic ancestry of the currently alive individuals. But you might want | ||
| more than that. For example, there may be individuals who are not alive any more, but | ||
| whose complete ancestry you would like to know. Or it may be that you want to access the |
There was a problem hiding this comment.
", or you'd like to know how the final generation relates to the individuals alive at some previous time."
|
|
||
| .. _sec_remembering_individuals: | ||
|
|
||
| By default, individuals are *permanently* remembered, by marking their nodes as actual |
There was a problem hiding this comment.
should be "individuals included in the tree sequence by a call to treeSeqRememberIndividuals( )"
|
I've made some minor comments on the docs - they look good, generally. I'd still vote to move the "historical individuals" bit to a new section in the Tutorial, maybe before "Extracting particular individuals". What do you think? I'll have another good read through after the figures are in and it compiles. |
|
Ok, I've added some tests, and fixed up the testing of And, this has turned up - I think - a bug in the SLiM implementation: the test recipe where I alternate retaining and remembering, |
Yes, I agree.
Yes, I'll check this out. |
f693cde to
bc1b492
Compare
I've just rebased on the new test framework, and the tests are all passing, so I can't find the problem you say, @petrelharp. Could you check if I'm missing something? It should be easier to try out a failing test & recipe now, so hopefully easier to report? |
|
You've forgotten to include the new tests I wrote (maybe just adding the recipe to |
|
Uh-oh, I'm afraid something's gone wrong with your rebase? For some reason this is showing a bunch of fixture-related changes in the diff. And (maybe this was an error that happened in that PR that we missed) there's a bunch of tests in |
|
The fixture commits showing up here is I think because you rebased to your local feature branch instead of rebaseing to |
|
But it looks like the merging/rebasing might need to be a bit more manual. I've got the previous state of this branch in my git repo if you want me to force-push it back to how it was before the rebase. |
|
Done: should work now. Sorry about that. |
|
Maybe we should mark those particular .trees files to not be ignored in the gitignore... |
|
Ok, so I get the same error. (tldr; we should delete this part of the test) Adding some prints and running the SLiM script and looking at the pedigree file, I see that this individual's ID is 77, and has two SLiM parents, 52 and 64. But for some reason 64 isn't in Ah-ha. but that other parent, with SLiM ID 64, is itself produced by 77's other parent, 52, by selfing: and I guess that 64 was just retained, not remembered, and so isn't in the tree sequence any more. The result is indistinguishable from 77 having been produced by 52 by selfing. Ok: my proposed fix is to just delete the lines since they're trying to test something we can't really test. |
Nah, it's OK. Once they are in the git store, it doesn't ignore them - if they change it will now be noticed. They only vanished because I changed the name of the directory they were in, so git forgot they were actually part of the repo. |
Great sleuthing. Thanks @petrelharp. Happy with that solution. I'll do it now. |
1b9d2b4 to
cfd9cc5
Compare
|
Interesting that this is now failing on This is even with the updated SLiM version (and we aren't doing keep_unary in the tests anyway). Any idea what's going on @petrelharp ? I'm just working on the Inkscape pictures for the new docs now. |
cfd9cc5 to
d610f72
Compare
|
I have now changed the docs so that "remembering and retaining" has its own section. That's meant a fair change in the diagrams, and a bit in the structure (e.g. I now have put "recapitation, simplification, mutation" in a higher-level section about combining forwards & backwards sims. I rather hacked the diagrams so haven't properly changed the master Inkscape file or the makefile that creates them. I'll do that once you look at the pictures, @petrelharp, and approve the general approach. I hope it makes the introduction a bit simpler (I wasn't sure which style out of Edit - one other thing I notice is that although it's on the "tutorial" page, the "remembering and retaining" section doesn't actually have any code to follow. Which seems a bit odd. |
d610f72 to
88d3eca
Compare
|
Well, the failing test is the same problem as above: individual 78 has parents 62 and 65, but only 62 is retained, and so we mistake 65's parent, 52, for 78's parent, because apparently 52 is still alive when 78 is born, and 78 inherited the entire chromosome from 52. So, overly strict tests again, I guess - I only really designed these Here's a fix: Sorry about that! |
| you may recall, this means we have their full genetic ancestry. The sample nodes, | ||
| and the individuals containing them, are always present in the tree sequence, which | ||
| should be clear in the diagram. (Note that additional nodes can be | ||
| :ref:`marked as samples <sec_remembering_individuals>` as detailed in the tutorial.) |
There was a problem hiding this comment.
I'd end this paragraph with "The sample nodes, and the individuals containing them, are always present in the tree sequence." (the rest is a bit confusing at this point).
There was a problem hiding this comment.
Good point, I was probably going too deep too early.
|
|
||
| ************** | ||
| ++++++++++++++ | ||
| Simplification |
There was a problem hiding this comment.
This and the next section ("adding mutations") aren't really part of "combining forward and coalescent simulations" - they're things you'd want to do even without any coalescent simulations at all. I don't think we need the "Combining..." top-level section at all?
There was a problem hiding this comment.
Ah, that was because the entire 3-part section has its own introduction. Previously that was the introduction used for the entire tutorial, but it didn't really fit because it was only relevant to the "recapitation -> simplification -> mutation" part. I guess a simple way to change this is to change the section heading to "recapitation, simplification, and mutation". But perhaps there's a better way?
There was a problem hiding this comment.
Right. This is a symptom of the docs being just cobbled together, and needing an overhaul. Those three things are together because they're part of the expected workflow. Maybe a heading titled "The standard workflow"? Or, "Common preprocessing steps"? Or, "The first things to do with your tree sequence"? Or, maybe just "Recapitation, simplification, and mutation", as you say; we'll rearrange later.
There was a problem hiding this comment.
I changed it to "Recapitation, simplification, and mutation", and added a bit of intro to explain that this is a common workflow.
I have overhauled some of the other sections a bit, and I think that makes them a tiny bit less of a hotchpotch. But I don't want to do much more (especially if we are going to move this over to a jupyter-book anyway).
|
|
||
| By default, a call to ``treeSeqRememberIndividuals()`` will permanently remember one or | ||
| more individuals, by marking their nodes as actual samples: the simulated equivalent of | ||
| ancient DNA dug out of permafrost, or stored |
|
Whoops - I was looking at an out-of-date version, and have deleted a few comments above. Looking good! I like the new Introduction figure! |
Good point. And the subsequent sections ("Extracting particular individuals" and "Individual metadata") should arguably go earlier, because they describe more basic things people would want to do. Maybe we should put in a simple example that uses remembering or retaining? e.g. just Remember everyone halfway through a nonWF simulation and then report the age structure at the time. I could throw tihs in a separate PR if you like. |
|
Looks good! I approve! |
Ah, embarrassed to say that I didn't follow too deeply what the problem was, so I didn't spot this, sorry (I was focussing on the docs instead) Thanks for the fix. It all passes now. I'll address your revised comments above, fix the SVG, and hopefully this will be good to go, so I can move on to the final tskit fix. |
88d3eca to
059705a
Compare
059705a to
8263415
Compare
|
This all looks great @petrelharp thanks for all your work on this and the associated fixes/tests in MesserLab/SLiM#158 and tskit-dev/tskit#1190 . I didn't realise how much work it would be to get all these moving parts working together 🤯 But it looks like it's all done now, so 🎉 |
|
Whoo! I think it's working now! Tests passed locally. I think I'll be ready to squash & merge. Let me know if you spot anything. |
Codecov Report
@@ Coverage Diff @@
## main #125 +/- ##
==========================================
+ Coverage 89.39% 89.40% +0.01%
==========================================
Files 5 5
Lines 886 887 +1
Branches 166 166
==========================================
+ Hits 792 793 +1
Misses 64 64
Partials 30 30
Continue to review full report at Codecov.
|
|
LGTM. Squash & merge away! (maybe even merge tskit-dev/tskit#1190 in tskit beforehand?) |
and relax parents test
f1a59fe to
0684704
Compare
Hi @petrelharp - here's the basic PR for dealing with Retaining in pyslim but I haven't added any more tests. I guess we should add a slim recipe in where e.g. we Retain (rather than remember) everyone, and maybe a recipe where we Retain some and Remember others? I guess we want a round trip of some sort - does this exist already?
Also, we are still testing the (deprecated) function
first_generation_individuals(), but that function relies on theINDIVIDUAL_FIRST_GENconstant that no longer exists. What should we do this this: simply turn the warning into an error? It's causingtests/test_tree_sequence.py::TestDeprecations::test_first_gento fail.