mau_who
mau_who

Reputation: 335

Use wildcard on params

I try to use one tool and I need to use a wildcard present on input.

This is an example:

aDict = {"120":"121" } #tumor : normal


rule all:
 input: expand("{case}.mutect2.vcf",case=aDict.keys())


def get_files_somatic(wildcards):
 case = wildcards.case
 control = aDict[wildcards.case]
 return [case + ".sorted.bam", control + ".sorted.bam"]



rule gatk_Mutect2:
    input:
        get_files_somatic,

    output:
        "{case}.mutect2.vcf"

    params:
        genome="ref/hg19.fa",
        target= "chr12",
        name_tumor='{case}'
    log:
        "logs/{case}.mutect2.log"
    threads: 8
    shell:
        " gatk-launch Mutect2 -R {params.genome} -I {input[0]} -tumor {params.name_tumor} -I {input[1]} -normal {wildcards.control}"
        " -L {params.target} -O {output}"

I Have this error:

'Wildcards' object has no attribute 'control'

So I have a function with case and control. I'm not able to extract code.

Upvotes: 3

Views: 738

Answers (2)

Manavalan Gajapathy
Manavalan Gajapathy

Reputation: 4089

You could define control in params. Also {input.target2} in shell command would result in error. May be it's supposed to be params.target?

rule gatk_Mutect2:
    input:
        get_files_somatic,
    output:
        "{case}.mutect2.vcf"
    params:
        genome="ref/hg19.fa",
        target= "chr12",
        name_tumor='{case}',
        control = lambda wildcards: aDict[wildcards.case]
    shell:
        """
        gatk-launch Mutect2 -R {params.genome} -I {input[0]} -tumor {params.name_tumor} \\
            -I {input[1]} -normal {params.control} -L {params.target} -O {output}
        """

Upvotes: 2

Foldager
Foldager

Reputation: 519

The wildcards are derived from the output file/pattern. That is why you only have the wildcard called case. You have to derive the control from that. Try replacing your shell statement with this:

run:
    control = aDict[wildcards.case]
    shell(
        "gatk-launch Mutect2 -R {params.genome} -I {input[0]} "
        "-tumor {params.name_tumor} -I {input[1]} -normal {control} "
        "-L {input.target2} -O {output}"
    )

Upvotes: 2

Related Questions