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
Currently sort_tables doesn't ensure mutations occur after their parents. It probably should, but this behvaior is documented, so it's not major.
This is a way that tables can be out of order that sort_tables does not fix, so we should probably address it, although we don't have a use case that produces tables out of order in this way.
The only way I can think of to do this is to add a field to the mutation struct used for sorting that is "number of hops to the root", computed by following mutation.parent indices until you hit a -1.
I've just hit this, when trying to turn a biallelic site into a multiallelic site, for testing purposes. I tried simply adding extra mutations onto nodes in the tree at that site, but fell foul of the mutation order requirement, which I can't easily see how to fix.
This'd be nice to fix, but for your tests, @hyanwong - did you know that if you add the new mutations without any parents, then call compute_mutation_parents, this will fill them in for you (using order in the table)?
@petrelharp thanks - the problem here is with mutations with order dependence (i.e. one mutation on the same lineage as another at the same site). I don't think compute_mutation_parents works in this case.
@Chris1221 could add the following code as a unit test for fixing it, perhaps?
import tskit
import msprime
ts = msprime.simulate(4, mutation_rate=2)
tables = ts.dump_tables()
tables.mutations.add_row( # Add above the root => guaranteed to be in the "wrong" order
site=0, node=ts.first().root, derived_state="2", parent=tskit.NULL)
tables.sort() # Does not sort mutations within a site
tables.build_index() # Apparently needed to compute mutation parents
tables.compute_mutation_parents() # Currently fails with _tskit.LibraryError
Activity
jeromekelleher commentedon Jul 10, 2018
Probably not for 0.6.1 I'd say --- shall we create a 0.6.2 milestone and add it to that?
hyanwong commentedon Nov 14, 2019
I've just hit this, when trying to turn a biallelic site into a multiallelic site, for testing purposes. I tried simply adding extra mutations onto nodes in the tree at that site, but fell foul of the mutation order requirement, which I can't easily see how to fix.
hyanwong commentedon Dec 4, 2019
Ping @Chris1221 as an issue that could probably be tackled along with #117 (I would find it useful if this issue were solved)
Chris1221 commentedon Dec 4, 2019
Great, thank you @hyanwong, I'll take a look in the next little while. :)
petrelharp commentedon Dec 5, 2019
This'd be nice to fix, but for your tests, @hyanwong - did you know that if you add the new mutations without any parents, then call
compute_mutation_parents, this will fill them in for you (using order in the table)?hyanwong commentedon Dec 5, 2019
@petrelharp thanks - the problem here is with mutations with order dependence (i.e. one mutation on the same lineage as another at the same site). I don't think
compute_mutation_parentsworks in this case.@Chris1221 could add the following code as a unit test for fixing it, perhaps?
hyanwong commentedon Dec 5, 2019
NB - once fixed, remember to remove the docs noting this problem, on line 653 of
docs/data-model.rstChris1221 commentedon Dec 5, 2019
Thanks @hyanwong, I was thinking of asking for an example of the failure -- this will help me tremendously to get started.
jeromekelleher commentedon Sep 29, 2020
Closing this, as the semantics of sort are pretty well nailed down. Please reopen if you disagree.