user3224522
user3224522

Reputation: 1149

Snakemake: output files in one output directory

The program I am running requires only the directory to be specified in order to save the output files. If I run this with snakemake it is giving me error:

IOError: [Errno 2] No such file or directory: 'BOB/call_images/chrX_194_1967_BOB_78.rpkm.png'

My try:

rule all:
    input:
        "BOB/call_images/"

rule plot:
    input:
        hdf="BOB/hdf5/analysis.hdf5",
        txt="BOB/calls.txt"
    output:
        directory("BOB/call_images/")
    shell:
        """
        python someprogram.py plotcalls --input {input.hdf} --calls {input.txt} --outputdir {output[0]}
        """

Neither this version works:

output:
     outdir="BOB/call_images/"

Upvotes: 0

Views: 1673

Answers (1)

Marmaduke
Marmaduke

Reputation: 591

Normally, snakemake will create the output directory for specified output files. The snakemake directory() declaration tells snakemake that the directory is the output, so it leaves it up to the rule to create the output directory.

If you can predict what the output files are called (even if you don't specify them on the command line), you should tell snakemake the output filenames in the output: field. EG:

rule plot:
    input:
        hdf="BOB/hdf5/analysis.hdf5",
        txt="BOB/calls.txt"
    output:
        "BOB/call_images/chrX_194_1967_BOB_78.rpkm.png"
    params:
        outdir="BOB/call_images"
    shell:
        """
        python someprogram.py plotcalls --input {input.hdf} --calls {input.txt} --outputdir {params.outdir}
        """

(The advantage of using the params to define the output dir instead of hard coding it in the shell command is that you can use wildcards there)

If you can't predict the output file name, then you have to manually run mkdir -p {output} as the first step of the shell command.

rule plot:
    input:
        hdf="BOB/hdf5/analysis.hdf5",
        txt="BOB/calls.txt"
    output: directory("BOB/call_images")
    shell:
        """
        mkdir -p {output}
        python someprogram.py plotcalls --input {input.hdf} --calls {input.txt} --outputdir {output}
        """

Upvotes: 1

Related Questions