snakemake define folder as output

后端 未结 3 426
予麋鹿
予麋鹿 2021-01-20 01:43

I try to run prokka using snakemake and rule all. In the latter I define all output folders which will be produced by prokka to write the results. Prokka requires a folder t

相关标签:
3条回答
  • 2021-01-20 02:23

    As @JohnnyBD mentioned, your major problem appears to be with rule all output not matching rule prokka. If you still need to use directory as output instead of a file, you may want to use directory() as it better handles edge cases.

    0 讨论(0)
  • 2021-01-20 02:26

    Your example has some issues as your rule all output files do not match your rule prokka output file.

    However, one way to implement what you want to do is to use params to specify the output directory and use that as argument to the flag --outdir {params.outdir}.

    A similar example is shown below:

    PATIENTID_ls = [1,2]
    PREFIX = "contigs500_anno9ref"
    
    rule all:
        input:
            expand("results_{subjectID}_outputfolder/{prefix}.gff",subjectID=PATIENTID_ls, prefix=PREFIX), 
    
    rule prokka:
        input:
            "contigs/contigs.fasta",
        params:
            outdir= "results_{subjectID}_outputfolder",
            prefix= PREFIX,
        output:
            "results_{subjectID}_outputfolder/{prefix}.gff",
        shell:
            "echo '{params.prefix}' > {params.outdir}/{PREFIX}.gff"
    

    You still should specify a file as an output in rule prokka and in rule all. Based on the example on the prokka repo the output file is essentially {outdir}/{prefix}.gff. You can specify that as the output to both rule all and rule prokka without ever directly using it while invoking the command.


    Alternatively even though there does not seem to be a reason for it, you could use a mock file to signify completion of the rule.

    An example would be:

    PATIENTID_ls = [1,2]
    rule all:
        input:
            expand("results_{subjectID}_outputfolder/mockfile.txt",subjectID=PATIENTID_ls), 
    
    rule prokka:
        input:
            "contigs/contigs.fasta",
        params:
            outdir= "results_{subjectID}_outputfolder",
            prefix= "contigs500_anno9ref",
        output:
            "results_{subjectID}_outputfolder/mockfile.txt",
        shell:
            "echo '{params.prefix}' && touch {params.outdir}/mockfile.txt"
    
    0 讨论(0)
  • 2021-01-20 02:37

    You can create a variable refering to your output directory, and call it on the rule:

    outputdir= "your_output_directory"
    
    rule Align_Sequences:
        input: sequence.fasta
        output: outputdir + "/sequence_aligned.fasta"
        shell: "mafft  {input} > {output}"
    
    0 讨论(0)
提交回复
热议问题