You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add requirement that mutations are sorted by time #651
A though: once this is implemented, we should have sort_tables sort mutations by time, which satisfies the current requirement that parents come before children, but would make the ordering produced by sort_tables less ambiguous (not totally, if in discrete time, though). Perhaps we should make "sorted by time" a requirement of the mutation table, also.
This seems like a sensible thing to do, to me, and we'll regret it if we miss the opportunity to set this constraint while we're adding the field. We just need to think through the consequences.
Started looking into this. One question is how we deal with unknowns - based on the "parents before children" requirement we have to include unknown times in a place that is consistent with that requirement. That means doing more than a simple comparison of time, but instead following each mutations parents to see which one is in the parent chain of the other. Am I getting that right?
Started looking into this. One question is how we deal with unknowns - based on the "parents before children" requirement we have to include unknown times in a place that is consistent with that requirement. That means doing more than a simple comparison of time, but instead following each mutations parents to see which one is in the parent chain of the other. Am I getting that right?
I think to the thing to do with UNKNOWN_TIME is to duplicate the old behaviour. So, the goal would be to keep the code exactly the same semantically if an old tree sequence was read in (which didn't have times), and then only have different behaviour when we do know the times. This should be easy enough to do within the comparison func. The only tricky bit is dealing with how to compare known and unknown times - but I guess the only thing to do there is to treat them both as unknown and not compare the time at all.
Thanks for pointing that out @mufernando. I think it's best to do each change to the sorting requirements as a separate sub-PR to #705. This prevents PRs and their discussions getting too large. I'll do a PR for this mutation time issue if that's good with you?
Actually, we realized in #705 that the only thing we needed to do was to sort the mutations, so we can close that one in favor of this one. Let's see, here's the things we have available to sort on (after sorting by site; the discussion is how to order the mutations that all have the same site):
time (maybe)
node
parent mutation id
original mutation id (ie order in the table before sorting)
Observations:
Sorting on (time, parent), with missing times incomparable, would suffice to ensure that things are ordered by time, and that parents come before children even if times are missing, as long as mutation parents are present.
Sorting on (time, original id) would also ensure this, as long as mutation parents came before children in the original table; and what we did before is just maintain original order, so sort on just original id.
Neither of these give you a canonical ordering; so we're proposing in make sort stricter #705 sorting on (time, parent, node) to make it canonical.
So I guess that here you could sort on (time, original id) to keep it as close to the original as possible. But I think we do want to move to (time, parent, node), so why not do that now?
@jeromekelleher and I had a chat about this earlier and for basic mutation time sorting settled on your (2) as the simplest option. To be explicit I think cmp_mutation would look like this:
You can only use parent to sort if the ids are already sorted correctly with respect to parenthood, right? Is that a safe assumption?
Not sure what you mean here? If you have correct parent ids already, then proposal (3) will put them in the correct order, regardless of whether beforehand parents came before children. (you gotta recompute mutation parents after sorting, though!)
Maybe this is what you mean? If mutations previously had parents coming before children, but did not have mutation parents computed, then (2) would preserve that (and thus compute_mutation_parents would still work), while (3) would break it. I think that's OK, since once we have mutation time, we don't have to rely on this relatively fragile ordering to keep that information. Edit: this is wrong - we still need to rely on it - because times may not be unique.
It's not clear to me that we do want to canonicalise the ordering of mutations here. Wouldn't it be easier to think about a canonical ordering when we're guaranteed that all the elements of the data model are present and correct? As it is with sorting, we have to be robust to parents being wrong (i.e., the parent is pointing to NULL, but it actually does have a parent). So, perhaps it would be easiest to do option (2) for the regular sorting algorithm, and deal with canonicalisation separately, preconditioned on a full TSK_CHECK_TREES integrity check?
In working out the tests for option 2 I realised that if you have two out-of-time-order mutations then putting an unknown time between them satisfies the order checking as it just looks at neighbouring mutations. Is this ok as mixed known/unknown is a fringe use case, or do we need to do more intensive checking for "monotonically decreasing known times per site"?
In working out the tests for option 2 I realised that if you have two out-of-time-order mutations then putting an unknown time between them satisfies the order checking as it just looks at neighbouring mutations. Is this ok as mixed known/unknown is a fringe use case, or do we need to do more intensive checking for "monotonically decreasing known times per site"?
I guess it's simpler to actually check this. We just need to remember the last_known_time as we go through the mutations for a site, right?
I agree with doing (2) after all: SLiM will want mutations with the same time (and node) to keep their relative order, since we won't have parent, and that's the only way we preserve that information. Sorry - I hadn't thought carefully enough about nonuniqueness of times before.
Activity
jeromekelleher commentedon May 26, 2020
This seems like a sensible thing to do, to me, and we'll regret it if we miss the opportunity to set this constraint while we're adding the field. We just need to think through the consequences.
petrelharp commentedon May 27, 2020
Ah, this would close #27 .
benjeffery commentedon Jul 17, 2020
Started looking into this. One question is how we deal with unknowns - based on the "parents before children" requirement we have to include unknown times in a place that is consistent with that requirement. That means doing more than a simple comparison of time, but instead following each mutations parents to see which one is in the parent chain of the other. Am I getting that right?
mufernando commentedon Jul 17, 2020
@benjeffery , I started looking into this in #715 (see also issue #705). Could use your help there, I've been busy with some other things this week.
jeromekelleher commentedon Jul 17, 2020
I think to the thing to do with UNKNOWN_TIME is to duplicate the old behaviour. So, the goal would be to keep the code exactly the same semantically if an old tree sequence was read in (which didn't have times), and then only have different behaviour when we do know the times. This should be easy enough to do within the comparison func. The only tricky bit is dealing with how to compare known and unknown times - but I guess the only thing to do there is to treat them both as unknown and not compare the time at all.
benjeffery commentedon Jul 17, 2020
Thanks for pointing that out @mufernando. I think it's best to do each change to the sorting requirements as a separate sub-PR to #705. This prevents PRs and their discussions getting too large. I'll do a PR for this mutation time issue if that's good with you?
mufernando commentedon Jul 17, 2020
Sounds good to me! Thanks!
petrelharp commentedon Jul 17, 2020
Actually, we realized in #705 that the only thing we needed to do was to sort the mutations, so we can close that one in favor of this one. Let's see, here's the things we have available to sort on (after sorting by site; the discussion is how to order the mutations that all have the same site):
Observations:
So I guess that here you could sort on (time, original id) to keep it as close to the original as possible. But I think we do want to move to (time, parent, node), so why not do that now?
benjeffery commentedon Jul 17, 2020
@jeromekelleher and I had a chat about this earlier and for basic mutation time sorting settled on your (2) as the simplest option. To be explicit I think
cmp_mutationwould look like this:Whereas for your option (3), if I understand correctly would be:
You can only use
parentto sort if the ids are already sorted correctly with respect to parenthood, right? Is that a safe assumption?I'm all for doing (3) now if that's what we want to end up with.
mufernando commentedon Jul 17, 2020
I would think that is a safe assumption because the current sorting behavior (on site id only) would not work otherwise, no?
petrelharp commentedon Jul 17, 2020
That's right, those are options (2) and (3).
Not sure what you mean here? If you have correct parent ids already, then proposal (3) will put them in the correct order, regardless of whether beforehand parents came before children. (you gotta recompute mutation parents after sorting, though!)
Maybe this is what you mean? If mutations previously had parents coming before children, but did not have mutation parents computed, then (2) would preserve that (and thus compute_mutation_parents would still work), while (3) would break it. I think that's OK, since once we have mutation time, we don't have to rely on this relatively fragile ordering to keep that information. Edit: this is wrong - we still need to rely on it - because times may not be unique.
jeromekelleher commentedon Jul 20, 2020
It's not clear to me that we do want to canonicalise the ordering of mutations here. Wouldn't it be easier to think about a canonical ordering when we're guaranteed that all the elements of the data model are present and correct? As it is with sorting, we have to be robust to parents being wrong (i.e., the parent is pointing to NULL, but it actually does have a parent). So, perhaps it would be easiest to do option (2) for the regular sorting algorithm, and deal with canonicalisation separately, preconditioned on a full TSK_CHECK_TREES integrity check?
benjeffery commentedon Jul 20, 2020
In working out the tests for option 2 I realised that if you have two out-of-time-order mutations then putting an unknown time between them satisfies the order checking as it just looks at neighbouring mutations. Is this ok as mixed known/unknown is a fringe use case, or do we need to do more intensive checking for "monotonically decreasing known times per site"?
jeromekelleher commentedon Jul 20, 2020
I guess it's simpler to actually check this. We just need to remember the
last_known_timeas we go through the mutations for a site, right?petrelharp commentedon Jul 20, 2020
I agree with doing (2) after all: SLiM will want mutations with the same time (and node) to keep their relative order, since we won't have parent, and that's the only way we preserve that information. Sorry - I hadn't thought carefully enough about nonuniqueness of times before.