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 10, 2018 in Python by aryya
• 7,440 points
359 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,120 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,770 points

closed Oct 3, 2018 by Priyaj 870 views
0 votes
1 answer

How can I expose callbacks to Fortran using Python

The code that I've written below. The ...READ MORE

answered Aug 23, 2018 in Python by aryya
• 7,440 points
586 views
0 votes
1 answer
0 votes
2 answers

How can I write a program to add two numbers using functions in python?

there is sum() function as a built ...READ MORE

answered Oct 24, 2020 in Python by anonymous
14,863 views
+2 votes
4 answers

How can I replace values with 'none' in a dataframe using pandas

Actually in later versions of pandas this ...READ MORE

answered Aug 13, 2018 in Python by bug_seeker
• 15,550 points
38,991 views
+2 votes
2 answers

How can I plot a k-dsitance graph using python?

Hi there, instead of sklearn you could ...READ MORE

answered Apr 10, 2018 in Python by charlie_brown
• 7,780 points
3,101 views
+2 votes
3 answers

How can I play an audio file in the background using Python?

down voteacceptedFor windows: you could use  winsound.SND_ASYNC to play them ...READ MORE

answered Apr 3, 2018 in Python by charlie_brown
• 7,780 points
8,488 views
0 votes
1 answer

How can I Get Laplacian pyramid using opencv

As far as I can see you ...READ MORE

answered Sep 4, 2018 in Python by Priyaj
• 58,120 points
859 views