2017-05-07 24 views
1

這裏是一個config.yaml的短例如:Snakemake:帶有子項目的樣本,如何捕獲它們?

samples: 
    sample1: 
    stranded: True 
    sample2: 
    stranded: False 

正如所看到的,每個樣本具有一個分項(倍數實際上)。但我不知道如何抓住他們。 我的蛇形文件:

configfile: "config.yaml" 

rule all: 
    input: 
    expand("output/{sample}.bam", sample=config['samples']), 

rule one: 
    input: 
    "input/{sample}.bam", 
    output: 
    "output/{sample}.bam", 
    run: 
    if config['samples']["{sample}"]['stranded']: # How catch stranded value ? 
     option = "--stranded", 
    shell(
     'some_command ' 
     ' {option}' 
     ' {input} > {output}' 
    ) 

在此先感謝您的幫助。

Hetica

回答

2

終於,我發現了一個響應,在PARAMS指令使用lambda表達式,並在運行條件:

configfile: "config.yaml" 

rule all: 
    input: 
    expand("output/{sample}.bam", sample=config['samples']), 

rule one: 
    input: 
    "input/{sample}.bam", 
    output: 
    "output/{sample}.bam", 
    params: 
    stranded = lambda wildcards: config['samples'][wildcards.sample]['stranded'], 
    run: 
    stranded = "--stranded" if params.stranded else '' 
    shell(
     'echo ' 
     + stranded + 
     ' {input} > {output};\n' 
     'touch {output}' 
    ) 

這是否可以幫助別人...

相關問題