showyourwork / showyourwork

A workflow for reproducible and open scientific articles

Home Page:https://show-your.work

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add tex command for snakefile parameters

nstarman opened this issue · comments

It would be awesome if the params in the snakefile could be accessed by a command similar to \variable.
For example, given the following

CleanShot 2023-09-06 at 22 04 08@2x

In the tex file I would like to write something like

We ran \snakeparameter{simulations["iterations"]} in our simulation.

SYW would then parse the snakefile and save the parameter to a text file so that \snakeparameter{rule[param]} -> \input{output/snakefile/rule/param.txt}.

This is an interesting suggestion. My initial feeling is that this would be pretty non-trivial to add to SYW in a general way, but probably wouldn't be too hard to add manually. I'd probably prefer to add this as an example to the docs (using \variable directly), rather than trying to build it into SYW, but if you think you could make it work simply, please feel free to take a stab!

Just trying to think through the steps:

  1. Make a snakefile folder in output (and the cache)
  2. Using the existing variable detection mechanism determine which files to generate, parsing if the file name starts with output/snakefile/
  3. Parse the file path for [rule] in output/snakefile/[rule]/[param].txt and mkdir that folder
  4. parse the file path for [param] in output/snakefile/[rule]/[param].txt, parse that parameter in the rule's parameter section and save that text to the file. This seems the least trivial portion.

I was imagining something simpler like adding params="params.tex" as an output to the simulation rule above, and then in your script do something like (untested):

with open(snakemake.output["params"], "w") as f:
  f.write(f"\newcommand{{\paramseed}}{{{snakemake.params.seed}}}")
  ...