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

添加longphase_phase规则后Snakemake管道出现KeyError求助

解决Snakemake添加longphase_phase规则后的KeyError问题

问题现象

运行SNP与5mC相位分析的Snakemake管道,添加longphase_phase规则后触发KeyError,错误日志如下:

Building DAG of jobs...
InputFunctionException in rule call_snps_indels in file /data1/greenbab/users/ahunos/apps/workflows/phased_modifications/phase_5mC.smk, line 34:
Error:
  KeyError: 'D-0-2_5000/D-0-2_5000'
Wildcards:
  samples=D-0-2_5000/D-0-2_5000

错误原因

核心问题是longphase_phase规则中snpFile的路径定义错误:
原代码中snpFile路径为:

snpFile='results/call_snps_indels/{samples}/{samples}/snv.vcf.gz'

这里多了一层/{samples}目录,但call_snps_indels规则的输出路径是results/call_snps_indels/{samples}/snv.vcf.gz(仅单层级样本目录)。

当Snakemake解析该错误路径时,会将D-0-2_5000/D-0-2_5000整体识别为{samples}通配符的值,而样本配置文件中仅存在D-0-2_5000这一键,因此触发KeyError。

修复步骤

  1. 修改longphase_phase规则的snpFile输入路径,移除多余的/{samples}层级:
rule longphase_phase:
    input:
        bamfile=lambda wildcards: config["samples"][wildcards.samples],
        modcallfile='results/longphase_modcall/{samples}/modcall_{samples}.vcf',
        snpFile='results/call_snps_indels/{samples}/snv.vcf.gz'  # 修复此处路径
    # 其余参数、输出、shell命令保持不变
  1. (可选)清理之前因错误路径生成的无效文件/目录,避免干扰后续运行:
rm -rf results/call_snps_indels/D-0-2_5000/D-0-2_5000/

验证方法

执行dry-run检查DAG构建是否正常:

snakemake -n

若输出无KeyError且显示正确的任务依赖,则修复成功,可正式运行管道。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.19 10:16:04