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 ariaholic
• 7,320 points
92 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
• 56,140 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,670 points

closed Oct 3, 2018 by Priyaj 156 views
0 votes
1 answer
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 ariaholic
• 7,320 points
83 views
0 votes
1 answer
0 votes
1 answer

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

def add(a,b):      return a + b #when i call ...READ MORE

answered May 20 in Python by Mohammad
• 1,400 points
15 views
+2 votes
2 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,300 points
3,290 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,710 points
907 views
0 votes
1 answer

How can I write nested dictionaries to a csv file?

You can use the pandas library to ...READ MORE

answered Apr 17, 2018 in Python by anonymous
82 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,710 points
1,097 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
• 56,140 points
159 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.