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

时间:2020-03-10 16:42:46

标签: directory wildcard snakemake

我在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.

是否有任何方法可以通过snakemake方式“提取”文件夹,而无需重新编写程序代码? 谢谢

2 个答案:

答案 0 :(得分:0)

对于所有可能面临相同问题的人们。经过一些测试,我通过创建一个虚拟的“中间件”规则来做到这一点。所以第一个规则是:

GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey();

return Scaffold(
  appBar: AppBar(
      title: Text('Draw'),
      leading: IconButton(
          icon: Icon(Icons.dehaze),
          onPressed: () {
            if (_scaffoldKey.currentState.isDrawerOpen == false) {
              _scaffoldKey.currentState.openDrawer();
            } else {
              _scaffoldKey.currentState.openEndDrawer();
            }
          })),
  body: Scaffold(
    key: _scaffoldKey,
    drawer: Drawer(),
    body: Center(
      child: Text('Drawer'),
    ),
  ),
);

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

然后在下面,我使用选择性扩展创建了该虚拟规则,该扩展接受刚创建的文件并仅返回文件夹:

h

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

r

答案 1 :(得分:0)

我认为您确实不需要中间规则或目录作为输出。目录标签对于输出未知数量文件的规则(例如分散操作)很重要。在您的情况下,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 = range(2),snakemake -nq feat1/edge1/label1/summary.csv给出:

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

因为参数仅包含带有通配符的文件夹路径,所以通配符将被替换。将触摸用于输出并在摘要规则中回显params.folder可以得到:

feat1/edge1/label1/