Using a demes-format file in SLiM to simulate under a realistic demographic model

20 views
Skip to first unread message

Rodolfo

unread,
Jun 9, 2025, 2:39:32 PMJun 9
to slim-discuss

Hello,

I hope you're doing well. I’m currently working on a simulation project using SLiM and would like to incorporate a realistic demographic model. I have a demographic history defined in a .yaml file following the demes format, and I was wondering if it's possible to use this directly in SLiM.

Could you let me know if SLiM supports importing demes-formatted files, either directly or through a conversion tool or script? If not, what would be the best way to convert such a model into something SLiM can use?

I've been exploring demes-slim, but according to the documentation, this method is currently unavailable and not recommended for use.

Thank you in advance for your help!

Best regards,

Rodolfo


Peter Ralph

unread,
Jun 9, 2025, 3:15:23 PMJun 9
to Rodolfo, slim-discuss
Hello! This would be a nice tool, but AFAIK there is no such thing available.

(Note: you could do this by converting the demes file with msprime to an msprime model, then using stdpopsim to produce a SLiM script, but the latter step is not designed to be general-purpose and the script that's produced is pretty hard to understand, so I'd be worried about introducing hard-to-find errors.)

-peter

From: slim-d...@googlegroups.com <slim-d...@googlegroups.com> on behalf of Rodolfo <rodolfo.a...@gmail.com>
Sent: Monday, June 9, 2025 11:39 AM
To: slim-discuss <slim-d...@googlegroups.com>
Subject: Using a demes-format file in SLiM to simulate under a realistic demographic model
 
--
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 visit https://groups.google.com/d/msgid/slim-discuss/6e6f85a3-c19a-4206-8991-8a68aa9feb56n%40googlegroups.com.

Ben Haller

unread,
Jun 9, 2025, 3:27:04 PMJun 9
to Peter Ralph, Rodolfo, slim-discuss
Agreed, it would be nice.  Perhaps Graham Gower, who wrote demes-slim, might update it at some point?  (Or maybe he'd accept a pull request, if you're motivated and feel like getting derailed into a side project.  :->)

I would also suggest looking at the `slendr` package by Martin Petr.  I don't think it accepts demes files directly (although perhaps that would be a feature request that Martin would be receptive to!), but it does allow for a pretty easy and flexible specification of demography, and can then simulate the specified model using either msprime or SLiM as a back end.

Cheers,
-B.

Benjamin C. Haller
Messer Lab
Cornell University


Peter Ralph wrote on 6/9/25 3:15 PM:

Rodolfo

unread,
Jun 9, 2025, 3:53:05 PMJun 9
to slim-discuss

Yep! At first, I tried something similar: I converted the Demes file into an 'msprime' model and then used 'pyslim' to turn it into a .trees file. However, I’m planning to introduce selection in my simulations, and as far as I know, msprime only supports neutral simulations. That’s why I’m looking for an alternative that would allow me to use the model directly in SLiM without having to go through msprime first. I’m going to take a look at the 'slendr' package to see if it might be suitable for my purposes. Hopefully it is! Thanks!

Best,

Rodolfo 

Martin Petr

unread,
Jun 10, 2025, 9:13:38 AMJun 10
to slim-discuss
Hi all,

Thanks for the ping, Ben.

I'm afraid slendr won't be of much help in this instance. I considered implementing support for Demes at some point in the past but ultimately decided against it. I don't use Demes myself and I was worried about the risk of maintaining something I don't actively use and fully understand in the long-term...

I had a Master's student two years ago who implemented a draft of an R parser and validator for Demes models for her thesis: https://github.com/RacimoLab/demes-r She also wrote a proof-of-concept functionality to then compile a Demes model into a slendr model. The point was to capture the structure of a Demes model as a native R data structure, such as nested lists, and it worked quite nicely (I think her code passed about 90% of validation tests in the Demes spec)... but the package was never published on CRAN, hasn't been maintained since then, and is unlikely to be picked up again. :( 

I suppose you could take a look at that package as a potential starting point, but the way things currently stand, I wonder whether you might actually have a better luck updating Graham's old Demes parser, generating .slim script file from your Demes model, and "injecting" custom selection code into it yourself. The reason I'm saying this is that I seem to remember that Graham's code implemented a fairly straightforward code generation from Demes to SLiM, emitting Eidos code as the parser iterates over various "events" encoded in the Demes file. Which could be a lot simpler to do if you need to just run some simulations (rather than first having to understand and probably even fix a more general-purpose R package).

Cheers,
Martin
Reply all
Reply to author
Forward
0 new messages