[英]How to call a program installed on linux from within python?
This is what I've been trying 这就是我一直在尝试的
def test():
import sys
import subprocess
file1 = open(sys.argv[1],"r") #this is the input to fastacmd
idx = file1.readlines()
outname = idx[0].split("\r\n")[0]
foutname = outname + "_f_output"
astaseq = subprocess.call(["fastacmd","-i", file1, "-o",foutname])
blastresult = subprocess.call(["blastp", "-db", "db1.faa", "-query", foutname, "-out", outname])
But I get caught with this, and I can't really make sense of it 但是我被这个抓住了,我真的无法理解它
File "test.py", line 16, in <module>
fastacmd_blastp()
File "test.py", line 11, in test
fastaseq = subprocess.call(["fastacmd","-i", file1, "-o",fastaoutname])
File "/usr/local/lib/python2.7/subprocess.py", line 486, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/local/lib/python2.7/subprocess.py", line 672, in __init__
errread, errwrite)
File "/usr/local/lib/python2.7/subprocess.py", line 1202, in _execute_child
raise child_exception
TypeError: execv() arg 2 must contain only strings
Can anyone help? 有人可以帮忙吗? thanks 谢谢
Guess the input file should be the filename sys.argv[1]
and not the python handle to the file. 猜猜输入文件应该是文件名sys.argv[1]
而不是文件的python句柄。 ( http://nebc.nerc.ac.uk/bioinformatics/documentation/blast/fastacmd.html ) ( http://nebc.nerc.ac.uk/bioinformatics/documentation/blast/fastacmd.html )
In other words, change astaseq = subprocess.call(["fastacmd","-i", file1, "-o",foutname])
to astaseq = subprocess.call(["fastacmd","-i", sys.argv[1], "-o",foutname])
换句话说,将astaseq = subprocess.call(["fastacmd","-i", file1, "-o",foutname])
更改为astaseq = subprocess.call(["fastacmd","-i", sys.argv[1], "-o",foutname])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.