Handling parallelization

Deadly 提交于 2020-01-24 15:34:26

问题


I'm a bit new on snakemake.

Imagine that I have a rule, like the one below (I've set the number of threads to 10).

Is there any way to make snakemake magically handles the parallelization of the loop for in this rule?

rule MY_RULE:
    input:
        input_file=TRAIN_DATA
    output:
        output_file=OUTPUT_DATA
    threads: 10
    run:        
        for f,o in zip(input.input_file, output.output_file):
            DO_SOMETHING_AND_SAVE(f,o)

Thanks


回答1:


I guess your rule could be re-written as (with additional code to make a small self-contained example):

TRAIN_DATA = ['a.txt', 'b.txt', 'c.txt']
OUTPUT_DATA = ['a.out', 'b.out', 'c.out']

files= dict(zip(OUTPUT_DATA, TRAIN_DATA))

wildcard_constraints:
    x= '|'.join([re.escape(x) for x in OUTPUT_DATA])

rule all:
    input:
        expand('{x}', x= OUTPUT_DATA),

rule MY_RULE:
    input:
        input_file= lambda wc: files[wc.x]
    output:
        output_file= '{x}'
    run:        
        DO_SOMETHING_AND_SAVE(input.input_file, output.output_file)

This will run rule MY_RULE for each input/output pair in parallel. Of course, the details depend on what exactly you want to do before and after MY_RULE...



来源:https://stackoverflow.com/questions/58556939/handling-parallelization

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!