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

Python Snakemake使用不同文件夹中的输入文件按名称汇总,python,snakemake,Python,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 我想通过一系列步骤,最终得到一个包含内容的outdi

我正在尝试开发一个管道,它将从不同的目录(在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>

规则所有:
输入:
processed_files=expand(config['output']+“/processed_{name}.extension”,name=config['input']))
规则步骤1:
输入:
input_file=lambda wc:config['input'][wc.name]
输出:
中间文件=config['output']+“/intermediate{name}.extension”
运行:
规则步骤2:
输入:
中间文件=config['output']+“/intermediate{name}.extension”
输出:
processed_file=config['output']+“/processed_{name}.extension”
运行:
但这给了我通配符错误,我认为这是有道理的——它无法找出通配符,因为它们只存在于配置文件中。我觉得这与中的示例非常相似,但差异很大,我就是无法让它工作

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


编辑2:我终于让它开始工作了。老实说,我不确定是什么改变了,我一定是打错了什么。。。但是我想我可以说这个整体结构是有效的。

我在您显示的代码中没有发现重大错误,尽管我删除了fstring并将
run:
更改为
shell:
,以便进行简单的测试。以下内容适用于适当的configfile

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}"

rule all
中,
name
的值需要是
name=config['input'].keys()
。目前,它指向的是整个字典,而不仅仅是它的键。另外,
input
output
文件都不应该是f字符串。@ManavalanGajapathy我实际上完全改变了f字符串,只是为了正常的字符串连接(例如,
intermediate\u file=config['output']+“/intermediate\uu{name}.extension”
现在),这似乎没有帮助。我不认为.keys()是问题所在——expand按我所期望的方式执行,并提供正确的字符串