5

i'm sorry if my question may seem a bit dumb.

So, i'm currently trying to write a workflow on snakemake (my first, as a trainee), i've to automate a couple of steps, those steps dependings all on python scripts already made. My trouble is that the input and outputs of those scripts are folders themselves (and their content corresponding of files linked of the first directory content..).

So far, i did this (which is not working, as we can expect)

configfile: "config.yaml"

rule all:
    input:
        "{dirname}/directory_results/sub_dir2", dirname=config["dirname"]

rule script1:
    input:
        "{dirname}/reference/{files}.gbff", dirname=config["dirname"]
    output:
        "{dirname}/directory_results", dirname=config["dirname"]
    shell:
        "python script_1.py -i {dirname}/reference -o {output}"

rule script2:
    input:
        "{dirname}/directory_results/sub_dir1/{files}.gbff.gff", dirname=config["dirname"]
    output:
        "{dirname}/directory_results/sub_dir2", dirname=config["dirname"]
    shell:
        "python script_2.py -i {dirname}/directory_results/sub_dir1"

As for config.yaml, it's a simple file that i used for now, to put the path of the said "dirname"

dirname:
    Sero_1: /project/work/test_snake/Sero_1

I know that there is much to refactor (i'm still not accustomed to snakemake since, beside the tutorial, it's my first workflow ever made). I also understand that the problem lie probably in the fact that, input can't be directories. I tried a couple of things since a couple of days, and i thought i may ask some advice since i'm struggling

How can i put an input that will permit to use for scripts directories?

Debbah N
  • 91
  • 1
  • 6
  • Please be a bit kinder to yourself :). I am not sure what the question/problem is though... Does [this](https://snakemake.readthedocs.io/en/stable/snakefiles/rules.html#directories-as-outputs) help? – Maarten-vd-Sande Jul 01 '20 at 08:14
  • Yes it may help for the output, i tried that too, but it doesn't work since, scripts are taking as input whole directories :/ – Debbah N Jul 01 '20 at 10:21

1 Answers1

4

If it may help, i solved my rule "script1" by doing:

configfile: "config.yaml"

dirname = config["dirname"]

rule all:
    input:
        expand("{dirname}/directory_results/", "{dirname}/directory_results/subdir2" dirname=dirname)

rule script1:
    input:
        expand("{dirname}/reference/", dirname=dirname)
    output:
        directory(expand("{dirname}/directory_results", dirname=dirname))
    shell:
        "python script_1.py -i {input} -o {output}"

rule script2:
    input:
        rules.script1.output
    output:
        directory(extend("{dirname}/directory_results/sub_dir2", dirname=dirname))
    shell:
        "python script_2.py -i {input}"

As for the config.yaml file:

dirname:
    - /project/work/test_snake/Sero_1
    - /project/work/test_snake/Sero_2
Debbah N
  • 91
  • 1
  • 6