3

我尝试使用一种工具,我需要在输入中使用通配符。

这是一个例子:

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}"

我有这个错误:

'Wildcards' object has no attribute 'control'

所以我有一个带有案例和控制的功能。我无法提取代码。

4

2 回答 2

2

通配符派生自输出文件/模式。这就是为什么您只有通配符称为 case。您必须从中获得控制权。尝试用这个替换你的 shell 语句:

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}"
    )
于 2018-03-29T17:56:20.833 回答
2

你可以定义controlparams. 同样{input.target2}在 shell 命令中也会导致错误。也许它应该是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}
        """
于 2018-03-29T18:09:15.323 回答