bodkan / slendr

Population genetic simulations in R 🌍
https://bodkan.net/slendr
Other
54 stars 5 forks source link

Add SLiM's selfing rate function to slendR? #109

Closed ornobalam closed 7 months ago

ornobalam commented 2 years ago

Hi Martin,

We briefly talked about this during the Copenhagen workshop. Here is how I am adding selfing after running the slim() function with method = "gui":

function (void) create_pop(object pop) { pop_id = pop.getValue("pop_id");

if (pop.getValue("parent") ==  "ancestor") {
    log_output("creating " + pop.getValue("pop") + "(p" + pop.getValue("pop_id") + ")");
    sim.addSubpop(pop_id, pop.getValue("N"));
    **get_pop(pop_id).setSelfingRate(0.96);**
} else {
    log_output(
        "split of " + pop.getValue("pop") + "(p" + pop.getValue("pop_id") + ")" +
        " from " + pop.getValue("parent") + "(p" + pop.getValue("parent_id")  + ")"
    );
    sim.addSubpopSplit(pop_id, pop.getValue("N"), pop.getValue("parent_id"));
    **get_pop(pop_id).setSelfingRate(0.96);**

}

This is adding selfing globally to all populations when they're created. We discussed possibly adding an argument inside the population() function to set the selfing rate for each population.

Best, Ornob

bodkan commented 2 years ago

Thank you for the suggestion, Ornob! This will be very easy to do. I'll post an update once I get to it.

It was very nice meeting you!

ornobalam commented 2 years ago

Thank you so much! I am glad this will be simple. It was great talking to you!

Ornob

On Mon, Aug 29, 2022 at 1:43 PM Martin Petr @.***> wrote:

Thank you for the suggestion, Ornob! This will be very easy to do. I'll post an update once I get to it.

It was very nice meeting you!

— Reply to this email directly, view it on GitHub https://urldefense.com/v3/__https://github.com/bodkan/slendr/issues/109*issuecomment-1230642359__;Iw!!BhJSzQqDqA!WFnRcFCl7IVG5YAPiLLhifzbneXLMO-aNxJfYk3v-9BMwbdCR9iGNNzC7s-8rIrDJBSFCRxjz4I5HCcjPwGAfrWq$, or unsubscribe https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/ANKDVSDADKBPEQTL4PGTKKDV3TZCTANCNFSM575WJ3YA__;!!BhJSzQqDqA!WFnRcFCl7IVG5YAPiLLhifzbneXLMO-aNxJfYk3v-9BMwbdCR9iGNNzC7s-8rIrDJBSFCRxjz4I5HCcjP0A6OJ6c$ . You are receiving this because you authored the thread.Message ID: @.***>

bodkan commented 7 months ago

Sooo, as much as this will probably be a disappointment for some, I have decided against adding this feature (already a while ago, actually).

Even if it means narrowing down the set of use cases without hacking on the built-in SLiM script -- which is always possible by spawning a SLiM gui or better by providing a path to a customized slendr SLiM script in compile_model() -- I would prefer to maintain parity between slim() and msprime() wherever possible. Adding engine-specific parameters to either of those functions for relatively rare-case scenarios would make slendr internals much more complex.

Adding support for running all slendr models through msprime() -- which ended up to be a surprisingly popular feature of slendr -- has made me re-evaluate how large of a subset of SLiM's functionality should slendr adopt. The answer is: "much less than I originally envisioned".

That being said, I am still planning to add seamless support for extending the built-in SLiM script from the R side, by plugging in bits of user-defined SLiM code. This won't require changes to slendr's R interface, while making the range of possible SLiM simulations much wider (including the functionality mentioned in this issue).