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

snakemake执行rule all时报Missing input file错误求助

问题原因分析
  • 核心错误1:违反Snakemake执行逻辑,在输入函数get_fastq_files中执行生成文件的操作。Snakemake的输入函数仅在DAG构建阶段运行,作用是返回任务所需的输入文件路径,该阶段Snakemake仅收集所有任务的输入输出依赖,不会将你在函数中通过subprocess偷偷生成的文件纳入依赖管理体系,因此就算文件实际存在,Snakemake也会因为没有匹配到可生成该文件的规则,抛出MissingInputException。
  • 错误2:路径不匹配。从报错日志可以看到原始fastq路径被打印为data/RUNs/xxx,但你提供的样本表中路径前缀是data/,同时如果你的Snakefile存放在子目录下,执行snakemake命令的工作目录与预期不一致,会导致相对路径解析错误,不需要拼接的样本因为Snakemake找不到原始fastq输入,无法运行后续test_rule,自然不会生成touch文件。
  • 代码小瑕疵:concatenate_fastq函数中{[sample_df['path']][0]}的写法冗余,[sample_df['path']][0]完全等价于sample_df['path']。
修复方案

步骤1:新增独立的拼接规则

将拼接逻辑从输入函数中剥离,单独声明为Snakemake规则,让Snakemake可以感知到拼接文件的生成逻辑:

rule concatenate_fastq:
    input:
        r1 = lambda wildcards: SAMPLES.loc[wildcards.sample, "path"],
        r2 = lambda wildcards: SAMPLES.loc[wildcards.sample, "path2"]
    output:
        "data/processed/{sample}_concatenated.fastq.gz"
    # 仅对存在path2的样本运行该规则,避免无效匹配
    wildcard_constraints:
        sample = "|".join(SAMPLES[~SAMPLES["path2"].isna()].index.tolist())
    shell:
        "cat {input.r1} {input.r2} > {output}"

步骤2:修改输入函数,仅返回路径

删除输入函数中的文件生成逻辑,仅根据样本情况返回对应的输入路径:

def get_fastq_files(wildcards):
    sample_df = SAMPLES.loc[wildcards.sample]
    if pd.isna(sample_df["path2"]):
        # 无第二个fastq,直接返回原始路径
        return [sample_df["path"]]
    else:
        # 有第二个fastq,返回拼接后的文件路径,Snakemake会自动调用上面的拼接规则生成
        return [f"data/processed/{wildcards.sample}_concatenated.fastq.gz"]

步骤3:校验路径一致性

  • 检查prueba_snakemake.csv中的路径是否和实际文件路径一致,确认是否多余RUNs/前缀
  • 执行snakemake命令时,确保工作目录为项目根目录(即data/文件夹所在的目录),避免相对路径解析错误

步骤4:保留原有test_rule无需修改

rule test_rule:
    input:
        reads = get_fastq_files
    output:
        "data/processed/{sample}.test"
    shell:
        "touch {output}"

修复后Snakemake会自动识别依赖:不需要拼接的样本直接用原始fastq运行test_rule,需要拼接的样本先运行concatenate_fastq生成拼接文件,再运行test_rule,两个问题都会解决。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.25 17:24:07