calling BWA mem from within python
1
1
Entering edit mode
8.5 years ago
lien ▴ 90

Dear all,

I would like to call BWA mem from within a python script. This works, but I cannot specify an output filename. The output is printed to stdout, but off course this is not what I want. From within BWA I should use '>' but this is not working from within python. This is the call function that I'm using:

aln_value=call([script_dir+"/software/bwa","mem", "-t 4", "-M", script_dir+"/ref/hg19.navin", args.fastq_file ],stderr=ERR_LOG,stdout=OUT_LOG)

Is there a simple alternative that allows me to specify the outputfile from within the python script?

Thanks , Lien

bwa mem python • 7.2k views
ADD COMMENT
0
Entering edit mode

You can build the command as a string in python however you want, then run the command using os.system:

import os
cmd = "bwa mem -t 4 -M " + script_dir + "/ref/hg19.navin " + fastq_file + " > output"
os.system(cmd)
ADD REPLY
0
Entering edit mode

Thanks, this worked for me (Python 3.7). It seems that BWA doesn't work properly with os.subprocess(), but instead os.system() works perfectly. The bug about os.subprocess() should be something with output handling, I'm not sure.

ADD REPLY
2
Entering edit mode
8.5 years ago
Picasa ▴ 650

Take a look at subprocess

ADD COMMENT
0
Entering edit mode

This would be the ideal option as it would let you rebuild shell style pipelines in python. Something like bwa mem .... | samtools view ...

ADD REPLY

Login before adding your answer.

Traffic: 1705 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