RNA-seq 示例工作流程中的 nextflow .collect() 方法

nextflow .collect() method in RNA-seq example workflow

我知道当我们 运行 一个将两个通道作为输入的过程时,我们必须使用 collect(),其中第一个通道有一个元素,第二个通道有 > 1 个元素:


#! /usr/bin/env nextflow

nextflow.enable.dsl=2

process A {

    input:
    val(input1)

    output:
    path 'index.txt', emit: foo

    script:
    """
    echo 'This is an index' > index.txt
    """
}

process B {

    input:
    val(input1)
    path(input2)

    output:
    path("${input1}.txt")

    script:
    """
    cat <(echo ${input1}) ${input2} > \"${input1}.txt\"
    """
}

workflow {

    A( Channel.from( 'A' ) )

    // This would only run for one element of the first channel:
    B( Channel.from( 1, 2, 3 ), A.out.foo )

    // and this for all of them as intended:
    B( Channel.from( 1, 2, 3 ), A.out.foo.collect() )

}

现在的问题是:为什么 nextflow-io (https://github.com/nextflow-io/rnaseq-nf/blob/master/modules/rnaseq.nf#L15) 示例工作流程中的这一行可以在不使用 collect()toList() 的情况下工作?

情况相同,具有一个元素(索引)的通道和具有 > 1(fastq 对)的通道应由同一进程(量化)使用,并且 运行s在所有 fastq 文件上。与我的虚拟示例相比,我缺少什么?

您需要使用永不耗尽通道的 value 工厂创建第一个通道。

您的链接示例 implicitly creates a value channel 这就是它起作用的原因。当您在 A.out.foo 上调用 .collect() 时,也会发生同样的情况。

Channel.from(或更现代的Channel.of)创建一个可以被耗尽的序列通道,这就是为什么AB都只有运行一次。

所以

A( Channel.value('A') )

就是你所需要的。