如何在Snakemake中使用扩展功能进行列表的排列或组合

问题描述

在Snakemake中可能是一个非常基本的问题,但到目前为止我找不到答案。说我有样品清单

SAMPLES = ["A","B","C"]

典型的expand命令如下所示:

expand("{sample}.txt",sample=SAMPLES)

但是我想获得相同样本列表的组合(甚至排列)。

正在做

expand("{sample}-{sample}.txt",sample=SAMPLES)

会给你

 A-A.txt,A-B.txt,A-C.txt,B-A.txt,B-B.txt,B-C.txt,C-A.txt,C-B.txt,C-C.txt

我想要的是:

A-B.txt,B-C.txt

expand function的Snakemake文档中,他们说:

“默认情况下,expand使用python itertools函数product,该函数产生提供的通配符值的所有组合。但是,通过插入第二个位置参数,可以用任何组合函数代替,例如zip

但是,我不能仅将product替换为itertools.combinations函数,因为据我从source code of expand所知,您不能给rexpand的输出元组的长度)参数。做

import itertools
expand("{sample}-{sample}.txt",itertools.combinations,sample=SAMPLES)

返回错误'list' object cannot be interpreted as an integer。但是它可以与itertools.product一起使用。

我想我可以在调用expand之前用itertools.combinations在规则之外创建两个列表,但是我希望从Snakemake社区中找到一种优雅的方式。

谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)