Directory 使用目录作为输出时出现Snakemake SyntaxError

Directory 使用目录作为输出时出现Snakemake SyntaxError,directory,output,snakemake,Directory,Output,Snakemake,我想运行一个命令(chipseq greylist),它每次运行一个输入文件时都会输出三个文件。输出文件的名称由命令自动选择。例如: chipseq-greylist --outdir out_dir A.bam 此行将生成三个输出文件:A-greystats.csv、A-greydepth.tsv和A-grey.bed。我感兴趣的是将所有*-grey.bed文件收集到一个目录中,以便以后使用 因为这是我在许多文件上使用的管道的一部分,所以我使用Snakemake来处理所有这些作业。我知道可以

我想运行一个命令(chipseq greylist),它每次运行一个输入文件时都会输出三个文件。输出文件的名称由命令自动选择。例如:

chipseq-greylist --outdir out_dir A.bam
此行将生成三个输出文件:
A-greystats.csv、A-greydepth.tsv和A-grey.bed
。我感兴趣的是将所有
*-grey.bed
文件收集到一个目录中,以便以后使用

因为这是我在许多文件上使用的管道的一部分,所以我使用
Snakemake
来处理所有这些作业。我知道可以将目录指定为output(),这将完全符合我的要求。然而,当我以目录作为输出制定规则时,我得到了一个SyntaxError

from os.path import join

# Globals ---------------------------------------------------------------------

DIR = 'bowtie2/'

# A Snakemake regular expression matching BAM files.
SAMPLES, = glob_wildcards(join(DIR, '{sample,SRR\d+}_sorted_filtered.bam'))

# Rules -----------------------------------------------------------------------

rule all:
    input:
        expand("test/{sample}_sorted_filtered.bam.bai", sample=SAMPLES)

rule samtools_index:
    input:
        "bowtie2/{sample}_sorted_filtered.bam"
    output:
        "test/{sample}_sorted_filtered.bam.bai"
    log:
        "log/test/{sample}.log"
    shell:
        "samtools index {input} &> {log} > {output}"

rule greylist_call:
    input:
        "bowtie2/{sample}_sorted_filtered.bam"
    output:
        directory("greylist")
    log:
        "log/greylist/{sample}.log"
    shell:
        "chipseq-greylist --outdir {output} {input} &> {log}"
请注意,在我的示例中,我必须添加另一个步骤来包含
规则all
的目标文件。这是我在使用
directory()
时发现的另一个问题,因为我找不到为
rule all指定目标的方法。

我得到的错误是:

SyntaxError:并非规则greylist_调用的所有输出、日志和基准文件都包含相同的通配符。但是,为了避免两个或多个作业写入同一个文件,这一点至关重要。文件“Snakefile”,第34行,在

如果在
规则greylist_call
中向输出目录名添加
通配符,则可以消除错误消息

from os.path import join

# Globals ---------------------------------------------------------------------

DIR = 'bowtie2/'

# A Snakemake regular expression matching the forward mate FASTQ files.
SAMPLES, = glob_wildcards(join(DIR, '{sample,SRR\d+}_sorted_filtered.bam'))

# Rules -----------------------------------------------------------------------

rule all:
    input:
        expand("test/{sample}_sorted_filtered.bam.bai", sample=SAMPLES)

rule samtools_index:
    input:
        "bowtie2/{sample}_sorted_filtered.bam"
    output:
        "test/{sample}_sorted_filtered.bam.bai"
    log:
        "log/test/{sample}.log"
    shell:
        "samtools index {input} &> {log} > {output}"

rule greylist_call:
    input:
        "bowtie2/{sample}_sorted_filtered.bam"
    output:
        directory("greylist_{sample}")
    log:
        "log/greylist/{sample}.log"
    shell:
        "chipseq-greylist --outdir {output} {input} &> {log}"
但是,我觉得这违背了将所有文件直接放在同一个文件中的目的,尽管我可能会解决这个问题,但我仍然无法找到强制snakemake运行此规则的方法,因为我无法在
规则all
中指定目标文件

如果您能在snakemake中使用
目录
,或就如何改进这套规则提出任何其他建议,我将不胜感激

谢谢
Anna

我不明白为什么要将文件夹定义为输出。如果不提供命令的实际输出文件,snakemake无法确定shell命令是否按预期工作。因此,如果要在同一目录中生成所有不同的示例文件,只需借助
params

rule greylist_call:
    input:
        "bowtie2/{sample}_sorted_filtered.bam"
    output:
        "output_dir/{sample}-greystats.csv",
        "output_dir/{sample}-greydepth.tsv",
        "output_dir/{sample}-grey.bed"
    params:
        outputDir = "output_dir"
    log:
        "log/greylist/{sample}.log"
    shell:
        "chipseq-greylist --outdir {params.outputDir} {input} &> {log}"
在您的规则all中,您添加了:

expand("output_dir/{sample}-grey.bed", sample=SAMPLES)
这将在同一目录中生成所有文件

如果要在另一个规则中收集此目录中的所有bed文件,请定义如下输入:

input:
    expand("output_dir/{sample}-grey.bed",sample=SAMPLES)
解释您得到的错误:通配符是根据规则中的输出定义的。如果在rule all中请求文件
xxx.bed
,snakemake将找到输出类似
{wildcard}.bed
或文件
xxx.bed
本身的规则。一旦找到规则,snakemake将能够将通配符应用于输入、日志、参数等。。。总之,如果未在输出中定义通配符,则输入、日志或参数(甚至shell命令)中不能有通配符。 这就是为什么它与您的规则一起工作,该规则将
目录(“greylist_{sample}”)
作为输出,即使该规则没有按照您的要求工作