0

I would like to run a python program that interacts with the terminal to run another program and waits for it to complete before moving on. I have tried:

os.system('intersectBed -a Mutations.bed -b Promoters.bed -wb >Mutations.in.Promoters.bed')
subprocess.call('intersectBed -a Mutations.bed -b Promoters.bed -wb >Mutations.in.Promoters.bed', shell=True)

Neither run as i would like them to. Is there a way to do this?

intersectBed is the program I wish to run. If i use

with open('Mutations.in.Promoters.bed','w') as f:
subprocess.call(['intersectBed','-a','Mutations.bed','-b','Promoters.bed', '-wb'], stdout=f)

It gives an error that no such file or directory exists. But if i put that command into the terminal it works perfectly. The intersectBed is in the /bin folder. Does that make a difference?

EDIT*

with open('Mutations.in.Promoters.bed','w') as f:
subprocess.call(['/usr/local/bin/intersectBed','-a','Mutations.bed','-b','Promoters.bed', '-wb'], stdout=f)

THIS WORKED

asked Feb 7, 2014 at 16:30
3
  • What happens when you run those commands? What error messages do you get? Commented Feb 7, 2014 at 16:36
  • I don't get error messages. It runs. It just creates a blank file named Mutations.in.Promoters.bed. This created file should be about 2GB, not 0KB. Commented Feb 7, 2014 at 16:45
  • Does specifying the full path of intersectBed help? Commented Feb 7, 2014 at 17:19

1 Answer 1

1

Try this:

with open('Mutations.in.Promoters.bed', 'w') as f:
 subprocess.call(['intersectBed', '-a', 'Mutations.bed', '-b', 'Promoters.bed', '-wb'], stdout=f)

Referring to the documentation of subprocess, the use of shell=True should be avoided.

answered Feb 7, 2014 at 16:51
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.