【问题标题】:snakemake truncating shell codes [closed]snakemake 截断 shell 代码 [关闭]
【发布时间】:2022-01-16 07:41:44
【问题描述】:

我正在尝试使用 snakemake 的 shell 命令中的 samtools 重新标头将染色体编号符号从 [0-9XY] 更改为 Chr[0-9XY]。

rule rename:
    input:
        os.path.join(config["input"], "{sample}.bam"),
    output:
        os.path.join(config["output"], "new_sample/{sample}_chr.bam")
    log:
        os.path.join(config["log"], "samtools/{sample}")
    shell:
        "samtools view -H {input} | sed  -e 's/SN:\([0-9XY]*\)/SN:chr\1\/' -e 's/SN:MT/SN:chrM/' |samtools reheader - {input} > {output}"

代码在终端中运行成功,但是当我在snakemake中使用代码时出现错误:

shell:
        samtools view -H /Users/EGA_dataset/cnvkit_snakemake/input/EGAF00000788153_PD11458c.bam | sed  -e 's/SN:\([0-9XY]*\)/SN:chr/' -e 's/SN:MT/SN:chrM/' |samtools reheader - /Users/cnvkit_snakemake/input/EGAF00000788153_PD11458c.bam > /Users/EGA_dataset/cnvkit_snakemake/output/new_sample/EGAF00000788153_PD11458c_chr.bam
        (one of the commands exited with non-zero exit code; note that snakemake uses bash strict mode!)

当我查看错误时,我发现snakemake 将 sed -e 's/SN:([0-9XY]*)/SN:chr\1/ 读取为 's/SN:([0-9XY]*)/SN:chr/'。也就是说,由于某些我不明白的原因,它截断了代码。

【问题讨论】:

标签: python shell unix bioinformatics snakemake


【解决方案1】:

@KeyboardCat 的答案可能是正确的,但我不会使用转义字符,而是使用原始字符串格式(即r"..."),因此您无需担心 python 解释器以特殊方式处理反斜杠和其他元字符.例如:

rule rename:
    ...
    shell:
        r"""
        samtools view -H {input} | sed  -e 's/SN:\([0-9XY]*\)/SN:chr\1\/' -e 's/SN:MT/SN:chrM/' |samtools reheader - {input} > {output}
        """

虽然我有点怀疑chr\1 是否真的是你想要的......?

【讨论】:

    【解决方案2】:

    我有理由确定这是由于 Python 将反斜杠视为转义字符 - 您需要使用另一个反斜杠来转义您拥有的任何反斜杠,以便它们通过 shell 而不是由 Python 解释:

    rule rename:
        input:
            os.path.join(config["input"], "{sample}.bam"),
        output:
            os.path.join(config["output"], "new_sample/{sample}_chr.bam")
        log:
            os.path.join(config["log"], "samtools/{sample}")
        shell:
            "samtools view -H {input} | sed  -e 's/SN:\\([0-9XY]*\\)/SN:chr\\1\\/' -e 's/SN:MT/SN:chrM/' |samtools reheader - {input} > {output}"
    

    (假设转义括号是您的本意。)

    【讨论】:

      猜你喜欢
      • 2013-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多