Nextflow 平面图未按预期执行

Nextflow flatmap not executing as expected

我有一本字典"data"。我需要将一个键值对解析为一个过程。最终结果应如下所示:

carcode=somename
params={minimum=3000, ignore=60, maximum_A=2500, maximum_B=500}
carcode=somename2
params={minimum=5000, ignore=100, maximum_A=3500, maximum_B=22500}

我写了这段代码,它使用硬编码值而不是变量"it"我会在代码中指出它。

data = [
    "a" : "A",
    "b" : "B",
    "c" : [
        "somename":[
            "z" : "Z",
            "y" : "Y",
            "params" :[
                "minimum": "3000",
                "ignore": "60",
                "maximum_A": "2500",
                "maximum_B": "500"
            ]
        ],

        "somename2":[
            "z" : "Z",
            "y" : "Y",
            "params" :[
                "minimum": "5000",
                "ignore": "100",
                "maximum_A": "3500",
                "maximum_B": "22500"
            ]
        ]
    ]
]

carcodes = Channel.from(data.c.keySet())
transform_carcodes = carcodes.flatMap { it ->  [it] }
//HERE
results = transform_carcodes.flatMap { it ->  [barcode: it, params: data.c."somename".params] }
//HERE
results.subscribe onNext: { println it }

目前输出获得了正确的键,但使用了硬编码键的值:

carcode=somename
params={minimum=3000, ignore=60, maximum_A=2500, maximum_B=500}
carcode=somename2
params={minimum=3000, ignore=60, maximum_A=2500, maximum_B=500}

为什么我做 params: data.c.it.params 时它不起作用?

我得到输出:Cannot get property 'params' on null object

我试过了toString(it)

此外,一旦获得输出,我如何将这个 k/v 对传递给进程,并为每个 k/v 对生成一个新进程?

process{
    container "python:3"

    script:
    """
    python3 some_file.py <key> <value>
    """
}

什么时候 运行 这个进程应该产生:

python3 some_file.py somename {minimum=3000, ignore=60, maximum_A=2500, maximum_B=500}
python3 some_file.py somename2 {minimum=3000, ignore=60, maximum_A=2500, maximum_B=500}

如果您这样做 data.c.it.params,则 it 将被视为嵌套映射中的另一个键。一旦不存在这样的键,您就会得到 params 键的空值。

构建您想要的结果的代码可能类似于

def data = [....]

data.c.each{ k, v -> 
  "python3 some_file.py $k {${v.params.collect{ "$it.key=$it.value" }join(', ')}}".execute().text
}

每个字符串呈现为

python3 some_file.py somename {minimum=3000, ignore=60, maximum_A=2500, maximum_B=500}
python3 some_file.py somename2 {minimum=5000, ignore=100, maximum_A=3500, maximum_B=22500}

在 Nextflow 中,我是这样处理这个问题的:

诀窍是使用 c[it] 而不是 c.it

carcodes = Channel.from(data.c.keySet())
transform_carcodes = carcodes.flatMap { it ->  [it] }
results = transform_carcodes.flatMap { it ->  [ [it, data.c[it].params] ] }

process A{
    echo true

    input:
    set x,y from results

    script:
    """
    python3.7 run_me.py ${x} \'${y}\'
    """

}

run_me.py

import sys

print("First:")
print(sys.argv[1])
print("Second:")
print(sys.argv[2])

并且输出:

[15/aec54c] process > A (1) [100%] 2 of 2 ✔
First:
somename
Second:
[minimum=3000, ignore=60, maximum_A=2500, maximum_B=500]

First:
somename2
Second:
[minimum=5000, ignore=100, maximum_A=3500, maximum_B=22500]