【发布时间】:2020-12-17 06:03:27
【问题描述】:
我在 python 中创建了一个字典,并将目录的路径(我希望软件在其上运行)保存为键,相应的值是每个目录的预期输出列表。现在我有这样的结构:
sampleDict = {'/path_to_directory1': ["sample1","sample2","sample3"],
'/path_to_directory2': ["sample1","sample2"],
'/path_to_directory3': ["sample1","sample2","sample3"]}
# sampleDict looks pretty much like this
# key is a path to the directory that I want the rule to be executed on and the corresponding value sampleDict[key] is an array e.g. ["a","b","c"]
def input():
input=[]
for key in dirSampleDict:
input.extend(expand('{dir}/{sample}*.foo', dir = key, sample=dirSampleDict[key]))
return input
rule all:
input:
input()
# example should run some software on different directories for each set of directories and their expected output samples
rule example:
input:
# the path to each set of samples should be the wildcard
dir = lambda wildcards: expand("{dir}", dir=dirSampleDict.keys())
params:
# some params
output:
expand('{dir}/{sample}*.foo', dir = key, sample=dirSampleDict[key])
log:
log = '{dir}/{sample}.log'
run:
cmd = "software {dir}"
shell(cmd)
这样做我收到以下错误:
没有为通配符 'dir 指定值
编辑:也许我不太清楚我真正想要做什么,所以我填写了一些数据。
我也尝试使用我在 rule all 中设置的通配符如下:
sampleDict = {'/path_to_directory1': ["sample1","sample2","sample3"],
'/path_to_directory2': ["sample1","sample2"],
'/path_to_directory3': ["sample1","sample2","sample3"]}
# sampleDict looks pretty much like this
# key is a path to the directory that I want the rule to be executed on and the corresponding value sampleDict[key] is an array e.g. ["a","b","c"]
def input():
input=[]
for key in dirSampleDict:
input.extend(expand('{dir}/{sample}*.foo', dir = key, sample=dirSampleDict[key]))
return input
rule all:
input:
input()
# example should run some software on different directories for each set of directories and their expected output samples
rule example:
input:
# the path to each set of samples should be the wildcard
dir = "{{dir}}"
params:
# some params
output:
'{dir}/{sample}*.foo'
log:
log = '{dir}/{sample}.log'
run:
cmd = "software {dir}"
shell(cmd)
这样做我收到以下错误:
并非所有规则示例的输出、日志和基准文件都包含 相同的通配符。这是至关重要的,但为了避免这两个或 更多作业写入同一个文件。
我很确定第二部分更可能是我真正想要做的,因为 expand() 作为输出只会运行一次规则,但我需要为字典中的每个键值对运行它。
【问题讨论】:
标签: snakemake