bodkan / slendr

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

Figure out a more convenient way to coalesce lineages in `ts_recapitate` #67

Closed bodkan closed 7 months ago

bodkan commented 2 years ago

I had to add an emergency implementation of migration matrix for recapitation for an internal project. However, the Python way of specifying list-of-lists is supremely unidiomatic for R and also very inconvenient compared to other slendr interfaces which are much easier to use. There must be a more elegant way to do this which would leverage proper population names.

bodkan commented 2 years ago

How about letting the user specify lists of pairs of population labels like c("NEA", "AFR"), then internally pulling the correct 0-based SLiM/tskit IDs for those populations out of the model object, constructing the list of lists, and feeding it into ts$recapitate(..., migration_matrix = <here>) that happens internally in ts_recapitate?

I need to think about this more and I should also first read up on how msprime specifies these things.

petrelharp commented 2 years ago

Is this issue still pending? I have suggestions, if so.

bhaller commented 2 years ago

Note that in SLiM 3.7 (and in GitHub now) subpopulations can be given a name property, which is persisted in the population table in the tree sequence as metadata. So you should be able to refer to population names symbolically on the Python side.

bodkan commented 2 years ago

@petrelharp: Yes, still pending. I had no time to think about it and would love to hear your thoughts.

@bhaller: This is great to hear! Thanks for letting me now about this. You're right, this should make it very easy to solve this. I will take a look at the appropriate slendr/pyslim/tskit/msprime/reticulate plumbing.

More generally, this is yet another feature that will significantly simplify the SLiM backend code, retiring this little helper function. 🙂 I will add this to my notes on the SLiM 3.7 transition which I'll deal with in one fell swoop in a single PR when SLiM 3.7 is out. Whenever that happens--I'm still in no rush with regards to that.

bhaller commented 2 years ago

Whenever that happens--I'm still in no rush with regards to that.

You may not be in a rush, but I am. :-> It will be released before I go on vacation December 19th, if there is any way I can possibly make that happen. :->

bodkan commented 7 months ago

Closing because coalescing lineages by specifying migration_matrix has been superseded by providing a Demography Python object directly a long while ago.