Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
870 views
in Technique[技术] by (71.8m points)

python - Parallelizing snakemake rule

Sorry if this is a naive question, but I'm still trying to wrap my head around the intricacies of Snakemake.

I have a directory containing a number of files that I want to apply a rule to in parallel (i.e. I want to submit the same script to the cluster, specifying a different input file for each submission).

I first tried using expand for the input files, but this only resulted in one job submission:

CHROMS = [str(c) for c in range(1, 23)] + ["X"]
rule vep:
    input:
        expand("data/split/chr{chrom}.vcf", 
               chrom=CHROMS)
    output:
        expand("data/vep/split/chr{chrom}.ann.vcf",
               chrom=CHROMS)
    shell:
        "vep "
        "{input} "
        "{output}"

Is there an alternative approach here?

Thank you!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Currently, your workflow indeed consists in applying the "vep" rule only once, where it executes vep with all your inputs and outputs as arguments. I don't know how vep works, but it is likely either failing or not doing what you expect.

You should probably write your rule's input and output without expansion, and drive it using an "all" rule, that does the expand:

CHROMS = [str(c) for c in range(1, 23)] + ["X"]


rule all:
    input:
        expand("data/vep/split/chr{chrom}.ann.vcf",
               chrom=CHROMS)

rule vep:
    input:
        "data/split/chr{chrom}.vcf"
    output:
        "data/vep/split/chr{chrom}.ann.vcf"
    shell:
        "vep "
        "{input} "
        "{output}"

To generate the desired input of the "all" rule, snakemake will determine how many times and how (i.e. with what value for the chrom wildcard) it needs to apply the "vep" rule.

Be sure to put the "all" rule before all other rules.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...