Snakemake使用不同文件夹中的输入文件按名称进行汇总

问题描述

我正在尝试开发一个管道,该管道将从yaml配置文件中指定的不同目录中获取输入文件,并通过在yaml中指定的名称来跟踪它们。例如,说我的Yaml像

input:
    name1: /some/path/to/file1
    name2: /a/totally/different/path/to/file2
    name3: /yet/another/path/to/file3
output: /path/to/outdir

我想经过一系列步骤,最后得到包含内容的outdir

/path/to/outdir/processed_name1.extension
/path/to/outdir/processed_name2.extension
/path/to/outdir/processed_name3.extension

老实说,我什么也做不了。我一直停滞不前的当前状态是尝试将名称视为通配符,并使用其访问配置字典。但这是行不通的,因为从不初始化通配符,因为第一步是访问输入。由于公司政策的原因,我无法对代码示例进行具体说明,但基本上看起来像这样:

rule all:
    input:
        processed_files = expand(config['output'] + "/processed_{name}.extension",name=config['input'])
        

rule step_1:
    input:
        input_file = lambda wc: config['input'][wc.name]
    output:
        intermediate_file = config['output'] + "/intermediate_{name}.extension"
    run:
        <some command>

rule step_2:
    input:
        intermediate_file = config['output'] + "/intermediate_{name}.extension"
    output:
        processed_file = config['output'] + "/processed_{name}.extension"
    run:
        <some command>

但是这给了我通配符错误,我认为这是有道理的-由于通配符只存在于配置文件中,因此无法找出通配符。我觉得这与Advanced Workflow Example中的示例非常相似,但又相差甚远,以至于我无法使其正常工作...

编辑1:我用字符串连接替换了所有f字符串,只是为了确保这不是问题

编辑2:我最终使它起作用。老实说,我不确定会有什么变化,我肯定有错别字...但是我想我可以说总体结构有效。

解决方法

尽管我删除了fstrings并将run:更改为shell:以便进行简单测试,但是在显示的代码中没有发现主要错误。使用适当的配置文件,下面的命令就可以正常工作。

configfile: "config.yaml"

rule all:
    input:
        processed_files = expand(config['output'] + "/processed_{name}.extension",name=config['input'])


rule step_1:
    input:
        input_file = lambda wc: config['input'][wc.name]
    output:
        intermediate_file = config['output'] + "/intermediate_{name}.extension"
    shell:
        "cat {input} > {output}"

rule step_2:
    input:
        intermediate_file = config['output'] + "/intermediate_{name}.extension"
    output:
        processed_file = config['output'] + "/processed_{name}.extension"
    shell:
        "cat {input} > {output}"

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...