我有一个关于动态通配符使用的快速问题。我搜索了文档和论坛,但没有找到一个简单的答案来回答我的问题。
以下是给我带来麻烦的规则:
rule all:
input: dynamic("carvemeOut/{species}.xml")
shell:"snakemake --dag | dot -Tpng > pipemap.png"
rule speciesProt:
input:"evaluation-output/clustering_gt1000_scg.tab"
output: dynamic("carvemeOut/{species}.txt")
shell:
"""
cd {config[paths][concoct_run]}
mkdir -p {config[speciesProt_params][dir]}
cp {input} {config[paths][concoct_run]}/{config[speciesProt_params][dir]}
cd {config[speciesProt_params][dir]}
sed -i '1d' {config[speciesProt_params][infile]} #removes first row
awk '{{print $2}}' {config[speciesProt_params][infile]} > allspecies.txt #extracts node information
sed '/^>/ s/ .*//' {config[speciesProt_params][metaFASTA]} > {config[speciesProt_params][metaFASTAcleanID]} #removes annotation to protein ID
Rscript {config[speciesProt_params][scriptdir]}multiFASTA2speciesFASTA.R
sed -i 's/"//g' species*
sed -i '/k99/s/^/>/' species*
sed -i 's/{config[speciesProt_params][tab]}/{config[speciesProt_params][newline]}/' species*
cd {config[paths][concoct_run]}
mkdir -p {config[carveme_params][dir]}
cp {config[paths][concoct_run]}/{config[speciesProt_params][dir]}/species* {config[carveme_params][dir]}
cd {config[carveme_params][dir]}
find . -name "species*" -size -{config[carveme_params][cutoff]} -delete #delete files with little information, these cause trouble
"""
rule carveme:
input: dynamic("carvemeOut/{species}.txt")
output: dynamic("carvemeOut/{species}.xml")
shell:
"""
set +u;source activate concoct_env;set -u
cd {config[carveme_params][dir]}
echo {input}
echo {output}
carve $(basename {input})
"""
我之前使用了两个不同的widlcard来输入和输出卡维姆规则:
input: dynamic("carvemeOut/{species}.txt")
output: dynamic("carvemeOut/{gem}.xml")
我想让snakemake多次运行caveme规则,为每个input.txt文件创建一个output.xml文件。然而,snakemake只运行一次规则,使用输入列表创建一个输出,如下所示:
rule carveme:
input: carvemeOut/species2.txt, carvemeOut/species5.txt, carvemeOut/species1.txt, carvemeOut/species10.txt, carvemeOut/species4.txt, carvemeOut/species17.txt, carvemeOut/species13.txt, carvemeOut/species8.txt, carvemeOut/species14.txt
output: {*}.xml (dynamic)
jobid: 28
在修改我的规则以使用相同的通配符后,如@stovfl所建议的,并显示在第一个代码框中,我得到以下错误消息:
$ snakemake all
Building DAG of jobs...
WildcardError in line 174 of /c3se/NOBACKUP/groups/c3-c3se605-17-8/projects_francisco/binning/snakemake-concot/Snakefile:
Wildcards in input files cannot be determined from output files:
species
关于如何解决这个问题有什么建议吗?
提前感谢,FZ-
您希望在您的规则all和创建动态输出的规则中包含动态,但不包含在最后一个输出中。
下面是一个工作示例。以物种的输入文件为例species_example.txt
:
SpeciesA
SpeciesB
SpeciesC
SpeciesD
以下Snakefile
将动态生成4个输出文件
#Snakefile
rule all:
input:
dynamic("carvemeOut/{species}.xml"),
rule speciesProt:
input: "species_example.txt"
output: dynamic("carvemeOut/{species}.txt")
shell:
"""
awk '{{gsub(/\r/,"",$1);print > "carvemeOut/"$1".txt";}}' {input}
"""
rule carveme:
input: "carvemeOut/{species}.txt"
output: "carvemeOut/{species}.xml"
shell: "cat {input} > {output}"
Dynamic目前在Snakemake中有很多限制(只允许一个动态通配符请参阅下面Francisco的评论,在同一规则中不能混合非动态和动态输出(,因此我尽可能避免它。例如,我不想让这个例子变成动态的,而是在运行任何规则之前使用pyhton函数来生成一个可能的物种名称列表,并使用它来扩展rule all中的通配符。你确定你需要动态输出吗?
此外,您应该避免直接在Snakefile中写入如此长的shell部分,并使用外部脚本或将该shell命令分解为多个规则。