snakemake truncating shell codes
1
1
Entering edit mode
2.4 years ago
ohu20a ▴ 10

I'm trying to change the chromosome number notation from [0-9XY] to Chr[0-9XY] using the samtools reheader in the shell command of the snakemake.

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

The code ran successfully in the terminal but when I used the code in snakemake it gave the error:

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

When I looked into the error I found that the snakemake read the sed -e 's/SN:([0-9XY]*)/SN:chr\1/ as 's/SN:([0-9XY]*)/SN:chr/'. That is, it truncated the code.

python snakemake shell • 1.1k views
ADD COMMENT
0
Entering edit mode
ADD REPLY
4
Entering edit mode
2.4 years ago
Jianyu ▴ 580

I think it's due to python treats "\" as escape character, so adding another backslash should fix the error

"samtools view -H {input} | sed  -e 's/SN:\([0-9XY]*\)/SN:chr\\1\/' -e 's/SN:MT/SN:chrM/' |samtools  reheader - {input}  {output}"
ADD COMMENT

Login before adding your answer.

Traffic: 2351 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6