bodkan / slendr

Population genetic simulations in R 🌍
https://bodkan.net/slendr
Other
54 stars 5 forks source link

Add utility functions to print commands needed to run back-end scripts on the command-line #127

Closed bodkan closed 1 year ago

bodkan commented 1 year ago

For debugging purposes, it might be useful to have a way to write the "raw" commands which power our msprime() and slim() functions.

I.e., to be able to print the command-line statement behind this R command for some model model:

> msprime(model, sequence_length = 1e6, recombination_rate = 1e-8)

like this:

/Users/mp/Library/r-miniconda-arm64/envs/Python-3.11_msprime-1.2.0_tskit-0.5.4_pyslim-1.0.1/bin/python \
    /var/folders/d_/hblb15pd3b94rg0v35920wd80000gn/T//Rtmphz4YZz/file1322a7db0afbe/script.py  \
    --model /var/folders/d_/hblb15pd3b94rg0v35920wd80000gn/T//Rtmphz4YZz/file1322a7db0afbe \
    --output /var/folders/d_/hblb15pd3b94rg0v35920wd80000gn/T//Rtmphz4YZz/file1322a3482f11c.trees \
    --sequence-length 1000000 \
    --recombination-rate 1e-08

Or, for the slim() back end, to have a way to see this:

> slim(model, sequence_length = 1e6, recombination_rate = 1e-8)

in its raw form as this:

slim   \
    -d 'SAMPLES="/var/folders/d_/hblb15pd3b94rg0v35920wd80000gn/T//Rtmphz4YZz/file1322a6e359498"' \
    -d 'MODEL="/var/folders/d_/hblb15pd3b94rg0v35920wd80000gn/T//Rtmphz4YZz/file1322a7db0afbe"' \
    -d 'OUTPUT_TS="/var/folders/d_/hblb15pd3b94rg0v35920wd80000gn/T//Rtmphz4YZz/file1322aa38033.trees"' \
    -d SPATIAL=F \
    -d SEQUENCE_LENGTH=1e+06 \
    -d RECOMB_RATE=1e-08 \
    -d BURNIN_LENGTH=0 \
    -d SIMULATION_LENGTH=233333 \
    -d 'OUTPUT_LOCATIONS=""' \
    -d COALESCENT_ONLY=T \
    -d MAX_ATTEMPTS=1 \
    /var/folders/d_/hblb15pd3b94rg0v35920wd80000gn/T//Rtmphz4YZz/file1322a7db0afbe/script.slim

These command-line statements are anyway generated by msprime() and slim() internally, so one way to do this would be to add functions like msprime_command() and slim_command() or such that will simply print them instead of running the simulations in R like above by adding verbose = TRUE (i.e. the way these command can be accessed now).

Having this will make it easier to explore the internal Python and Eidos code in slendr, see what it is doing, and potentially discover (and fix) bugs.