Repository navigation
Initial version of mutate(). - #507
Conversation
|
This plan sounds reasonable to me, and I think this implementation will suffice for my needs at the present moment (i.e. will let me release SLiM 3, etc.). The We will eventually want to be able to open a .trees file with overlaid mutations back up in SLiM, to run further simulation on it, I think; to do that the overlaid mutations will need to get the appropriate metadata added to them, which I believe @petrelharp has a plan for...? That SLiMification process would also involve rounding off site positions to integers and merging mutations at the same site into stacked mutations with the appropriate stacked derived state, so it will be a bit of an adventure to do right. But the ability to do that does not need to make it into 0.6.0 or SLiM 3, I think. So for 0.6.0 this looks great, and I think the future plans should work. |
|
This looks like a good start. I think the |
I think we probably do need this for the initial version as putting neutral mutations onto something with selected sites seems like a fairly important thing to do. Let's see what @petrelharp thinks though.
Sounds good. I've opened issue #509 to track this. |
Great, thanks. I've opened issue #508 to track this. |
|
Looks good for now. Anyone sufficiently motivated could use infinite sites as fodder for a more complicated scheme. So, would the current |
This would be hidden away I think --- the interface is too low-level to expose to users. I think if we did end up writing different mutation models the whole low-level infrastructure would need to change, so this class would probably disappear. It might not even be necessary do some models in C for example. I'm sure we could rewrite the current infinite sites generator in numpy and it would be exactly as fast as the C method we have. The reasons I haven't done this so far is (a) I can't be bothered as it all works pretty well at the moment, and such a change would need to be carefully tested statistically; and (b) it's handy having mutations for testing in C. |
Also separate module for generating mutations.
9184190 to
c840aa4
Compare
- Added equals (closes tskit-dev#496) - Added deduplicate_sites (closes tskit-dev#495)
8b7ba4a to
56aa96d
Compare
|
I've updated the API here with the There's bunch of debugging in there at the moment as I've hit a problem with |
|
Wow, very impressive. Looking now.
Not sure I follow, but: the idea with |
|
Note: here should be |
|
Other notes about
|
|
Other than the issue with |
|
Thanks @petrelharp. I'm not sure I agree about the logic on I think there's a simpler way though. What if we just rejection sample any mutations that happen to fall on existing site positions in the MutationGenerator? It's simple to do, and I think it's more logically consistent. We're generating infinite sites mutations, so by definition these should not fall on any site that already exists. That way we don't need What do you think? |
This is how I do it, and it is super efficient given a good hash table implementation. |
It's already done within the existing mutation generator (using an AVL tree so not that fast, but good enough) to ensure that there are no duplicate site positions produced. So all we need to do here is to populate the lookup table with the site positions that are already in the table and it should all just work. |
|
I think that would be the most consistent thing to do, because new infinite sites mutations should really not hit existing sites... |
|
A bit more on the logic of OK, so the list of positions to check against isn't already available in the simulator; but it is certainly available in the Site table; so all we'd have to do is to check if a position is already present in |
|
OK, thanks for the rationale @petrelharp, that's helpful. I think the way forward here so is:
I'm still not crazy on the One thing a simulator could do to look up the sites is to use binary search on the sorted positions in |
Yes, agree.
What is the bug? But I guess I will see when you file the bug.
True, but if this is happening in a consistent forwards simulation, then it is guarenteed to make sense. It might make sense to leave |
There's something screwy with site metadata and ancestral states. I'll leave some test cases which provoke it.
Yes that's true. Fair enough. |
|
OK, this should do it. I've updated the low-level code to generate infinite sites mutations, conditioned on an existing set of positions. The I've left a few skipped tests for the issue with @petrelharp would you mind taking one last look at this before I merge? |
| mutation = site->mutations + j; | ||
| parent = mutation->parent; | ||
| if (parent != MSP_NULL_MUTATION) { | ||
| parent += new_mutations; |
| are discarded. | ||
| simulated. Under the infinite sites mutation model, any sites that are | ||
| generated with precisely the same position as an existing position will be | ||
| rejection sampled. |
There was a problem hiding this comment.
How about "Under the infinite sites mutation model, all new mutations generated will occur at distinct positions from each other and from any existing mutations (by rejection sampling)."
|
Looks good. Nice implementation, should make future mutation models quite easy. |
5ecf266 to
c381128
Compare
Thanks! It was due a spring clean, I had been hacking it just enough to work for a long time. Hopefully this clean implementation will inspire someone to make lots of useful mutation models. |
Closes #473.
Pinging @petrelharp, @bhaller and @molpopgen for review.
We can add complexity from there, but I think this is what the basic interface and default behaviour should be --- simple infinite sites 0/1 mutations, overwriting any existing mutations.
The main thing we need for forward simulations I think is to add a
keep(default=False) argument that tellsmutateto keep any existing mutations and discard any new mutations that are generated with the same site position.Someone mentioned a 'since' argument to limit the time slice over which mutations are applied. This is a good idea, but I think we can add this a planned feature rather than something essential in the first version. If we agree we can open an issue to track this and schedule it in for some future release.
In the future then we'll add a
model=msprime.JukesCantor()argument (e.g.) which will allow the user to generate mutations under some more complex model than infinite sites. (See #473 for more discussion here.) I might add amsprime.InfiniteSitesmodel here now just to make things concrete and make it clear how we envisage the API growing over time.