3

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.

Timur Shtatland
  • 12,024
  • 2
  • 30
  • 47
mau_who
  • 315
  • 2
  • 13

2 Answers2

2

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}"
    )
Foldager
  • 479
  • 1
  • 4
  • 10
2

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}
        """
Manavalan Gajapathy
  • 3,900
  • 2
  • 20
  • 43