首页 > 解决方案 > 通过qsub提交时如何确保snakemake规则依赖

问题描述

我正在使用 Snakemake 向集群提交作业。我正面临这样一种情况,即我希望仅在所有其他规则运行后才强制运行特定规则 - 这是因为该作业的输入文件(R 脚本)尚未准备好。

我碰巧在 Snakemake 文档页面上看到了这一点,它声明可以强制执行规则 - https://snakemake.readthedocs.io/en/stable/snakefiles/rules.html#flag-files

我有不同的规则,但为了简单起见,我展示了我的 Snakefile 和下面的最后 2 条规则(rsem_model 和 tximport_rsem)。在我的 qsub 集群工作流程中,我希望tximport_rsem 仅在 rsem_model 完成并且我尝试了“touchfile”方法后才执行,但我无法使其成功运行。

# Snakefile
rule all:
   input:
       expand("results/fastqc/{sample}_fastqc.zip",sample=samples),
       expand("results/bbduk/{sample}_trimmed.fastq",sample=samples),
       expand("results/bbduk/{sample}_trimmed_fastqc.zip",sample=samples),
       expand("results/bam/{sample}_Aligned.toTranscriptome.out.bam",sample=samples),
       expand("results/bam/{sample}_ReadsPerGene.out.tab",sample=samples),
       expand("results/quant/{sample}.genes.results",sample=samples),
       expand("results/quant/{sample}_diagnostic.pdf",sample=samples),
       expand("results/multiqc/project_QS_STAR_RSEM_trial.html"),
       expand("results/rsem_tximport/RSEM_GeneLevel_Summarization.csv"),
       expand("mytask.done")

rule clean:
     shell: "rm -rf .snakemake/"

include: 'rules/fastqc.smk'
include: 'rules/bbduk.smk'
include: 'rules/fastqc_after.smk'
include: 'rules/star_align.smk'
include: 'rules/rsem_norm.smk'
include: 'rules/rsem_model.smk'
include: 'rules/tximport_rsem.smk'
include: 'rules/multiqc.smk'
rule rsem_model:
    input:
        'results/quant/{sample}.genes.results'
    output:
        'results/quant/{sample}_diagnostic.pdf'
    params:
        plotmodel = config['rsem_plot_model'],
        prefix = 'results/quant/{sample}',
        touchfile = 'mytask.done'
    threads: 16
    priority: 60
    shell:"""
          touch {params.touchfile}
          {params.plotmodel} {params.prefix} {output}
        """
rule tximport_rsem:
    input: 'mytask.done'
    output:
        'results/rsem_tximport/RSEM_GeneLevel_Summarization.csv'
    priority: 50
    shell: "Rscript scripts/RSEM_tximport.R"

这是我尝试进行试运行时遇到的错误

snakemake -np
Building DAG of jobs...
MissingInputException in line 1 of /home/yh6314/rsem/tutorials/QS_Snakemake/rules/tximport_rsem.smk:
Missing input files for rule tximport_rsem:
mytask.done

需要注意的一件重要事情:如果我尝试在头节点上运行它,我不必执行“触摸文件”并且一切正常。

我将不胜感激建议和帮助找出解决方法。

提前致谢。

标签: snakemakeqsub

解决方案


只有在规则中的tximport_rsem所有作业完成后才会执行规则rsem_model(基于评论)。mytask.done因此,在这种情况下不需要中间文件。使用规则的输出文件rsem_model对所有样本进行规则tximport_rsem就足够了。

rule rsem_model:
    input:
        'results/quant/{sample}.genes.results'
    output:
        'results/quant/{sample}_diagnostic.pdf',
    shell:
        """
        {params.plotmodel} {params.prefix} {output.pdf}
        """

rule tximport_rsem:
    input: 
         expand('results/quant/{sample}_diagnostic.pdf', sample=sample_names)
    output:
        'results/rsem_tximport/RSEM_GeneLevel_Summarization.csv'
    shell: 
        "Rscript scripts/RSEM_tximport.R"

推荐阅读