Snakefile的位置重要吗?

时间:2019-05-17 10:42:45

标签: snakemake

我绝对是蛇术的初学者。我正在学习时正在建立管道。我的问题是,Snakefile是否与我要处理NameError的数据文件一起放置:但是如果我将Snakefile移至父目录并编辑input:和output的路径信息,则代码有效。我想念什么?

rule sra_convert:
    input:
        "rna/{id}.sra"
    output:
        "rna/fastq/{id}.fastq"
    shell:
        "fastq-dump {input} -O {output}"

当我使用

运行时,以上代码可以正常工作
snakemake -p rna/fastq/SRR873382.fastq

但是,如果我将文件移动到SRR873382.sra文件所在的“ rna”目录并按如下所示编辑代码

rule sra_convert:
    input:
        "{id}.sra"
    output:
        "fastq/{id}.fastq"
    message:
        "Converting from {id}.sra to {id}.fastq"
    shell:
        "fastq-dump {input} -O {output}"

并运行

snakemake -p fastq/SRR873382.fastq

我收到以下错误

Building DAG of jobs...
Job counts:
    count   jobs
    1   sra_convert
    1
RuleException in line 7 of /home/sarc/Data/rna/Snakefile:
NameError: The name 'id' is unknown in this context. Please make sure that you defined that variable. Also note that braces not used for variable access have to be escaped by repeating them, i.e. {{print $1}}

解决方案

rule sra_convert:
    input:
        "{id}.sra"
    output:
        "fastq/{id}.fastq"
    message:
        "Converting from {wildcards.id}.sra to {wildcards.id}.fastq"
    shell:
        "fastq-dump {input} -O {output}"

以上代码运行正常,没有错误

1 个答案:

答案 0 :(得分:0)

我相信,回答您实际问题的最佳来源是:

https://snakemake.readthedocs.io/en/stable/snakefiles/rules.html#wildcards

  

如果规则的输出与请求的文件匹配,则子字符串匹配   通配符传播到输入文件和变量   通配符,在shell命令中也使用通配符。通配符   可以使用与输入和输出相同的方式访问对象,即   如上所述。