0

我正在努力在containsAll()语句中使用 if/else。它在使用 测试时返回正确的true falseprintln(),但是当放入if语句时,它似乎总是评估为真——见下文。

def examine_phenotype(pheno){
  condition_values = \
  Channel
        .fromPath(pheno)
        .splitCsv(header: true, sep: ',')
        .map{ row ->

        def condition  = row.condition

        return condition

        }
        .toList().view()

        println(condition_values.containsAll('control'))

        if(condition_values.containsAll('control')){
        exit 1, "eval true"
        }else{
        exit 1, "eval false"
        }
}

两个不同文件的控制台输出,一个在“条件”列中带有“控制”,一个没有“控制”,这是函数的要点。

[normal, normal, normal, tumor, tumor, tumor]
DataflowInvocationExpression(value=false)
eval true
[control, control, control, tumor, tumor, tumor]
DataflowInvocationExpression(value=true)
eval true

使用collect()而不是toList()其中的每个项目condition_values都用单引号括起来也不能解决问题。线索可能就在其中,DataflowInvocationExpression但我还没有跟上 Groovy 的速度,也不知道如何继续。

4

1 回答 1

0

在函数中测试条件不起作用,但应用filter{}ifEmpty{}能够产生所需的检查:

ch_phenotype = Channel.empty()
if(pheno_path){

        pheno_file = file(pheno_path)
        
        ch_phenotype = examine_phenotype(pheno_file)
        ch_phenotype.filter{ it =~/control/ }
                    .ifEmpty{ exit 1, "no control values in condition column"}
}

def examine_phenotype(pheno){
  Channel
        .fromPath(pheno)
        .splitCsv(header: true, sep: ',')
        .map{ row ->

        def condition  =  row.condition
        return condition

        }
        .toList()
}
于 2021-03-16T12:07:32.667 回答