0

我有一个 nextflow 过程,它输入多个文件做一些事情,然后输出一些文件。在此过程中,我删除了条件中的空文件。

    process imputation {
    input:
    set val(chrom),val(chunk_array),val(chunk_start),val(chunk_end),path(in_haps),path(refs),path(maps) from imp_ch
    output:
    tuple val("${chrom}"),path("${chrom}.*") into imputed
    script:
    def (haps,sample)=in_haps
    def (haplotype, legend, samples)=refs
    """
    impute4 -g "${haps}" -h "${haplotype}" -l "${legend}" -m "${maps}" -o "${chrom}.imputed.chunk${chunk_array}" -no_maf_align -o_gz -int "${chunk_start}" "${chunk_end}" -Ne 20000 -buffer 1000 -seed 54321
    if [[ \$(gunzip -c "${chrom}.imputed.chunk${chunk_array}.gen.gz" | head -c1 | wc -c) == "0"]]
    then
     rm "${chrom}.imputed.chunk${chunk_array}.gen.gz"
    else
     qctools -g "${chrom}.imputed.chunk${chunk_array}.gen.gz" -snp-stats -osnp "${chrom}.imputed.chunk${chunk_array}.snp.stats"
    fi
    """
    }

该过程工作正常。该impute4程序提供*gen.gz文件的输出,其中一些可能是空的。因此,添加了 if 语句以删除那些空文件,因为qctools无法读取空文件并且进程崩溃。问题是,现在我收到错误:

Missing output file(s) `chr16*` expected by process `imputation (165)` (note: input files are not included in the default matching set)

我该如何解决这个问题。有什么帮助吗?

4

2 回答 2

1

使用用户 jfy133 建议的可选模式将是解决问题的一种方法。在任何情况下,您都可能希望将这两个命令拆分为不同的进程。

您还可以存储您在 if 子句中使用的行数或测试语句,并在运行之前在第一个进程的输出通道上使用 nextflowfilter或运算符branchqctools

过滤器

Channel
    .from( 1, 2, 3, 4, 5 )
    .filter { it % 2 == 1 }

分公司

Channel
    .from(1,2,3,40,50)
    .branch {
        small: it < 10
        large: it > 10
    }
    .set { result }

 result.small.view { "$it is small" }
 result.large.view { "$it is large" }

您的解决方案可能看起来像这样

process imputation {
    input:
        ...
    output:
        env(isempty), file(other), file(output) into imputed

    script:
        def (haps,sample)=in_haps
        def (haplotype, legend, samples)=refs
        """
        impute4 <your parameters>
        isempty=\$(gunzip -c "${chrom}.imputed.chunk${chunk_array}.gen.gz" | head -c1 | wc -c)
        """
}

filtered_imputed = imputed.filter { empty: it[0] > 0 }

process qctools {
    input:
        val(isempty), <your input> from filtered_imputed
    output:
        <your desired output> into qctools_output

    script:
    """
    qctools <your parameters>
    """
"""
于 2021-08-09T14:14:35.893 回答
0

这种nextflow模式会有帮助吗?

精简版:

process foo {
  output:
  file 'foo.txt' optional true into foo_ch

  script:
  '''
  your_command
  '''
}

基本上,通过指定输出是可选的,如果它没有找到任何定义的输出 glob,则该过程不会失败。

但是,根据输出文件的数量,您可能希望在输出声明中更具体地说明需要哪种输出文件以及哪些是可选的,以确保如果所有命令都失败(无论出于何种原因)您的进程仍然失败

于 2021-05-27T08:39:43.990 回答