【问题标题】:Nextflow: how do you pass an output (multiple files) from the publishdir to the next process?Nextflow:如何将输出(多个文件)从发布目录传递到下一个进程?
【发布时间】:2021-09-19 20:04:48
【问题描述】:

我有一个进程生成两个我感兴趣的文件,hitsort.cls 和 contigs.fasta。 我使用 publishdir 输出这些:

process RUN_RE {
    publishDir "$baseDir/RE_output", mode: 'copy'
  
    input:
    file 'interleaved.fq'

    output:
    file "${params.RE_run}/seqclust/clustering/hitsort.cls"
    file "${params.RE_run}/contigs.fasta"

    script:
    """
    some_code

    """

  }

现在,我需要这两个文件作为另一个进程的输入,但我不知道该怎么做。

我已经尝试用

调用这个过程
NEXT_PROCESS(params.hitsort, params.contigs)

同时将输入指定为:

process NEXT_PROCESS {
  
    input:
    path hitsort
    path contigs

但它不起作用,因为只使用基本名称而不是完整路径。基本上我想要的是等待 RUN_RE 完成,然后将它输出的两个文件用于下一个进程。

【问题讨论】:

    标签: process nextflow publishdir


    【解决方案1】:

    最好避免访问publishDir 中的文件,因为:

    文件以异步方式复制到指定目录中,因此在流程执行结束时它们可能不会立即在已发布目录中可用。因此,进程发布的文件必须被其他下游进程访问。

    因此,建议确保您的进程仅访问工作目录中的文件(即./work)。这意味着:最好避免在输入和输出声明中使用绝对路径之类的东西。这也将有助于确保您的工作流程是可移植的。

    nextflow.enable.dsl=2
    
    params.interleaved_fq = './path/to/interleaved.fq'
    params.publish_dir = './results'
    
    process RUN_RE {
    
        publishDir "${params.publish_dir}/RE_output", mode: 'copy'
    
        input:
        path interleaved
    
        output:
        path "./seqclust/clustering/hitsort.cls", emit: hitsort_cls
        path "./contigs.fasta", emit: contigs_fasta
    
        """
        # do something with ${interleaved}...
        ls -l "${interleaved}"
    
        # create some outputs...
        mkdir -p ./seqclust/clustering
        touch ./seqclust/clustering/hitsort.cls
        touch ./contigs.fasta
        """
    }
    
    process NEXT_PROCESS {
    
        input:
        path hitsort
        path contigs
    
        """
        ls -l
        """
    }
    
    workflow {
    
        interleaved_fq = file( params.interleaved_fq )
    
        NEXT_PROCESS( RUN_RE( interleaved_fq ) )
    }
    

    上述工作流块实际上与:

    workflow {
    
        interleaved_fq = file( params.interleaved_fq )
    
        RUN_RE( interleaved_fq )
    
        NEXT_PROCESS( RUN_RE.out.hitsort_cls, RUN_RE.out.contigs_fasta )
    }
    

    【讨论】:

    • Emit 是我一直在寻找的神奇关键字。那并使用 RUN_RE.out 访问这些文件就成功了。
    • 或者,如果您总是需要将这些文件作为一对,那么您可以将其作为一个元组发出,因为这样可以将这两个文件放在一个数据流中。
    猜你喜欢
    • 2023-01-26
    • 1970-01-01
    • 2022-11-02
    • 2020-11-30
    • 1970-01-01
    • 2020-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多