tskit-dev / pyslim

Tools for dealing with tree sequences coming to and from SLiM.
MIT License
27 stars 23 forks source link

individual_populations gives *birth* locations, not sampling locations #185

Closed petrelharp closed 2 years ago

petrelharp commented 3 years ago

As pointed out by Tianzhu Xiong in the SLiM mailing list, ts.individual_locations gets its information from nodes, and is therefore the birth location; while individual metadata contains the "current" population; these differ if the individual is a migrant.

So, the tutorial currently has

alive = ts.individuals_alive_at(0)
adults = alive[ts.individual_ages[alive] > 2]
pops = [np.where(
           ts.individual_populations[adults] == k)[0] for k in [1, 2]]

but if we want to sample individuals from where they currently (at the end of the simulation) are, which is probably what the user would want, then we would instead do something like (not tested!):

pops = [
   [i for i in adults if ts.individual(i).metadata['subpopulation'] == k]
   for k in [1, 2]
]

Probably individual_locations should be renamed individual_birth_locations or something?

petrelharp commented 2 years ago

I think the thing to do is keep the name the same but document it.