Hi Soumitra,
You can also accomplish this using my new R package {slimr}. I just whipped up a minimal spatial simulation example and posted it here to give you an example:
https://rdinnager.github.io/slimr_resources/slimr_animating_a_simple_spatial_simulation.html. {slimr} makes it easy to write a SLiM script in R, run them, and get data in and out of them (see this
preprint for more details on the motivation; and here is the
package website). You would have to translate your simulation into slimr code though, but it is pretty straightforward: Just wrap your SLiM blocks in calls to `slim_block`, and then wrap up all you slim_blocks into a `slim_script` call. Here is a minimal example from the above linked vignette:
N <- 100
## minimal spatial sim
spat_sim <- slim_script(
slim_block(initialize(), {
initializeSLiMOptions(dimensionality = "xy")
initializeMutationRate(1e-7)
initializeMutationType("m1", 0.5, "f", 0.0)
initializeGenomicElementType("g1", m1, 1.0)
initializeGenomicElement(g1, 0, 100000 - 1)
initializeRecombinationRate(1e-8)
}),
slim_block(1, early(), {
sim.addSubpop("p1", !!N)
sim.addSubpop("p2", !!N)
p1.setSpatialBounds(c(0, 0, 1, 1))
p2.setSpatialBounds(c(0, 0, 1, 1))
p1.individuals.setSpatialPosition(p1.pointUniform(!!N))
p2.individuals.setSpatialPosition(p2.pointUniform(!!N))
}),
slim_block(1, 1000, late(), {
inds = sim.subpopulations.individuals
location = inds.spatialPosition
## move around a bit
inds.setSpatialPosition(p1.pointReflected(sim.subpopulations.individuals.spatialPosition +
rnorm(inds.size() * 2, 0, 0.01)))
slimr_output_full() ## <- this bit is unique to slimr, it is how you get data out of SLiM into R
}),
slim_block(modifyChild(), {
child.setSpatialPosition(parent1.spatialPosition)
return(T)
})
)
There is also an experimental function in the package to convert SLiM code into slimr syntax (as_slimr_script()), but there are still some edge cases where it doesn't work. If you are interested in trying out the package, feel free. If you run into any problems just post an issue on the github page. I intend to add functions to automatically generate animation sometime soon. Cheers.
Also, hi Martin! I recently saw your twitter posts about slendr and have been meaning to reach out to you about it soon. I feel like our respective, independently developed packages have different enough goals to coexist, but perhaps we might consider combining our efforts in some way in the future?
Russell Dinnage