我试图使用snakemake的shell命令中的samtools重新标头将染色体编号从0-9XY更改为Chr0-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 's/SN:(0-9XY*)/SN:chr\1/读取为's/SN:(0-9XY*)/SN:chr/'.。也就是说,由于一些我不明白的原因,它截断了代码。
发布于 2021-12-13 07:43:34
我相当肯定,这是因为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}"(假设转义括号是您想要做的事情。)
发布于 2021-12-13 09:03:11
@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真的是你想要的.?
https://stackoverflow.com/questions/70324411
复制相似问题