Snakemake会将资源使用率带到后续规则中

2024-09-21 05:21:13 发布

您现在位置:Python中文网/ 问答频道 /正文

在snakemake中,对于给定的规则,拥有资源使用永久性的最佳方法是什么?这意味着给定规则的resources继承以下规则。一个例子是在分区(例如/dev/shm)中一次限制一个输入bam文件,而随后的规则正在使用它:

samples = ["sample1", "sample2", "sample3"]
motifs = ["motif_1", ... , "motif_n"]

rule all:
    input: expand("output/{sample}.{motif}.out", sample=samples, motif=motifs)

rule copy_bam_to_shm:
    input: "{sample}.bam"
    output: temporary("/dev/shm/{sample}.bam")
    resources: shm_usage = 1
    shell: "cp {input} {output}"

rule process_motif:
    input:
        bam = rules.copy_bam_to_shm.output,
        motif = "{motif}.bed"
    output: "output/{sample}.{motif}.out"
    shell: "run_bed_bam_and_beyond.py {input.bam} {input.bed} > {output}"

我想要的是,copy_bam_to_shm中声明的shm_usage资源约束保持不变,同时我正在为当前示例运行所有后续的process_motif步骤—使用尽可能多的并发作业执行后一个规则。只有在sample1.bam完成之后,sample2.bam才会被复制到/dev/shm并进行处理,依此类推。如果不清楚,请参阅下面的伪代码以了解我需要的行为:

# Pseudocode
for sample in samples
    copy sample.bam to /dev/shm
    for motif in motifs
        process motif (in parallel with as many motifs as possible)
    remove sample.bam from /dev/shm
done

Tags: tosampledevinputoutput规则ruleprocess

热门问题