Snakemake目录文件依赖报错:MissingInputException如何解决?
Snakemake MissingInputException 问题修复
问题场景
rule_1调用工具生成包含多文件的directory_rule1目录,后续rule2依赖该目录下的a.tsv和b.tsv作为输入,但构建DAG时触发MissingInputException报错。
原规则代码
rule rule_1: #Line 62 input: a="a.txt", b="b.txt" output: "directory_rule1" params: a = "10", b = "1000" log: "rule1.log" shell: "nohup python2 rule1.py --a {input.a} " "--b {input.b} " "--out {output} " "--a {params.a} " "--b {params.b) &> {log} " rule rule2: input: a="directory_rule1/a.tsv", b="directory_rule1/b.tsv" output: "a.csv" params: d="500" log: "rule2.log" shell: "python3 rule2.py -a {input.a} -b {input.b} -threshold {params.d} &> {log} "
报错信息
Building DAG of jobs... MissingInputException in line 62 of pathtosnakefile/snakefile: Missing input files for rule rule2: output: a.csv affected files: directory_rule1/a.tsv directory_rule1/b.tsv
修复方案
核心原因
Snakemake无法自动关联“目录输出”与“目录内文件”的依赖关系,必须明确声明rule_1生成了rule2需要的具体文件。
具体修复步骤
修正rule_1的输出定义
将rule_1的output改为明确声明目录内的目标文件,同时用directory()标记目录(可选,但能让Snakemake更清晰识别目录结构):rule rule_1: #Line 62 input: a="a.txt", b="b.txt" output: directory("directory_rule1"), # 标记输出目录 "directory_rule1/a.tsv", "directory_rule1/b.tsv" params: a = "10", b = "1000" log: "rule1.log" shell: "nohup python2 rule1.py --a {input.a} " "--b {input.b} " "--out {output.directory_rule1} " # 引用目录输出项 "--a {params.a} " "--b {params.b} &> {log} " # 修正原代码的括号语法错误修正shell命令的语法错误
原rule_1的shell命令中--b {params.b)存在括号错误(应为}),这个错误会导致rule_1执行失败,必须修正。
为什么之前的尝试无效?
- 移除rule2的output:rule2必须有输出,否则Snakemake无法识别任务目标;
- 将目录放入params:params不参与依赖关系构建,Snakemake不会追踪params中的路径;
- 仅使用
directory():只标记目录但未声明具体文件,Snakemake不知道目录内的文件是该规则生成的,无法建立依赖链。
内容的提问来源于stack exchange,提问作者cookiemonster
相关产品推荐
相关产品推荐

