我正在尝试重命名 Snakemake 管道中的一些文件。
假设我有三个文件:"FileA.txt"
, "FileB.txt"
, "FileC.txt"
我希望根据字典重新命名它们dict = {"A": "0", "B": "1", "C": "2"}
to get "RenamedFile0.txt"
, "RenamedFile1.txt"
, and "RenamedFile2.txt"
。如何为此编写一条规则?
这就是我的管道的样子(我尝试过使用一个函数但不起作用)
SAMPLES = ["A", "B", "C"]
RENAMED_SAMPLES = ["0", "1", "2"]
rename = {"0": "A", "1": "B", "2": "C"}
def mapFile(wildcards):
file = "results/EditedFile" + str(rename[wildcards]) + ".txt"
return(file)
rule all:
input:
"results/Combined.txt"
rule cut:
input:
"data/File{sample}.txt"
output:
"results/EditedFile{sample}.txt"
shell:
"cut -f1 {input} > {output}"
rule rename:
input:
mapFile
output:
"results/RenamedFile{renamedSample}.txt"
shell:
"cp {input} {output}"
rule combine:
input:
expand("results/RenamedFile{renamedSample}.txt", renamedSample = RENAMED_SAMPLES)
output:
"results/Combined.txt"
shell:
"cat {input} > {output}"
我收到以下错误:
KeyError: ['2']
Wildcards:
renamedSample=2
谢谢!!!
运行自定义扩展时,应指定通配符的名称:
def mapFile(wildcards):
file = "results/EditedFile" + rename[wildcards.renamedSample] + ".txt"
return(file)
在这种特定情况下,还可以将逻辑集成到规则本身中:
rule rename:
input:
lambda wildcards: f"results/EditedFile{rename[wildcards.renamedSample]}.txt"
output:
"results/RenamedFile{renamedSample}.txt"
shell:
"cp {input} {output}"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)