add `.individuals` property to `Population` object?
See original GitHub issueIt is a very common thing to need to (a) first go through the individuals in a tree sequence and find their population, and then (b) subsample according to population. Right now, we might get the list of individuals by population like so:
pop_inds = [[] for _ in range(ts.num_populations)]
for ind in ts.individuals():
pops = [ts.node(n).population for n in ind.nodes]
for pop in set(pops):
pop_inds[pop].append(ind.id)
… and I’ve omitted the error checking enuring no individual has nodes in more than one population. This would be easier if we could do
pop_inds = [pop.individuals for pop in ts.populations()]
This suggestion is somewhat fraught because of the possibility that an individual’s nodes may have different populations (although if they do, it’s probably an error). So, I propose throwing an error if any individual’s nodes have more than one population associated. (This check could be an optional argument, but I can’t think of when this wouldn’t be an error.)
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Population Objects: Interpassive Subjects - SAGE Journals
Abstract. While Foucault described population as the object of biopower he did not investigate the practices that make it possible to know population....
Read more >What is an ADU: Accessory Dwelling Units explained
Accessory Dwelling Units (ADUs) are on the rise -- and with good reason. Learn about what ADUs are and why so many people...
Read more >Carrying Capacity
A population gains individuals by birth and immigration and loses individuals by death and emigration. Biotic Potential. Populations vary in their capacity to ......
Read more >Lesson 5: Estimating Population Size - MEASURE Evaluation
This lesson focuses on ways to estimate and project the population size of a locale. ... The tool assumes that the same number...
Read more >it requires a fundamental extension in morality
The population problem has no technical solution; it requires a fundamental extension ... The more people, the less resources there are for each...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
That’s great, thanks @petrelharp, exactly what I needed!
+1
Hello tskit team. Looking for a way to get
diversity
per population from an msprime simulation. Peter’s code above is already a huge help as it looks like just what I need, but I agree it would be useful to simplify in one of the two ways suggested here. From a user perspective, I think it’s more natural for individuals to be a property of populations, but either way would be fine.Long time msprime/tskit user here. Thanks for this amazing resource and all your hard work!