module - 如何在 nextflow dsl2 的同一模块中重复使用同一进程两次,但以不同的名称保存输出?

标签 module process dsl nextflow

我正在构建一个 nextflow 工作流程(DSL2),在同一个模块中,我需要重复使用相同的流程两次,但我使用的语法似乎冒犯了 nextflow,因为它提示该流程已被使用我需要正确地给它起别名,但问题是我不知道如何做。

这是错误

流程“可重用”已被使用 - 如果您需要重用相同的组件,请使用不同的名称包含它或将其包含在不同的工作流上下文中

这是一个有意义的例子:

process ReUsable {
    publishDir "${params.publish_dir}/VF/SZ/${meta}", mode: 'copy', pattern: '*.out'
    container 'bla.1'
    input:
        tuple val(meta), path(input)
    output:
        tuple val(meta), path('one.out'), emit: out1
    script:
        """
        cat ${input} > one.out
        """
}
process ScndStep {
         publishDir "${params.publish_dir}/VF/${meta}", mode: 'copy', pattern: '*sub.out'
    container 'bla.2'
    input:
        tuple val(meta), path(out1)
    output:
        tuple val(meta), path('two.out'), emit: out2
    script:
        """
        sed -i "s/i/o/g" ${out1} > two.out
        """
}
workflow Unite {
      take:
               input
      main:
               out1 = ReUsable(input)
               out2 = ScndStep(out1)
               out3 = ReUsable(out2)
               .SaveAs{three.out}
      emit:
               out1
               out2
               out3

}

显然这不是正确的方法,当我环顾四周时,建议设置一个新模块,然后每次使用不同的名称两次包含可重用模块。然而,在我看来,事情过于复杂化了。这里的重点是让它变得简单,并在同一工作流程中重用相同的流程,已经不必重写 ReUsable2 流程了。 有任何想法吗? 非常感谢

最佳答案

是的 - 最简单的方法是使用 include此关键字。使用module aliases允许您重用具有相同名称的组件,例如:

main.nf的内容:

include { ReUsable as ReUsable1 } from './modules/reusable'
include { ReUsable as ReUsable2 } from './modules/reusable'
include { ScndStep } from './modules/secondstep'


workflow Unite {

      take:
      input_ch

      main:
      input_ch | ReUsable1 | ScndStep | ReUsable2

      emit:
      ReUsable1.out
      ScndStep.out
      ReUsable2.out
}

modules/reusable/main.nf 的内容:

process ReUsable {

    input:
    tuple val(meta), path(input)

    output:
    tuple val(meta), path('one.out'), emit: out1

    script:
    """
    cat ${input} > one.out
    """
}

modules/secondstep/main.nf 的内容:

process ScndStep {

    input:
    tuple val(meta), path(out1)

    output:
    tuple val(meta), path('two.out'), emit: out2

    script:
    """
    sed "s/i/o/g" ${out1} > two.out
    """
}

nextflow.config的内容:

params {

    publish_dir = './results'
}

process {

    withName: ReUsable1 {

        publishDir = [
            path: "${params.publish_dir}/ReUsable1",
            mode: 'copy',
        ]
    }

    withName: ScndStep {

        publishDir = [
            path: "${params.publish_dir}/ScndStep",
            mode: 'copy',
        ]
    }

    withName: ReUsable2 {

        publishDir = [
            path: "${params.publish_dir}/ReUsable2",
            mode: 'copy',
        ]
    }
}

关于module - 如何在 nextflow dsl2 的同一模块中重复使用同一进程两次,但以不同的名称保存输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76730547/

相关文章:

Python 如何列出 python 函数的导入

python - 从 .pyo 文件导入 .pyd 文件(作为 python 模块)时出错

javascript - 是否为每个需求创建了一个 node.js 模块实例?

c# - 如何 - 从进程列表中取消列出我的程序..?

spring-integration - 如何使 RedisQueueMessageDrivenEndpoint 与 IntegrationFlow 配合使用?

haskell - 是否可以使用 Free 在 DSL 中实现多态函数

ruby-on-rails - rails 3 : How to add a module to a model?

c - 如何编译 C 程序以在没有命令框的情况下运行?

c - 子进程中的变量修改

elasticsearch - 在 Elasticsearch 中过滤出分支