Question: calling BWA mem from within python
gravatar for lien
4.7 years ago by
lien90 wrote:

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 • 3.7k views
ADD COMMENTlink modified 4.7 years ago by Picasa590 • written 4.7 years ago by lien90

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"
ADD REPLYlink written 4.7 years ago by Damian Kao15k

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 REPLYlink written 12 months ago by Benedek Dankó10
gravatar for Picasa
4.7 years ago by
Picasa590 wrote:

Take a look at subprocess

ADD COMMENTlink written 4.7 years ago by Picasa590

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

ADD REPLYlink written 4.7 years ago by pld4.9k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 2465 users visited in the last hour