JayB
JayB

Reputation: 103

Python Subprocess - variable types?

I'm working a python code that uses some programs accessible only from my Unix terminal (Windows 7 OS, using a putty terminal) I have already looked at countless articles, I know that similar questions have been asked but nothing is working for me.

This is the code

#written in Py 2.7

from subprocess import call

subject = open ('test_file1', 'r')
target =open ('test_file2', 'r')
output = open ('output_test.bla8', 'w')
call(['blat', '-prot', '-minScore=0', '-stepSize=5', '-repMatch=2253', '-minIdentity=0', '-out=blast8', subject, target, output])
subject.close()
target.close()
output.close()

The error I receive is this:

TypeError: execv() arg 2 must contain only strings

So a bit of explanation, "blat" is the program I am calling, all the -flags are arguments that I want to pass to the blat program and the last three statements are also arguments that I need to get to program but they actually specify files for the program to read/write.

Is there a way to pass argument values to a shell command that are actually files if not using 'subprocess.call'?? Surely there is a simple way to accomplish this, that as I beginner I'm just not aware of. By the way I have had a glance at the subprocess docs, but as a newbie I still can't quite get it http://docs.python.org/2/library/subprocess.html#subprocess.call

THANKS!!!

Upvotes: 0

Views: 255

Answers (2)

JayB
JayB

Reputation: 103

I solved this issue using this code:

new_list= []
for file in os.listdir('.'):
    if fnmatch.fnmatch(file, '*.fa'):
    new_list.append(file)

input_file1 = new_list[0]
input_file2 = new_list[1]
blat =call(['blat', '-prot', '-minScore=0', '-stepSize=5', '-repMatch=2253', 'minIdentity=0', '-out=blast8', input_file1 , input_file1, 'output_test'])

Upvotes: 0

bj0
bj0

Reputation: 8213

When you do:

f = open('file','r')

your Python process is opening the file and storing the file handle/object in f. This open file handle/object cannot be put on a commandline (you can't type it), so you are getting an error from call, which takes commandline arguments.

If your 'blat' program takes filenames and opens the file in its own process, you should just remove the open calls and just put the filenames directly into the call call. If that's not what blat does, than you need to understand how it gets its data and pass it in that form.

Upvotes: 3

Related Questions