动态输入和动态输出ru的问题

2024-10-03 04:35:19 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个关于使用动态通配符的快速问题。我搜索了文档和论坛,但没有找到对我的问题的直接答案。在

以下是给我带来麻烦的规则:

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})
    """

我之前在carveme规则的输入和输出中使用了两个不同的widlcards:

^{pr2}$

我想要snakemake做的是多次运行carveme规则,为每个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

关于如何解决这个问题有什么建议吗?在

提前谢谢你, 自由区


Tags: txtconfiginputoutput规则dircddynamic
1条回答
网友
1楼 · 发布于 2024-10-03 04:35:19

您希望在规则all和创建动态输出的规则中包含dynamic,而不是在上一个输出中。在

这是一个有效的例子。以物种的输入文件为例species_example.txt

SpeciesA
SpeciesB
SpeciesC
SpeciesD

下面的Snakefile将动态生成4个输出文件

^{pr2}$

Dynamic目前在Snakemake中有很多限制(只允许一个动态通配符见下面Francisco的评论,在同一个规则中不能混合非动态和动态输出),因此如果可能,我尽量避免使用。例如,在运行任何规则之前,我将使用pyton函数生成一个可能的物种名称列表,并使用该列表扩展rule all中的通配符,而不是使这个示例动态化。您确定需要动态输出吗?在

另外,您应该避免直接在Snakefile中写入如此长的shell部分,而使用外部脚本或将shell命令分解为多个规则。在

相关问题 更多 >