正确访问cluster_config'__default__'值

时间:2017-10-13 16:08:34

标签: snakemake

我有一个看起来像这样的cluster.json文件:

{
    "__default__":
    {
        "queue":"normal",
        "memory":"12288",
        "nCPU":"1",
        "name":"{rule}_{wildcards.sample}",
        "o":"logs/cluster/{wildcards.sample}/{rule}.o",
        "e":"logs/cluster/{wildcards.sample}/{rule}.e",
        "jvm":"10240m"
    },
    "aln_pe":
    {
        "memory":"61440",
        "nCPU":"16"
    },
    "GenotypeGVCFs":
    {
        "jvm":"102400m",
        "memory":"122880"
    }
}

在我的snakefile中,我有一些规则尝试访问其参数中的cluster_config对象

params:
  memory=cluster_config['__default__']['jvm']

但这会给我一个'KeyError'

KeyError in line 27 of home/bwubb/projects/Germline/S0330901/haplotype.snake:
'__default__'

这与“__default__”是一个特殊对象有关吗?它在一个视觉上吸引人的字典中打印,其他字母标记为OrderDict,但是当我看到json时,它看起来是一样的。

如果我的json没有问题,那么我应该避免访问'__default __'吗?

1 个答案:

答案 0 :(得分:0)

通过关键字" cluster",而不是

访问默认值
__default__ 

See here in this example in the tutorial:

{
"__default__" :
{
    "account" : "my account",
    "time" : "00:15:00",
    "n" : 1,
    "partition" : "core"
},
"compute1" :
{
    "time" : "00:20:00"
}
}

The JSON list in the URL above and listed above is the one being accessed in this example. It's unfortunate they are not on the same page. To access time, J.K. uses the following call.

#!python

#!/usr/bin/env python3
import os
import sys

from snakemake.utils import read_job_properties

jobscript = sys.argv[1]
job_properties = read_job_properties(jobscript)

# do something useful with the threads
threads = job_properties[threads]

# access property defined in the cluster configuration file (Snakemake >=3.6.0)
job_properties["cluster"]["time"]

os.system("qsub -t {threads} {script}".format(threads=threads, script=jobscript))