You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Snakemake写入列表到文件时触发MissingOutputException问题排查

问题

在使用Snakemake规则时遇到MissingOutputException异常,尝试通过Python代码将config.yaml中的列表写入scaffolds.list文件,但Snakemake持续报错。相关代码如下:

# --- Importing Configuration Files --- #

configfile: "config.yaml"

# -------------------------------------------------

scaffolds = config["Scaffolds"]

localrules: all, MakeScaffoldList

# -------------------------------------------------

rule all:
    input:
        LIST = "scaffolds.list"

# -------------------------------------------------

rule MakeScaffoldList:
    output:
        LIST = "scaffolds.list"
    params:
        SCAFFOLDS = scaffolds
    run:
        """
        with open(output.LIST, 'w') as f:
            for line in params.SCAFFOLDS:
                f.write(f"{line}\n")
        """

错误信息:

[Thu Nov 17 14:08:33 2022]
localrule MakeScaffoldList:
    output: scaffolds.list
    jobid: 1
    resources: mem_mb=27200, disk_mb=1000, tmpdir=/scratch, account=snic2022-22-156, partition=core, time=12:00:00, threads=4

MissingOutputException in line 37 of test.smk:
Job Missing files after 5 seconds. This might be due to filesystem latency. If that is the case, consider to increase the wait time with --latency-wait:
scaffolds.list completed successfully, but some output files are missing. 0
Exiting because a job execution failed. Look above for error message
解决方法
  • 核心问题:run块的代码被当作shell命令执行,而非Python代码
    Snakemake中,run块若用三重双引号包裹内容,会被识别为shell命令执行。你写的Python代码被当成shell命令运行,自然不会生成目标文件,触发MissingOutputException。

  • 修复步骤
    移除run块内的三重双引号,直接编写Python代码:

    rule MakeScaffoldList:
        output:
            LIST = "scaffolds.list"
        params:
            SCAFFOLDS = scaffolds
        run:
            with open(output.LIST, 'w') as f:
                for line in params.SCAFFOLDS:
                    f.write(f"{line}\n")
    
  • 额外验证项

    1. 确认config.yaml中的Scaffolds是合法列表格式,示例:
      Scaffolds:
        - scaffold_1
        - scaffold_2
        - scaffold_3
      
    2. 若在集群共享文件系统运行,可尝试添加--latency-wait 10参数规避文件系统延迟误判,但这是临时方案,核心仍需修复run块的代码执行方式。

内容的提问来源于stack exchange,提问作者Valentina

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.11 22:25:17