访问ru中的嵌套配置变量

2024-10-02 12:32:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我不熟悉Snakemake,并试图弄清楚嵌套配置值是如何工作的。我已经创建了以下配置文件。。。在

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

…在我的蛇档案里遵守这条规则。在

^{pr2}$

然后我想通过调用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只支持访问顶级变量?在


Tags: ofinjsonthat配置文件familyvariablefa
1条回答
网友
1楼 · 发布于 2024-10-02 12:32:42

解决这个问题的一种方法是使用^{}并解析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}"

相关问题 更多 >

    热门问题