question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

add `.individuals` property to `Population` object?

See original GitHub issue

It 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:open
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
isaacovercastcommented, Jun 22, 2020

That’s great, thanks @petrelharp, exactly what I needed!

1reaction
isaacovercastcommented, Jun 19, 2020

+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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found