How can I map input to output without using dynamic

+1 vote

I have a pipeline that has a problematic rule. I can't use wildcards in the output, and so I am unable to map the input to the output. The problem is Snakemake launch a job for each one of the combinations. However, I the tool outputs the three required files. I was able to sort the problem with 'dynamic', but I would prefer to

mapping: {'a': ['a_1', 'a_2', 'a_3'], 'b': ['b_1', 'b_2', 'b_3']}

rule build:

    input:

        ini=rules.create_ini.output,

        bam=lambda wildcards:

            expand('mappings/{names}.bam', names=mapping[wildcards.cond],

                cond=wildcards.cond)

    output:

        dynamic('tool/{cond}/{names}.tool')

    params: 

        output='{cond}'

    shell:

        '''

        module load tool

        tool build --conf {input.ini} --output {params.output} # < here

        '''

The tool produces three files, not one and Snakemake is launching six jobs instead two.

May 11, 2018 in Python by aryya
• 7,460 points
1,486 views

1 answer to this question.

0 votes

Here am talking about my example you can implement the same for your code.

For the use of dynamic function you have to get an other rule where the input are the dynamic files like this :

rule target :
  input : dynamic('{n}.txt')

rule source:
  output: dynamic('{n}.txt')
  run:
    source_dir = config["windows"]
    source = os.listdir(source_dir)
    for w in source:
      shell("ln -s %s/%s source/%s" % (source_dir, w, w))

Like this Snakemake will know what is has to attribute for the wildcard.

Hint when you use a wildcard you always have to define it. Here calling dynamic in the input of target rule will define the wildcard '{n}'.

answered Aug 8, 2018 by Priyaj
• 58,020 points

Related Questions In Python

0 votes
0 answers

Snakemake: how to map input to output without using dynamic()

I have a pipeline that has a ...READ MORE

Oct 3, 2018 in Python by eatcodesleeprepeat
• 4,710 points

closed Oct 3, 2018 by Priyaj 1,954 views