【问题标题】:Snakemake cannot handle very long command line?Snakemake 不能处理很长的命令行?
【发布时间】:2020-09-26 02:19:41
【问题描述】:

这是一个很奇怪的问题。 当我在rule 部分中指定的{input} 是{input} 有超过500 个文件时,snakemake 就退出了消息(one of the commands exited with non-zero exit code; note that snakemake uses bash strict mode!)。完整的日志没有提供任何错误消息。

日志请见:https://github.com/snakemake/snakemake/files/5285271/2020-09-25T151835.613199.snakemake.log

有效的规则是(注意input 限制为 200 个文件):

rule combine_fastq:
    input:
        lambda wildcards: samples.loc[(wildcards.sample), ["fq"]].dropna()[0].split(',')[:200]
    output:
        "combined.fastq/{sample}.fastq.gz"
    group: "minion_assemble"
    shell:
        """
echo {input} >  {output}
        """

失败的规则是:

rule combine_fastq:
    input:
        lambda wildcards: samples.loc[(wildcards.sample), ["fq"]].dropna()[0].split(',')
    output:
        "combined.fastq/{sample}.fastq.gz"
    group: "minion_assemble"
    shell:
        """
echo {input} >  {output}
        """

我的问题也发布在 GitHub 上:https://github.com/snakemake/snakemake/issues/643

【问题讨论】:

  • 我觉得可能和这个有关:stackoverflow.com/questions/19354870/…
  • 我认为shell中的命令行长度不是问题。我跑了getconf ARG_MAX ,得到了4611686018427387903
  • 你找到解决方案了吗?
  • @Maarten-vd-Sande 我还没想到。我写了一个不同的脚本来绕过snakemake中的这个问题。

标签: snakemake


【解决方案1】:

我支持 Maarten 的回答,因为您运行的文件数量众多,因此您遇到了 shell 限制; snakemake 在帮助您识别问题方面做得很差。

根据您引用的问题,您似乎正在使用 cat 来合并所有文件。也许遵循here 的答案会有所帮助:

rule combine_fastq_list:
    input:
        lambda wildcards: samples.loc[(wildcards.sample), ["fq"]].dropna()[0].split(',')
    output:
        temp("{sample}.tmp.list")
    group: "minion_assemble"
    script:
        with open(output[0]) as out:
            out.write('\n'.join(input))

rule combine_fastq:
    input:
        temp("{sample}.tmp.list")
    output:
        'combined.fastq/{sample}.fastq.gz'
    group: "minion_assemble"
    shell:
        'cat {input} | '  # this is reading the list of files from the file
            'xargs zcat -f | '
            '...'

希望它能让你走上正轨。

编辑

第一个选项为每个输入文件分别执行您的命令。对整个输入列表执行一次命令的另一个选项是:

rule combine_fastq:
    ...
    shell:
        """
        command $(< {input}) ...
        """

【讨论】:

  • 感谢您的技巧。我试过了,可惜没用。
  • 这对我不起作用,但直接使用输入作为参数:$(&lt; {input.files})!
  • @Maarten-vd-Sande 你能编辑我的答案或发布一个新答案吗?不确定我知道在哪里进行修改。
【解决方案2】:

对于那些登陆这里有类似问题(如Snakemake expand function alternative)的人,snakemake 6 可以处理长命令行。以下测试在 snakemake

rule all:
    input:
        'output.txt',

rule one:
    output:
        'output.txt',
    params:
        x= list(range(0, 1000000))
    shell:
        r"""
        echo {params.x} > {output}
        """

【讨论】:

    猜你喜欢
    • 2021-02-03
    • 2010-09-28
    • 1970-01-01
    • 2014-08-17
    • 1970-01-01
    • 1970-01-01
    • 2012-04-10
    相关资源
    最近更新 更多