Utility function to tell SLiM to output coordinates from spatial simulations

r_output_coords(dimensionality = c("x", "xy", "xyz"), ...)

slimr_output_coords(dimensionality = c("x", "xy", "xyz"), ...)

Arguments

dimensionality

What dimensionality should be output? Can be "x", "xy", or "xyz".

...

Other arguments to be passed to r_output

Value

None

Details

Outputs x, y, and z coordinates as separate entries in slimr_results, with names "x", "y", and "z".

Examples

if(slim_is_avail()) {
  test_sim <- slim_script(

    slim_block(initialize(),  {
        initializeSLiMOptions(dimensionality = "xy")
        initializeMutationRate(1e-07)
        initializeMutationType("m1", 0.5, "f", asFloat(0))
        initializeGenomicElementType("g1", m1, asFloat(1))
        initializeGenomicElement(g1, 0, 99999)
        initializeRecombinationRate(1e-08)
    }),

    slim_block(1, late(),  {
        sim.addSubpop("p1", 500)
        p1.individuals.x = runif(p1.individualCount)
        p1.individuals.y = runif(p1.individualCount)
    }),

    slim_block(1, 2000, late(), {
      r_output_coords(dimensionality = "xy", do_every = 10);
    }),

    slim_block(modifyChild(),  {
      child.x = parent1.x + rnorm(1, 0, 0.02)
      while((child.x < asFloat(0)) | (child.x > asFloat(1))) {
        child.x = parent1.x + rnorm(1, 0, 0.02)
      }
      child.y = parent1.y + rnorm(1, 0, 0.02)
      while((child.y < asFloat(0)) | (child.y > asFloat(1))) {
        child.y = parent1.y + rnorm(1, 0, 0.02)
      }
      return(T)
    }),

    slim_block(2000, late(),  {
        sim.outputFixedMutations()
    })
  ) |>
    slim_run()
  slim_results_to_data(test_sim)
}
#> 
#> 
#> Simulation finished with exit status: 0
#> 
#> Success!
#> # A tibble: 400 × 5
#>    type                                    expression     generation name  data 
#>    <chr>                                   <chr>               <int> <chr> <lis>
#>  1 "float [0:499] 0.403293 0.732211 ...\n" sim.subpopula…         10 x     <chr>
#>  2 "float [0:499] 0.734469 0.902523 ...\n" sim.subpopula…         10 y     <chr>
#>  3 "float [0:499] 0.598237 0.553393 ...\n" sim.subpopula…         20 x     <chr>
#>  4 "float [0:499] 0.578933 0.771491 ...\n" sim.subpopula…         20 y     <chr>
#>  5 "float [0:499] 0.501153 0.272912 ...\n" sim.subpopula…         30 x     <chr>
#>  6 "float [0:499] 0.440514 0.52441 ...\n"  sim.subpopula…         30 y     <chr>
#>  7 "float [0:499] 0.972029 0.845825 ...\n" sim.subpopula…         40 x     <chr>
#>  8 "float [0:499] 0.571773 0.70612 ...\n"  sim.subpopula…         40 y     <chr>
#>  9 "float [0:499] 0.193929 0.600441 ...\n" sim.subpopula…         50 x     <chr>
#> 10 "float [0:499] 0.844084 0.34089 ...\n"  sim.subpopula…         50 y     <chr>
#> # ℹ 390 more rows