Skip to content

Sort using mutation.parent property #27

Closed

Description

@petrelharp

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.

Activity

  1. jeromekelleher commented on Jul 10, 2018

    @jeromekelleher
    Member

    Probably not for 0.6.1 I'd say --- shall we create a 0.6.2 milestone and add it to that?

  2. hyanwong commented on Nov 14, 2019

    @hyanwong
    Member

    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.

  3. hyanwong commented on Dec 4, 2019

    @hyanwong
    Member

    Ping @Chris1221 as an issue that could probably be tackled along with #117 (I would find it useful if this issue were solved)

  4. Chris1221 commented on Dec 4, 2019

    @Chris1221

    Great, thank you @hyanwong, I'll take a look in the next little while. :)

  5. petrelharp commented on Dec 5, 2019

    @petrelharp
    ContributorAuthor

    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)?

  6. hyanwong commented on Dec 5, 2019

    @hyanwong
    Member

    @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
    
  7. hyanwong commented on Dec 5, 2019

    @hyanwong
    Member

    NB - once fixed, remember to remove the docs noting this problem, on line 653 of docs/data-model.rst

  8. Chris1221 commented on Dec 5, 2019

    @Chris1221

    Thanks @hyanwong, I was thinking of asking for an example of the failure -- this will help me tremendously to get started.

  9. jeromekelleher commented on Sep 29, 2020

    @jeromekelleher
    Member

    Closing this, as the semantics of sort are pretty well nailed down. Please reopen if you disagree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions