I am new to Reana and trying to run a simple snakemake workflow. Am I correct in assuming that Reana does not support the script:
directive of snakemake? Therefore I am now using shell:
directives to run a python script. Then the direct passing of arguments as in snakemake is not available (e.g. snakemake.input
etc.). How exactly do you pass arguments to the script? The example workflow uses a function in C, I am trying the same here in python:
rule Task3:
input:
"intermediateResult_10.txt",
"intermediateResult_5.txt"
output:
"finalResult.txt"
shell:
"cat {input} > {output}"
rule Task2:
input:
seed = "seed.txt",
script = config["generate_randoms"]
output:
"intermediateResult_{NumberOfRandoms}.txt"
shell:
" python '{input.script}(\"{input.seed}\",\"{output}\")'"
rule Task1:
output:
"seed.txt"
shell:
"echo 42 > {output}"
which calls the script:
#input_file = snakemake.input[0]
#output_file = snakemake.output[0]
#number_of_randoms = snakemake.params.current_NumberOfRandoms
import numpy
#import sys
#input_file = str(sys.argv[1])
#number_of_randoms = int(sys.argv[2])
#output_file = str(sys.argv[3])
def function(input_file,output_file):
number_of_randoms = 5
with open(input_file,"r") as input:
numpy.random.seed(int(input.readlines()[0]))
with open(output_file,"w") as output:
for i in range(number_of_randoms): output.write(f"{numpy.random.random()}\n")
I am very unsure about the syntax here and cannot find any documentation. For completeness here is my reana_snakemake.yaml:
version: 0.8.0
inputs:
files:
- snakemake/python_script.py
directories:
- snakemake
parameters:
input: snakemake/inputs.yaml
workflow:
type: snakemake
file: snakemake/Snakefile
outputs:
files:
- finalResult.txt
and snakemake/inputs.yaml:
generate_randoms: snakemake/python_script.py
This workflow runs without problems locally. reana-client validate
runs fine too, but reana-client run
returns
==> ERROR: Cannot create workflow workflow:
Object of type function is not JSON serializable
I would be very greatful for any tips, suggestions or working examples!