可能是蛇形游戏中一个非常基本的问题,但我目前还没有找到答案。假设我有一份样品清单
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, A-C.txt, B-C.txt
在expand function的蛇形文件中,他们说:
默认情况下,expand使用python itertools函数product
,该函数生成所提供的通配符值的所有组合。但是,通过插入第二个位置参数,它可以被任何组合函数替换,例如zip
但是,我不能用itertools.combinations函数替换product
,因为从source code of expand可以看出,您不能将r
(输出元组的长度)参数指定给expand
。做
import itertools
expand("{sample}-{sample}.txt", itertools.combinations, sample=SAMPLES)
返回一个错误'list' object cannot be interpreted as an integer
。但是它与itertools.product
一起工作
我想我可以在调用expand之前使用itertools.combinations
创建两个规则之外的列表,但我希望从Snakemake社区获得一种优雅的方法
谢谢
也许可以在
expand
内完成,但我认为如果没有它,生成感兴趣的列表会更容易。例如:现在使用
combs
无论您在哪里使用expand(...)
。假设^ {< CD1>}只是一个返回列表的便利函数,但不必使用它相关问题 更多 >
编程相关推荐