0

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/"

1 Answer 1

1

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}
        """
Sign up to request clarification or add additional context in comments.

1 Comment

thanks, the second script works. I thought the program would produce the directory itself, as it usually does. Many thanks anyway!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.