snakemake作业提交的顺序方式

问题描述

我写了一个蛇形管道来执行sortmeRNA 4.2.0版本。管道如下,当我为1个示例运行它时,它可以完美运行:

SAMPLES = ['A']
READS=["R1","R2"]

rule all:
    input: 
        expand("Clean/{exp}.clean.{read}.fastq.gz",exp = SAMPLES,read = READS)

rule sortmeRNA:
    input:
        one = "{SAMPLES}.R1.trimd.fastq.gz",two = "{SAMPLES}.R2.trimd.fastq.gz"
    output:
        one = "Clean/{SAMPLES}.clean.R1.fastq.gz",two = "Clean/{SAMPLES}.clean.R2.fastq.gz"
        
    params:
        bac16s = "rRNA_databases/silva-bac-16s-id90.fasta",bac23s = "rRNA_databases/silva-bac-23s-id98.fasta",acc = "--num_alignments 1 --threads 16 --fastx --other -v"
    message: "---Sorting reads with rRNA databases---"

    shell:'''
        rm -rf {SAMPLES}/kvdb;\
        sortmerna -ref {params.bac16s} -ref {params.bac23s}\
            -reads {input.one} -reads {input.two}\
            --workdir {SAMPLES}\
            {params.acc} && \
            echo "deinterleaving...." &&\
            bash deinterleave_fastq.sh < {SAMPLES}/out/other.fastq {output.one} {output.two} compress && \
            echo "moving log and removing folder.." && mkdir -p Sort_log && mv {SAMPLES}/out/aligned.log Sort_log/{SAMPLES}.log &&\
            rm -rf {SAMPLES}
    '''

最后一部分执行以下操作:

  1. 清除{SAMPLES} / kvdb(如果存在)
  2. 运行sortmeRNA
  3. 检查{SAMPLES} /out/other.fastq
  4. 运行“ deinterleave_fastq.sh”,并将R1和R2放入名为“ Clean”的文件夹中
  5. 将“ aligned.log”移动到Sort_log并将其重命名为{SAMPLES} .log
  6. 删除{SAMPLES}文件夹。

从本质上讲,发生的是,对于每个“样本”,它都会过滤出fastq文件,仅保留所需的输出并清除其他文件夹。

通过以下方式提交:

snakemake -ps sortmeRNAv4.2.0.snakefile --cluster "sbatch -n 1 --time=02:00:00 -c 16" --jobs 1

当我执行以下操作时,就会出现问题:

SAMPLES = ['A','B']

snakemake -ps sortmeRNAv4.2.0.snakefile --cluster "sbatch -n 1 --time=02:00:00 -c 16" --jobs 2

该作业已提交,但出现错误

rm -rf A B

我知道,SAMPLES被A&B代替,因为它尚未生成,并且每次清除文件夹时都无法满足条件。如何修改代码,使每个作业并行运行而不会发生冲突?即在任何给定时间,该命令应仅

批处理命令集

SAMPLES = A,完成流程 SAMPLES = B,完成流程

不要混在一起。

谢谢。

解决方法

这里的问题是输入和输出中的{SAMPLES}是通配符。在外壳程序中,它被视为规则上方定义的全局变量。

您应该在外壳程序部分使用{wildcards.SAMPLES}

rule sortmeRNA:
    input:
        one = "{SAMPLES}.R1.trimd.fastq.gz",two = "{SAMPLES}.R2.trimd.fastq.gz"
    output:
        one = "Clean/{SAMPLES}.clean.R1.fastq.gz",two = "Clean/{SAMPLES}.clean.R2.fastq.gz"
        
    params:
        bac16s = "rRNA_databases/silva-bac-16s-id90.fasta",bac23s = "rRNA_databases/silva-bac-23s-id98.fasta",acc = "--num_alignments 1 --threads 16 --fastx --other -v"
    message: "---Sorting reads with rRNA databases---"

    shell:'''
        rm -rf {wildcards.SAMPLES}/kvdb;\
        sortmerna -ref {params.bac16s} -ref {params.bac23s}\
            -reads {input.one} -reads {input.two}\
            --workdir {wildcards.SAMPLES}\
            {params.acc} && \
            echo "deinterleaving...." &&\
            bash deinterleave_fastq.sh < {wildcards.SAMPLES}/out/other.fastq {output.one} {output.two} compress && \
            echo "moving log and removing folder.." && mkdir -p Sort_log && mv {wildcards.SAMPLES}/out/aligned.log Sort_log/{wildcards.SAMPLES}.log &&\
            rm -rf {wildcards.SAMPLES}
    '''

您还应该避免将通配符命名为全局python变量。您的规则一次只处理一个样本,因此只需将其命名为{sample},然后将SAMPLES留给规则上方定义的python变量即可。