英文:
why I got Cannot invoke method view() on null object
问题
I got "Cannot invoke method view() on null object" 错误,我的代码如下:
workflow parsefq {
  take: samplesheet
  main:
  Channel.fromPath( samplesheet )
         .splitCsv ( header:true, sep:'\t' ) // dict: [sample:test1, fqdir:xxx, barcode: 10, 11]
         .map { create_fastq_channel(it) }   //[test1, [fq1, fq2]]
         .set {reads}
  emit: reads
}
def create_fastq_channel(LinkedHashMap row) {...return [row.sample, fq1s, fq2s]}
workflow {
  ch_input = file(params.input)
  parsefq (ch_input)
         .set {ch_fq}
         .view()      //在这里出错
}
英文:
why I got Cannot invoke method view() on null object,,,
my code is like:
workflow parsefq {
  take: samplesheet
  main:
  Channel.fromPath( samplesheet )
         .splitCsv ( header:true, sep:'\t' ) // dict: [sample:test1, fqdir:xxx, barcode: 10, 11]
         .map { create_fastq_channel(it) }   //[test1, [fq1, fq2]]
         .set {reads}
  emit: reads
}
def create_fastq_channel(LinkedHashMap row) {...return [row.sample, fq1s, fq2s]}
workflow {
  ch_input = file(params.input)
  parsefq (ch_input)
         .set {ch_fq}
         .view()      //got error on this
}
答案1
得分: 1
因为set操作符只会返回null,所以你会收到上述错误。它的主要目的是为通道分配一个变量名。通常,我们在一系列通道操作的最后使用set操作符。如果我们不需要对输出应用任何转换,可以使用=赋值操作符来分配通道名称:
workflow {
    ch_input = file(params.input)
    ch_fq = parsefq(ch_input)
    ch_fq.view()
}
英文:
You get the error above because the set operator just returns null. It is intended only to assign a variable name to a channel. Usually we use the set operator at the end of a chain of channel operations. If we don't need to apply any transformations to the output, we can just assign a channel name using the = assignment operator:
workflow {
    ch_input = file(params.input)
    ch_fq = parsefq(ch_input)
    ch_fq.view()
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论