我想在snakemake的帮助下对不同的输入文件多次执行R脚本。为此,我尝试使用 expand 函数。
我对snakemake比较陌生,当我正确理解它时,扩展功能为我提供了例如多个输入文件,然后所有输入文件都可以通过{input}.
是否可以对文件一一调用shell命令?
假设我在 config.yaml 中有这个定义:
types:
- "A"
- "B"
Run Code Online (Sandbox Code Playgroud)
这将是我的示例规则:
rule manual_groups:
input:
expand("chip_{type}.bed",type=config["types"])
output:
expand("data/p_chip_{type}.model",type=config["types"])
shell:
"Rscript scripts/pre_process.R {input}"
Run Code Online (Sandbox Code Playgroud)
这将导致命令:
Rscript scripts/pre_process.R chip_A.bed chip_B.bed
Run Code Online (Sandbox Code Playgroud)
是否可以使用如下两种类型独立调用命令两次:
Rscript scripts/pre_process.R chip_A.bed
Rscript scripts/pre_process.R chip_B.bed
Run Code Online (Sandbox Code Playgroud)
提前感谢您的任何帮助!
定义最终的目标文件中rule all,然后只需使用适当的通配符(即type在规则)manual_groups。这将rule manual_groups针对 中列出的每个输出文件单独运行rule all。
rule all:
input:
expand("data/p_chip_{type}.model",type=config["types"])
rule manual_groups:
input:
"chip_{type}.bed"
output:
"data/p_chip_{type}.model"
shell:
"Rscript scripts/pre_process.R {input}"
Run Code Online (Sandbox Code Playgroud)
PS-type由于与 Python 的类型方法潜在冲突,您可能想要更改通配符术语。