Nextflow脚本运行报错:未找到变量result的解决咨询
解决Nextflow脚本中"No such variable: result"错误
问题重现
刚学习Nextflow,运行参考脚本时出现No such variable: result错误,相关信息如下:
原脚本代码
#!/usr/bin/env nextflow // Example1 from gist params.str = 'Hello world!' process AFcalc { """ echo '${params.str}' """ } //this is necessary to print the output result.subscribe { println it.trim() }
运行命令
nextflow run example1.nf
错误输出
N E X T F L O W ~ version 22.04.5 Launching `example1.nf` [nostalgic_brahmagupta] DSL2 - revision: 17976728a8 No such variable: result -- Check script 'example1.nf' at line: 15 or see '.nextflow.log' file for more details
日志详情
Oct-02 13:51:35.370 [main] DEBUG nextflow.cli.Launcher - $> nextflow run example1.nf Oct-02 13:51:35.413 [main] INFO nextflow.cli.CmdRun - N E X T F L O W ~ version 22.04.5 Oct-02 13:51:35.446 [main] DEBUG nextflow.cli.CmdRun - Applied DSL=2 by global default Oct-02 13:51:35.460 [main] INFO nextflow.cli.CmdRun - Launching `example1.nf` [nostalgic_brahmagupta] DSL2 - revision: 17976728a8 Oct-02 13:51:35.468 [main] DEBUG nextflow.plugin.PluginsFacade - Setting up plugin manager > mode=prod; plugins-dir=/Users/theodosiou/.nextflow/plugins; core-plugins: nf-amazon@1.7.2,nf-azure@0.13.2,nf-console@1.0.3,nf-ga4gh@1.0.3,nf-google@1.1.4,nf-sqldb@0.4.0,nf-tower@1.4.0 Oct-02 13:51:35.469 [main] DEBUG nextflow.plugin.PluginsFacade - Plugins default=[] Oct-02 13:51:35.474 [main] INFO org.pf4j.DefaultPluginStatusProvider - Enabled plugins: [] Oct-02 13:51:35.474 [main] INFO org.pf4j.DefaultPluginStatusProvider - Disabled plugins: [] Oct-02 13:51:35.476 [main] INFO org.pf4j.DefaultPluginManager - PF4J version 3.4.1 in 'deployment' mode Oct-02 13:51:35.481 [main] INFO org.pf4j.AbstractPluginManager - No plugins Oct-02 13:51:35.511 [main] DEBUG nextflow.Session - Session uuid: ef770a53-e834-4fcd-8ae5-6216009b4ebc Oct-02 13:51:35.511 [main] DEBUG nextflow.Session - Run name: nostalgic_brahmagupta Oct-02 13:51:35.512 [main] DEBUG nextflow.Session - Executor pool size: 8 Oct-02 13:51:35.831 [main] DEBUG nextflow.cli.CmdRun - Version: 22.04.5 build 5708 Created: 15-07-2022 16:09 UTC (18:09 CEST) System: Mac OS X 12.6 Runtime: Groovy 3.0.10 on Java HotSpot(TM) 64-Bit Server VM 17+35-LTS-2724 Encoding: UTF-8 (UTF-8) Process: 50922@LOUKASs-Air [192.168.0.207] CPUs: 8 - Mem: 16 GB (90.5 MB) - Swap: 2 GB (356.6 MB) Oct-02 13:51:35.840 [main] DEBUG nextflow.Session - Work-dir: /Users/theodosiou/Documents/Projects/nextflow/nextflow-example/work [Mac OS X] Oct-02 13:51:35.840 [main] DEBUG nextflow.Session - Script base path does not exist or is not a directory: /Users/theodosiou/Documents/Projects/nextflow/nextflow-example/bin Oct-02 13:51:35.846 [main] DEBUG nextflow.executor.ExecutorFactory - Extension executors providers=[] Oct-02 13:51:35.851 [main] DEBUG nextflow.Session - Observer factory: DefaultObserverFactory Oct-02 13:51:35.861 [main] DEBUG nextflow.cache.CacheFactory - Using Nextflow cache factory: nextflow.cache.DefaultCacheFactory Oct-02 13:51:35.867 [main] DEBUG nextflow.util.CustomThreadPool - Creating default thread pool > poolSize: 9; maxThreads: 1000 Oct-02 13:51:35.903 [main] DEBUG nextflow.Session - Session start invoked Oct-02 13:51:36.227 [main] DEBUG nextflow.script.ScriptRunner - > Launching execution Oct-02 13:51:36.235 [main] DEBUG nextflow.Session - Session aborted -- Cause: No such property: result for class: Script_0f3fefb4 Oct-02 13:51:36.241 [main] ERROR nextflow.cli.Launcher - @unknown groovy.lang.MissingPropertyException: No such property: result for class: Script_0f3fefb4 at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:65) at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:51) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:341) at Script_0f3fefb4.runScript(Script_0f3fefb4:15) at nextflow.script.BaseScript.runDsl2(BaseScript.groovy:170) at nextflow.script.BaseScript.run(BaseScript.groovy:217) at nextflow.script.ScriptParser.runScript(ScriptParser.groovy:220) at nextflow.script.ScriptRunner.run(ScriptRunner.groovy:212) at nextflow.script.ScriptRunner.execute(ScriptRunner.groovy:120) at nextflow.cli.CmdRun.run(CmdRun.groovy:337) at nextflow.cli.Launcher.run(Launcher.groovy:480) at nextflow.cli.Launcher.main(Launcher.groovy:639)
问题原因
- 原脚本是DSL1写法,但你的Nextflow版本(22.04.5)默认启用DSL2,两者语法差异导致错误。
- DSL1中,流程的输出会自动绑定到与流程同名的变量(如
AFcalc流程的输出是AFcalc变量),但脚本中错误使用了未定义的result变量。 - DSL2默认不会自动执行流程,需要通过
workflow块显式调用流程并处理输出通道。
修复方案
提供两种兼容方案,任选其一即可:
方案1:切换为DSL1模式
在脚本开头添加DSL1启用声明,并将订阅对象改为流程名:
#!/usr/bin/env nextflow nextflow.enable.dsl=1 params.str = 'Hello world!' process AFcalc { """ echo '${params.str}' """ } // 订阅AFcalc流程的输出通道 AFcalc.subscribe { println it.trim() }
方案2:适配DSL2模式
使用workflow块执行流程,显式定义输出通道并订阅:
#!/usr/bin/env nextflow params.str = 'Hello world!' process AFcalc { // 显式定义输出通道,将标准输出命名为msg output: stdout emit: msg """ echo '${params.str}' """ } // 定义工作流,调用流程并处理输出 workflow { // 调用AFcalc流程,获取其输出通道 calc_result = AFcalc() // 订阅输出通道中的msg calc_result.msg.subscribe { println it.trim() } }
验证运行
保存修改后的脚本,重新运行命令:
nextflow run example1.nf
脚本将正常执行,输出Hello world!。
内容的提问来源于stack exchange,提问作者LDT
相关产品推荐
相关产品推荐

