-2

I would like to execute this shell command through python, I tried to use

shell="ls *R1.fastq.gz|while read a; do b=${a%R1.fastq.gz}R2.fastq.gz; c=${a%R1.fastq.gz}R1.out.fq; d=${a%R1.fastq.gz}R2.out.fq; e=${a%R1.fastq.gz}.s.fq; echo "sickle pe -t sanger -f $a -r $b -o $c -p $d -s $e"; done >SICKLE.sh"

system.os(shell)

But a get a SythaxError: InvalidSyntax I make some research, maybe I should use subprocces ? but I'am pretty new with this, could we help me ?

ThiBei
  • 3
  • 2
  • 1
    Also you have to escape quotes in your command, or use single quotes to contain your string. – user3483203 May 21 '18 at 02:25
  • @chrisz what do you mean by escape the quotes ? get ride of them ? but it will not work like correctly without them – ThiBei May 21 '18 at 02:37
  • One way is like this: shell="ls *R1.fastq.gz|while read a; do b=${a%R1.fastq.gz}R2.fastq.gz; c=${a%R1.fastq.gz}R1.out.fq; d=${a%R1.fastq.gz}R2.out.fq; e=${a%R1.fastq.gz}.s.fq; echo \"sickle pe -t sanger -f $a -r $b -o $c -p $d -s $e\"; done >SICKLE.sh" – samwyse May 21 '18 at 03:24

1 Answers1

0

escape quotes (add \ before quotes in your string)

shell="*R1.fastq.gz|while read a; do b=${a%R1.fastq.gz}R2.fastq.gz; c=${a%R1.fastq.gz}R1.out.fq; d=${a%R1.fastq.gz}R2.out.fq; e=${a%R1.fastq.gz}.s.fq; echo \"sickle pe -t sanger -f $a -r $b -o $c -p $d -s $e\"; done >SICKLE.sh"

subprocess.call:

import subprocess
subprocess.call(["ls", shell])
user3483203
  • 50,081
  • 9
  • 65
  • 94