Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: selection for slim engine. #462

Merged
merged 1 commit into from
Sep 29, 2020

Conversation

grahamgower
Copy link
Member

Not for merging until at least after the next stdpopsim release. Feel free to ignore this for now. (Unless you're feeling bored, in which case feedback is welcome!)

@codecov
Copy link

codecov bot commented Apr 3, 2020

Codecov Report

Merging #462 into master will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #462      +/-   ##
==========================================
+ Coverage   99.65%   99.67%   +0.02%     
==========================================
  Files          29       31       +2     
  Lines        2000     2172     +172     
  Branches      207      253      +46     
==========================================
+ Hits         1993     2165     +172     
  Misses          3        3              
  Partials        4        4              
Impacted Files Coverage Δ
stdpopsim/__init__.py 95.65% <100.00%> (+0.19%) ⬆️
stdpopsim/ext/__init__.py 100.00% <100.00%> (ø)
stdpopsim/ext/selection.py 100.00% <100.00%> (ø)
stdpopsim/slim_engine.py 99.67% <100.00%> (+0.12%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 74565e1...380ab4f. Read the comment docs.

@jeromekelleher
Copy link
Member

Cool! I'm not sure about the ext subpackage --- I guess the idea is that SLiM isn't always going to be available? But, we might be able to do some specialised selective sweeps in msprime too. Maybe just a stdpopsim.selection module? Seems like a pretty core thing so putting it into it's own module seems pretty safe. (This is nitpicking, but I'm very cautious about package structure as this is one thing you really can't change once it's done. I think a flat structure for the external API is much better, unless the namespace is really big.)

@grahamgower
Copy link
Member Author

I was only thinking there needed to be another namespace for stuff that might not be supported in all engines (or for all demographic models?). I don't mind much what it's called. I wasn't sure how much of this would be selection-specific, and how much would be slim-specific. Possibly we'll end up with one selection module that works for msprime and slim, but maybe not. I hope this concrete example provides some useful information about what sort of interface could work on the slim side. It would be really nice if the interface(s) could be engine-agnostic and also "extension feature"-agnostic. To that end, it might be worth simultaneously considering one or more non-selection features.

@jeromekelleher
Copy link
Member

Sounds good. How about we put in a comment in the ext module saying this is experimental and should be revisited before release, once we have a better idea of the overall landscape?

@grahamgower grahamgower marked this pull request as draft April 18, 2020 19:38
@grahamgower grahamgower force-pushed the selection branch 3 times, most recently from fd52965 to f8c2920 Compare April 22, 2020 13:12
@grahamgower grahamgower force-pushed the selection branch 2 times, most recently from 87b5904 to 258e859 Compare May 20, 2020 12:04
@grahamgower
Copy link
Member Author

@grahamgower grahamgower marked this pull request as ready for review June 12, 2020 15:52
@grahamgower grahamgower requested a review from mufernando June 12, 2020 15:52
@petrelharp
Copy link
Contributor

Could you remind us of how to emit the SLiM script to have a look at?

Comment on lines +175 to +182
ts = engine.simulate(
model, contig, samples,
seed=seed,
mutation_types=mutation_types,
slim_scaling_factor=10,
slim_burn_in=10,
# Set slim_script=True to print the script instead of running it.
# slim_script=True,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@petrelharp: pull down the pr branch, then edit this line of docs/selection_example.py, and run it to emit the slim script to stdout.

@mufernando mufernando self-requested a review September 2, 2020 18:13
frequency conditioning.

FIXME: Drawing multiple mutations using the same mutation type causes
erroneous allele frequency calculation in the SLiM code!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you mean here more specifically, @grahamgower?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The allele frequency calculation is a bit fragile. I didn't think too hard about it when I originally wrote it, because my use case was limited to drawing only one mutation. What do you think, should we change this af() function, or disallow multiple drawn mutations of the same mutation type?

// Return the allele frequency of a drawn mutation in the specified population.
// Assumes there's only one mutation of the given type.
function (float$)af(object$ mut_type, object$ pop) {
    mut = sim.mutationsOfType(mut_type);
    if (length(mut) == 0) {
        return 0.0;
    }
    return sim.mutationFrequencies(pop, mut);
}

Copy link
Member

@mufernando mufernando left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great to me. Really amazing work, @grahamgower! What do we need to do to push this over the finish line (apart from more careful documentation)?

@grahamgower
Copy link
Member Author

Hey @mufernando, thanks for taking another look. I think the most important thing is to make sure the python API (all the extended events stuff) is appropriate. We want something that is extensible --- so that we can add new features in the future while keeping backwards compatibility. But if there's nothing obvious that could be improved here, maybe we just get it merged and worry about that if/when the time comes?

(I see you made a comment and then deleted it: I think a simple additional feature could be to accept a starting allele frequency for a drawn mutation)

@grahamgower
Copy link
Member Author

One additional thought @mufernando: what if folks want to define a DFE with a custom h(s) function (where the dominance coefficient is a function of the selection coefficient)? I don't know if this is the normal thing to do for a DFE, but it's not possible in the current PR's API. And actually, it might be tricky to support this in a general way. Any thoughts on how we could allow this?

@grahamgower
Copy link
Member Author

Rebased. @jeromekelleher, would you be able to take a look at the python/API side of things here?

Copy link
Member

@jeromekelleher jeromekelleher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it looks great @grahamgower. I'm not sure about the value of the "ExtendedEvent", but we're being fairly explicit that this is an extension and stuff might change. So, I say we merge this much and start using and building on it!

@grahamgower
Copy link
Member Author

Ok, cool. I'll squash this down, push the "Merge" button, and open some follow up issues.

This supports drawing a mutation, changing it's fitness effects at
a chosen time, and conditioning the simulation on the mutation having a
given frequency in a given population at a given time.

We also support simple DFEs via SLiM's initializeMutationType.
@grahamgower grahamgower merged commit 906f103 into popsim-consortium:master Sep 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants