【问题标题】:Nextflow name collisionNextflow 名称冲突
【发布时间】:2023-02-10 02:57:56
【问题描述】:

我有名称相同但位于不同文件夹中的文件。 Nextflow 将这些文件暂存到同一个工作目录中,从而导致名称冲突。我的问题是如何处理没有重命名文件。例子:

# Example data
mkdir folder1 folder2
echo 1 > folder1/file.txt
echo 2 > folder2/file.txt

# We read from samplesheet
$ cat samplesheet.csv
sample,file
sample1,/home/atpoint/foo/folder1/file.txt
sample1,/home/atpoint/foo/folder2/file.txt

# Nextflow main.nf
#! /usr/bin/env nextflow

nextflow.enable.dsl=2

// Read samplesheet and group files by sample (first column)
samplesheet = Channel
    .fromPath(params.samplesheet)
    .splitCsv(header:true)
    .map {
            sample = it['sample']
            file   = it['file']
            tuple(sample, file)
}
        
ch_samplesheet = samplesheet.groupTuple(by:0)

// That creates a tuple like:
// [sample1, [/home/atpoint/foo/folder1/file.txt, /home/atpoint/foo/folder2/file.txt]]

// Dummy process that stages both files into the same work directory folder
process PRO {

    input:
    tuple val(samplename), path(files)

    output:
    path("out.txt")

    script:
    """
    echo $samplename with files $files > out.txt
    """

}

workflow { PRO(ch_samplesheet) }

# Run it
NXF_VER=21.10.6 nextflow run main.nf --samplesheet $(realpath samplesheet.csv)

...显然导致:

N E X T F L O W  ~  version 21.10.6
Launching `main.nf` [adoring_jennings] - revision: 87f26fa90b
[-        ] process > PRO -
Error executing process > 'PRO (1)'

Caused by:
  Process `PRO` input file name collision -- There are multiple input files for each of the following file names: file.txt

所以现在怎么办?这里的真实世界应用程序是对同一个 fastq 文件进行测序复制,这些文件具有相同的名称,但位于不同的文件夹中,我想将它们提供给一个合并它们的过程。我知道这个 section in the docs 但不能说它有任何帮助或我理解正确。

【问题讨论】:

    标签: nextflow


    【解决方案1】:

    您可以在流程定义中使用 stageAs 选项。

    #! /usr/bin/env nextflow
    nextflow.enable.dsl=2
    
    samplesheet = Channel
        .fromPath(params.samplesheet)
        .splitCsv(header:true)
        .map {
            sample = it['sample']
            file = it['file']
            tuple(sample, file)
         }
        .groupTuple()
        .set { ch_samplesheet }
    
    // [sample1, [/path/to/folder1/file.txt, /path/to/folder2/file.txt]]
    
    process PRO {
        input:
            tuple val(samplename), path(files, stageAs: "?/*")
    
        output:
            path("out.txt")
    
        shell:
            def input_str = files instanceof List ? files.join(" ") : files
            """
            cat ${input_str} > out.txt
            """
    }
    
    workflow { PRO(ch_samplesheet) }
    

    an example from nf-corepath input type docs

    【讨论】:

    猜你喜欢
    • 2017-10-31
    • 2012-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-21
    • 2014-10-14
    • 2010-11-05
    相关资源
    最近更新 更多