动态输入和动态输出规则的问题
Problems with dynamic input and dynamic output rule
我有一个关于动态通配符使用的快速问题。我搜索了文档和论坛,但没有找到直接回答我的问题的答案。
以下是给我带来麻烦的规则:
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 }}' {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})
"""
我之前使用了两个不同的 widlcards 作为 carveme 规则的输入和输出:
input: dynamic("carvemeOut/{species}.txt")
output: dynamic("carvemeOut/{gem}.xml")
我想让 snakemake 做的是多次 运行 carveme 规则,为每个输入 .txt 文件创建一个输出 .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
您希望在所有规则和创建动态输出但不在最后一个输出中的规则中使用动态。
这是一个工作示例。以物种的输入文件为例 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/,"",);print > "carvemeOut/"".txt";}}' {input}
"""
rule carveme:
input: "carvemeOut/{species}.txt"
output: "carvemeOut/{species}.xml"
shell: "cat {input} > {output}"
动态在Snakemake中目前有很多限制(只允许一个动态通配符见下面F运行cisco的评论,不能混合非动态和动态输出在同一条规则中)因此我尽可能避免它。例如,我不会使这个示例动态化,而是使用 pyhton 函数在任何规则 运行 之前生成可能的物种名称列表,并使用它来扩展规则 all 中的通配符。您确定需要动态输出吗?
此外,您应该避免直接在 Snakefile 中编写如此长的 shell 部分,并使用外部脚本或将 shell 命令分解为多个规则。
我有一个关于动态通配符使用的快速问题。我搜索了文档和论坛,但没有找到直接回答我的问题的答案。
以下是给我带来麻烦的规则:
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 }}' {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})
"""
我之前使用了两个不同的 widlcards 作为 carveme 规则的输入和输出:
input: dynamic("carvemeOut/{species}.txt")
output: dynamic("carvemeOut/{gem}.xml")
我想让 snakemake 做的是多次 运行 carveme 规则,为每个输入 .txt 文件创建一个输出 .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
您希望在所有规则和创建动态输出但不在最后一个输出中的规则中使用动态。
这是一个工作示例。以物种的输入文件为例 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/,"",);print > "carvemeOut/"".txt";}}' {input}
"""
rule carveme:
input: "carvemeOut/{species}.txt"
output: "carvemeOut/{species}.xml"
shell: "cat {input} > {output}"
动态在Snakemake中目前有很多限制(只允许一个动态通配符见下面F运行cisco的评论,不能混合非动态和动态输出在同一条规则中)因此我尽可能避免它。例如,我不会使这个示例动态化,而是使用 pyhton 函数在任何规则 运行 之前生成可能的物种名称列表,并使用它来扩展规则 all 中的通配符。您确定需要动态输出吗?
此外,您应该避免直接在 Snakefile 中编写如此长的 shell 部分,并使用外部脚本或将 shell 命令分解为多个规则。