2017-12-28 44 views
1

Snakemake를 처음 사용하고 중첩 된 구성 값이 작동하는 방법을 알아 내려고했습니다. 내 Snakefile에서 (다른 사람의 사이에서)이 규칙과 함께 갈 ... 다음 설정 파일 ...규칙의 중첩 구성 변수에 액세스

# dummyconfig.json 
{ 
    "fam1": { 
     "numchr": 1, 
     "chrlen": 2500000, 
     "seeds": { 
      "genome": 8013785666, 
      "simtrio": 1776, 
      "simseq": { 
       "mother": 2053695854357871005, 
       "father": 4517457392071889495, 
       "proband": 2574020394472462046 
      } 
     }, 
     "ninherited": 100, 
     "ndenovo": 5, 
     "numreads": 375000 
    } 
} 

을 만들었습니다.

# Snakefile 
rule simgenome: 
    input: 
     "human.order6.mm", 
    output: 
     "{family}-refr.fa.gz" 
    shell: 
     "nuclmm simulate --out - --order 6 --numseqs {config[wildcards.family][numchr]} --seqlen {config[wildcards.family][chrlen]} --seed {config[wildcards.family][seeds][genome]} {input} | gzip -c > {output}" 

그때 snakemake --configfile dummyconfig.json fam1-refr.fa.gz를 호출하여 fam1-refr.fa.gz를 작성하고 싶습니다. 그렇게하면 다음과 같은 오류 메시지가 나타납니다.

Building DAG of jobs... 

rule simgenome: 
    input: human.order6.mm 
    output: fam1-refr.fa.gz 
    jobid: 0 
    wildcards: family=fam1 

RuleException in line 1 of /Users/standage/Projects/noble/Snakefile: 
NameError: The name 'wildcards.family' is unknown in this context. Please make sure that you defined that variable. Also note that braces not used for variable access have to be escaped by repeating them, i.e. {{print $1}} 

그래서 fam1 올바르게 family 와일드 카드의 값으로 인식되고 있지만, 그 변수가 {config[wildcards.family][numchr]} 일처럼 액세스 나타나지 않습니다.

Snakemake는 이러한 방식으로 중첩 된 구성을 통과 할 수 있습니까? 아니면 Snakemake가 최상위 수준 변수에 대한 액세스 만 지원합니까?

답변

1

해결 방법 중 하나는 params을 사용하고 shell 블록 외부의 변수를 해결하는 것입니다.

rule simgenome: 
    input: 
     "human.order6.mm", 
    output: 
     "{family}-refr.fa.gz" 
    params: 
     seed=lambda w: config[w.family]['seeds']['genome'], 
     numseqs=lambda w: config[w.family]['numchr'], 
     seqlen=lambda w: config[w.family]['chrlen'] 
    shell: 
     "nuclmm simulate --out - --order 6 --numseqs {params.numseqs} --seqlen {params.seqlen} --seed {params.seed} {input} | gzip -c > {output}"