Skip to content

Add function msprime.mutate(ts) #473

Closed

Description

@jeromekelleher

We need a nice simple way to dump neutral mutations on a tree sequence. What about:

def mutate(tree_sequence, mutation_rate,  model=None):
     """
     Returns a copy of the specified tree sequence with mutations thrown down under the specified model.
     If model is None, the default is simple infinite sites mutations.
     """
     # Do stuff
     return new_tree_sequence

Any thoughts @petrelharp or @molpopgen? I'm trying to keep it simple but leave the door open for more complex mutation in the future with the model argument. Maybe the rate parameter is a mistake though, and all the parameters should be subsumed into the MutationModel?

We can also do a version that takes a table collection as an argument I guess. I would imagine that most mutation models will need the trees though...

Activity

  1. molpopgen commented on May 2, 2018

    @molpopgen
    Member

    This is something that I'd been meaning to bring up. There are a couple of complications, one of which is specific, I think, to forward simulation.

    The first is allowing the mutation rate to vary along the region being simulated. I think this would be handy for forward and backwards simulations.

    The second issue is the idea of "mutate since". For many forward sims, many interesting things involve analyzing the simulation over time. For example, I may wish to get Tajima's D every 10 generations. To do that, I need to simplify and add mutations up to "now", and then add mutations again for the portion of the tree corresponding to [now+1,now+10].

    I'd like to hear your thoughts on this.

  2. petrelharp commented on May 2, 2018

    @petrelharp
    Contributor

    Agree!! The table version I'd think would just load the tables into a ts then write out the tables again after.

    What's the idea for the MutationModel?

  3. petrelharp commented on May 2, 2018

    @petrelharp
    Contributor

    Agree on @molpopgen's suggestions also. Sounds like "mutation since" could be a parameter; varying rates would go into MutationModel?

  4. jeromekelleher commented on May 3, 2018

    @jeromekelleher
    MemberAuthor

    All good ideas, thank @molpopgen and @petrelharp. For varying rates across the sequence, we could provide a "mutation_map" parameter that's analogous to a recombination map. It wouldn't be hard to do, it's basically just two numpy arrays.

    The since or start_time parameter would be no problem at all.

    The idea of a MutationModel is to allow for more complicated models of sequence evolution than simple infinite sites mutations. Presumably these need lots of parameters, and so rather than making the mutate function very complicated with lots of parameters, some of which only apply for different models and so on, we just wrap up the parameters required for these specific models in class the specifies this model.

    So, I guess the main practical question for now is whether the initial version of this should look like:

    mutated_ts = msprime.mutate(ts, mutation_rate)

    or

    mutated_ts = msprime.mutate(ts, msprime.InfiniteSites(mutation_rate))
    

    Does the idea of an overall rate translate to all the different mutation models?

    We also need the concept of an alphabet I think. Currently msprime generations '0'/'1' mutations, but we should also allow for nucleotides. Is this a parameter of the mutation model or the mutate function?

    I'm trying to think ahead to future complications, and you guys know a lot more about this stuff than I do, so I'd really appreciate your thoughts here!

  5. petrelharp commented on May 3, 2018

    @petrelharp
    Contributor

    Does the idea of an overall rate translate to all the different mutation models?

    I think ti does - any reasonable mutation model depends on time; and the mutation rate is just a time scaling. Any unreasonable one can ignore it. =)

    We also need the concept of an alphabet I think.

    I think this is a parameter of the mutation model (sometimes): for an infinite alleles model, the alphabet is infinite, not a parameter.

    A mutation model, seems like, will get the state at the parent node and the length of the branch, and will produce either no mutation or a derived state. I don't think we can think of all the possible parameters for mutation models, so I'd stick with the only required parameter being mutation_rate.

  6. molpopgen commented on May 3, 2018

    @molpopgen
    Member

    Does the idea of an overall rate translate to all the different mutation models?

    Yes. The challenge for the implementer of a mutation model comes from mapping variation in mutation rate back onto the trees. The approach that I use, and that SLiM uses, is to have an overall mutation rate and a series of weights associated with different "mutation classes". Those classes will tend to be something like ([start,stop), details about the kind of mutation to generate). Given that the [start,stop) for these regions will never perfectly overlap with marginal tree [left,right)s, one needs the total time in each marginal tree to re-weight as you go along the sequence.

    We also need the concept of an alphabet I think. Currently msprime generations '0'/'1' mutations, but we should also allow for nucleotides. Is this a parameter of the mutation model or the mutate function?

    Agree with @petrelharp -- this is a property of the model.

    I'm trying to think ahead to future complications, and you guys know a lot more about this stuff than I do, so I'd really appreciate your thoughts here!

  7. petrelharp commented on May 24, 2018

    @petrelharp
    Contributor

    This method should have an option that will keep any existing sites or mutations, instead of overwriting them. (and, perhaps this should be the default?)

    (mentioned in MesserLab/SLiM#8)

    I think we can do this by (1) generating new mutations as usual; (2) sorting, deduplicating, and adding mutation parents.

  8. jeromekelleher commented on May 30, 2018

    @jeromekelleher
    MemberAuthor

    This method should have an option that will keep any existing sites or mutations, instead of overwriting them. (and, perhaps this should be the default?)

    I agree it should have this option, but perhaps not as the default behaviour (seems like this could be surprising behaviour to coalescent simulator users). How about a binary flag overwrite=False by default?

  9. added this to the Release 0.6.0 milestone on Jun 2, 2018
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions