output tree sequence for subset of individuals

22 views
Skip to first unread message

Débora Brandt

unread,
Jun 25, 2024, 6:39:35 AM (8 days ago) Jun 25
to slim-discuss
Hi,

Maybe this is a simple question and I just missed it while reading the manual, but... Is it possible to output only a subset of the simulated individuals into a tree sequence?

Thank you in advance and thanks for developing SLim!
Best,
Débora

Ben Haller

unread,
Jun 25, 2024, 10:44:25 AM (8 days ago) Jun 25
to Débora Brandt, slim-discuss
Hi Débora,

SLiM always outputs the whole tree sequence.  That said, though, I did see a cute trick in a model I was looking at just today (by Perry Xu at Cornell); typing into this message (i.e., the below is untested code and might contain typos), it looked like this IIRC:

sim.treeSeqRememberIndividuals(inds_I_want);
sim.killIndividuals(sim.subpopulations.individuals);
sim.treeSeqOutput(...);

So, remember the individuals you want, then kill everybody, then output the tree-seq file.  Since treeSeqOutput() performs a simplify, the individuals you didn't remember get stripped away prior to writing.  Seems like it ought to work fine, if that is the result you want.  Maybe Peter will have more thoughts on this approach?  I haven't tried it myself, but it seems like it ought to work, and I guess it has been working for Perry.  :->

In any case you can always subset down to the individuals you want on the Python side.  :->

Happy modeling!

Cheers,
-B.

Benjamin C. Haller
Messer Lab
Cornell University


Débora Brandt wrote on 6/25/24 11:39 AM:
--
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/2ff63940-b337-4849-9def-1c9961f08cd2n%40googlegroups.com.

Peter Ralph

unread,
Jun 25, 2024, 11:57:52 AM (8 days ago) Jun 25
to Ben Haller, Débora Brandt, slim-discuss
That looks good to me, as long as killIndividuals removes them right away? We didn't have a way to do this because storing more individuals takes relatively little extra space (ie output size is almost logarithmic in sample size), and in many applications it's helpful to use the output of one simulation to get lots of pseudoreplicate samples.

P

Ben Haller

unread,
Jun 26, 2024, 4:17:38 AM (7 days ago) Jun 26
to Peter Ralph, Débora Brandt, slim-discuss
Yep, killIndividuals() removes the individuals from the subpopulation immediately.  So this approach ought to work in nonWF models; in WF models, you can't call killIndividuals() (because the population size is constant), so in that case you'd need to narrow down on the Python side, which isn't hard to do.


Cheers,
-B.

Benjamin C. Haller
Messer Lab
Cornell University


Peter Ralph wrote on 6/25/24 4:57 PM:
Message has been deleted
Message has been deleted

Débora Brandt

unread,
Jun 28, 2024, 3:21:36 AM (5 days ago) Jun 28
to slim-discuss
Thanks a lot, that might work for me! I will try it. I have been doing the sampling in python, but I'm reaching my cluster's file quota and would like to save some disk space, because I'm running a lot of simulations.

Thanks for the quick and very helpful replies!

Best,
Debora

Miguel de Navascués

unread,
Jun 28, 2024, 3:21:39 AM (5 days ago) Jun 28
to slim-d...@googlegroups.com
Hi,

What we are doing is "remembering individuals" of the sample, then
setting population size to zero and running an extra generation (WF
model). I guess it is less direct but equivalent to use
sim.killIndividuals().

Miguel
> <https://urldefense.com/v3/__http://messerlab.org/slim/__;!!C5qS4YX3!DbyCvZVbnnTp4iTGUpaY_rnKoUkwJYqcSYpgnhKI6cCmOERzYzzgJkw2CGdkOErOI6h_wgepk6AmRd9gXqpvGi1rfA$>
> ---
> 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
> <mailto:slim-discuss...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/slim-discuss/2ff63940-b337-4849-9def-1c9961f08cd2n%40googlegroups.com <https://urldefense.com/v3/__https://groups.google.com/d/msgid/slim-discuss/2ff63940-b337-4849-9def-1c9961f08cd2n*40googlegroups.com?utm_medium=email&utm_source=footer__;JQ!!C5qS4YX3!DbyCvZVbnnTp4iTGUpaY_rnKoUkwJYqcSYpgnhKI6cCmOERzYzzgJkw2CGdkOErOI6h_wgepk6AmRd9gXqob7grANA$>.
>
>
> --
> SLiM forward genetic simulation: http://messerlab.org/slim/
> <https://urldefense.com/v3/__http://messerlab.org/slim/__;!!C5qS4YX3!DbyCvZVbnnTp4iTGUpaY_rnKoUkwJYqcSYpgnhKI6cCmOERzYzzgJkw2CGdkOErOI6h_wgepk6AmRd9gXqpvGi1rfA$>
> ---
> 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
> <mailto:slim-discuss...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/slim-discuss/f8b8a969-4665-d2ed-791d-25f0eee88045%40mac.com <https://urldefense.com/v3/__https://groups.google.com/d/msgid/slim-discuss/f8b8a969-4665-d2ed-791d-25f0eee88045*40mac.com?utm_medium=email&utm_source=footer__;JQ!!C5qS4YX3!DbyCvZVbnnTp4iTGUpaY_rnKoUkwJYqcSYpgnhKI6cCmOERzYzzgJkw2CGdkOErOI6h_wgepk6AmRd9gXqqEZakoeQ$>.
>
>
> --
> SLiM forward genetic simulation: http://messerlab.org/slim/
> <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
> <mailto:slim-discuss...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/slim-discuss/44ead04b-96ee-43e7-83fe-ab2e9ee7d232%40email.android.com <https://groups.google.com/d/msgid/slim-discuss/44ead04b-96ee-43e7-83fe-ab2e9ee7d232%40email.android.com?utm_medium=email&utm_source=footer>.

--
Miguel de Navascués

UMR CBGP, INRAE
Centre de Biologie pour la Gestion des Populations
755 avenue du campus Agropolis, CS30016
34988 Montferrier-sur-Lez cedex (France)

miguel.navascues AT inrae.fr
@Miguel_de...@mastodon.online

https://www6.montpellier.inrae.fr/cbgp_eng/Staff/Permanent-staff/de-Navascues

Sign the PCI Manifesto for free open access to scientific publications!
https://peercommunityin.org/pci-manifesto/

Débora Brandt

unread,
Jun 28, 2024, 3:21:43 AM (5 days ago) Jun 28
to slim-discuss
Thanks, that is very helpful! I might try to use that trick.
I just wanted to add a note that I actually found that my tree sequence files for a simulation with  10x more individuals were about 10x larger (700kb for 2k individuals, 7Mb for 20k individuals), so that will actually make a big difference for me in terms of storage, especially if I'm only sampling a fraction of the whole population in both cases (eg 100 individuals from each).

Thanks for the quick replies and great support!

Best,
Debora
On Wednesday, June 26, 2024 at 9:17:38 AM UTC+1 Ben Haller wrote:
Reply all
Reply to author
Forward
0 new messages