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,450 points
556 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,100 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,195 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 24, 2018 in Python by aryya
• 7,450 points
939 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 25, 2020 in Python by anonymous
21,441 views
0 votes
0 answers

How can I convert a list to a string using Python?

How can I convert a list to ...READ MORE

Sep 21, 2022 in Python by Samuel
• 460 points
127 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,530 points
97,659 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 4, 2018 in Python by charlie_brown
• 7,720 points
11,675 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,100 points
1,283 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP