pyslim tree_sequence's "individual_populations" does not equal individual's population record in metadata

35 views
Skip to first unread message

Xiong, Tianzhu

unread,
Jul 14, 2021, 11:10:26 PM7/14/21
to slim-discuss
Hi Ben,

I recently found out that in a nonWF model with migration among subpopulations, if I store a treesequence of the entire simulation immediately after moving individuals using subpopulation.takeMigrant(), then these individuals' metadata in pyslim will still have their original subpopulation ID prior to migration, however, if using tree_sequence.individual_populations[individual_id], this subpopulation ID corresponds to that individual's current population (i.e., after migration). 

I wonder if it is designed to be like that in order to trace the origin of individuals, or is it something else? If metadata is supposed to store individual's current profile, isn't it more sensible to store its current subpopulation ID?

The SLiM version I have is 3.6

Many thanks!
Tianzhu
-=-=-=-=-

-----------------
Tianzhu Xiong
Ph.D. Candidate, Mallet Lab
Department of Organismic and Evolutionary Biology
Harvard University
16 Divinity Ave.  Biological Labs
Cambridge, MA 02138

Peter Ralph

unread,
Jul 15, 2021, 12:29:37 AM7/15/21
to Xiong, Tianzhu, slim-discuss
Ah-ha: good question. As you've noted, there's two distinct places to
find out an individual's subpopulation: (a) as the subpopulation
property of metadata, and (b) as the population attribute of its
nodes. It is the latter that is stored in `individual_populations`.
For instance:

ind = ts.individual(0)
metadata_pop = ind.metadata['subpopulation'] # this is (a)
for n_id in ind.nodes:
node = ts.node(n_id)
node_pop = node.population # this is (b)
assert node_pop == ts.individual_populations[0]

And, SLiM always puts nodes (i.e., chromosomes) in the tree sequence,
but only puts in individuals when asked to. So, (a) is recorded at the
end of the simulation, or when the individual is remembered; and (b)
is recorded at birth. They'll differ if the individual is a migrant,
as you've observed. But, I think that it should be the opposite, as
you expect - that metadata should have the current location and
individual_populations should have the origin. Are you sure you've got
things the right way around?

-- peter
> --
> SLiM forward genetic simulation: http://messerlab.org/slim/
> ---
> You received this message because you are subscribed to the Google Groups "slim-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to slim-discuss...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/slim-discuss/CADBWwQmLD3YWvQzaHBCU9Z3PYpFJO%3D4d-aSQs3G-VPf%2BNvrxiA%40mail.gmail.com.

Xiong, Tianzhu

unread,
Jul 15, 2021, 3:50:01 AM7/15/21
to Peter Ralph, slim-discuss
Hi Peter,

Thanks! You are absolutely right, metadata indeed show the current subpopulation ID, while the "individual_populations" will return historical subpopulation ID, at least when the treeseq is saved immediately after migration.

Regarding this, will the method described in the tutorial for sampling individuals from multiple populations occasionally lead to erroneous sampling?
Here is the code from the webpage:
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]]
sample_inds = [np.random.choice(pop, 10, replace=False) for pop in pops]
sample_nodes = []
for samp in sample_inds:
   for i in samp:
      sample_nodes.extend(ts.individual(i).nodes)
sub_ts = ts.simplify(sample_nodes)

Best,
Tianzhu
-----------------
Tianzhu Xiong
Ph.D. Candidate, Mallet Lab
Department of Organismic and Evolutionary Biology
Harvard University
16 Divinity Ave.  Biological Labs
Cambridge, MA 02138

Peter Ralph

unread,
Jul 15, 2021, 1:08:08 PM7/15/21
to Xiong, Tianzhu, slim-discuss
> Regarding this, will the method described in the tutorial for sampling individuals from multiple populations occasionally lead to erroneous sampling?

Ah, good point! I've opened an issue on github:
https://github.com/tskit-dev/pyslim/issues/185
and input on the right thing to do here would be appreciated.

--peter
Reply all
Reply to author
Forward
0 new messages