英文:
How to make Snakemake wildcard work for empty string?
问题
我期望Snakemake允许通配符为空字符串,然而,事实并非如此。
如何使通配符接受空字符串?
英文:
I expected Snakemake to allow wildcards to be empty strings, alas, this isn't the case.
How can I make a wildcard accept an empty string?
答案1
得分: 4
通配符默认只匹配正则表达式.+
,意味着匹配一切除了空字符串。不幸的是,除了Google小组讨论之外,这一点未记录。
要使通配符匹配空字符串,只需在规则范围内或全局添加自定义通配符约束wildcard_constraints: foo=".*"
:
# 选项 1
wildcard_constraints:
foo=".*"
rule a:
input: in{foo}.txt
output: out{foo}.txt
wildcard_constraints: foo=".*" # 选项 2
shell: "cp {input} {output}"
英文:
Wildcards by default only match the regex .+
meaning everything but empty strings. This is unfortunately not documented beyond a Google group conversation.
To make a wildcard accept empty strings, simply add a custom wildcard constraint wildcard_constraints: foo=".*"
, either within the scope of a rule or globally:
# Option 1
wildcard_constraints:
foo=".*"
rule a:
input: in{foo}.txt
output: out{foo}.txt
wildcard_constraints: foo=".*" # Option 2
shell: "cp {input} {output}"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论