具有扩展和不同数量参数的 Snakemake 输出

Snakemake output with expand and different number of parameters

我在 snakemake 中有这个规则:

    output:
        RESULTS + folderdestination + "/{feats}/{edges}/{labels}/predictions_{e}_{n}_{h}_run{r}.csv"
        dir=directory(RESULTS + folderdestination + "/{feats}/{edges}/{labels}/")

我需要传递给另一个规则,只是文件夹:

    dir=directory(RESULTS + folderdestination + "/{feats}/{edges}/{labels}/")

但是使用的通配符数量不同,snakemake 不允许我在同一规则中使用第二个语句,因为它引发

Not all output, log and benchmark files of rule analysis contain the same wildcards. This is crucial though, in order to avoid that two or more jobs write to the same file.

有没有什么办法可以"extract"以snakemake的方式把文件夹弄出来,而不需要重新写程序的代码? 谢谢

对于所有可能面临同样问题的人。经过一些测试后,我通过创建一个虚拟 "middleware" 规则来实现它。所以第一条规则是:

 output:
        RESULTS + folderdestination + "/{feats}/{edges}/{labels}/predictions_{e}_{n}_{h}_run{r}.csv"

featsedgeslabelsenhr.

然后我在下面创建了这个带有选择性扩展的虚拟规则,它接受刚刚创建的文件和 returns 只是文件夹:

rule dummy:
    input:
        expand(RESULTS + folderdt + "/{{feats}}/{{edges}}/{{labels}}/predictions_{e}_{n}_{h}_run{r}.csv",  e=e, n=n, h=h, r=r),
    output:
        RESULTS + folderdt + "/{feats}/{edges}/{labels}/",

最后,我得到了我的规则,它将在虚拟规则中创建的输出文件夹作为输入:

rule summary:
    input:
        folder=RESULTS + folderdt +"/{feats}/{edges}/{labels}/"
    output:
        file=RESULTS + folderdt +"/{feats}/{edges}/{labels}/summary.csv"

我认为您真的不需要中间规则或目录作为输出。目录标签对于输出未知数量文件的规则很重要,例如分散操作。在您的情况下,snakemake 仍会在开始作业之前创建所有嵌套目录。假设你有一个最新版本的 snakemake,expand 也可以接受一个名为 'allow_missing' 的命名参数,这样你就不必屏蔽通配符。总的来说我的想法是:

base_dir = RESULTS + folderdestination + "/{feats}/{edges}/{labels}/"
prediction = base_dir + "predictions_{e}_{n}_{h}_run{r}.csv"
summary = base_dir + "summary.csv"

rule make_prediction:
    output: prediction

rule summary:
    input:
        predictions=expand(prediction, e=e, n=n, h=h, r=r, allow_missing=True)
    params:
        base_dir
    output:
        file=summary
    # do things with {params.folder}, can ignore predictions.

对于 e、n、h、r = 范围 (2),snakemake -nq feat1/edge1/label1/summary.csv 给出:

Job counts:
        count   jobs
        1       all
        16      make_prediction
        1       summary
        18

因为params只包含带通配符的文件夹路径,所以通配符会被替换掉。在摘要规则中使用触摸输出和回显 params.folder 给出:

feat1/edge1/label1/