[英]subprocess.call to run mafft
I wrote a script to run mafft module from the terminal: 我写了一个脚本从终端运行mafft模块:
import subprocess
def linsi_MSA(sequnces_file_path):
cmd = ' mafft --maxiterate 1000 --localpair {seqs} > {out}'.format(seqs=sequnces_file_path, out=sequnces_file_path)
subprocess.call(cmd.split(), shell=True)
if __name__ == '__main__':
import logging
logger = logging.getLogger('main')
from sys import argv
if len(argv) < 2:
logger.error('Usage: MSA <sequnces_file_path> ')
exit()
else:
linsi_MSA(*argv[1:])
for some reason when trying to run the script from the terminal using: 由于某些原因,当尝试使用以下命令从终端运行脚本时:
python ./MSA.py ./sample.fa
I get the mafft interactive version opening directly in the trminal (asking for input ..output etc..) 我直接在终端打开了mafft交互式版本(要求输入..output等。)
when i'm trying to write the cmd directly in the terminal using: 当我尝试使用以下命令直接在终端中编写cmd时:
mafft --maxiterate 1000 --localpair sample.fa > sample.fa
its working as expected and perfoming the command line version as without opening the interactive version. 它可以按预期方式工作,并且无需打开交互式版本即可执行命令行版本。
I want my script to be able to perform the cmd line version on the terminal. 我希望我的脚本能够在终端上执行cmd行版本。 what seems to be the problem? 似乎是什么问题?
thanks! 谢谢!
If you use shell=True
you should pass one string as argument, not a list, eg: 如果使用shell=True
,则应传递一个字符串作为参数,而不是列表,例如:
subprocess.call("ls > outfile", shell=True)
It's not explained in the docs, but I suspect it has to do with what low-level library function is ultimately called: 在文档中没有对此进行解释,但是我怀疑它与最终调用的底层库函数有关:
call(["ls", "-l"]) --> execlp("ls", "-l")
^^^^^^^^^^ ^^^^^^^^^^
call("ls -l", shell=True) --> execlp("sh", "-c", "ls -l")
^^^^^^^ ^^^^^^^
call(["ls", "-l"], shell=True) --> execlp("sh", "-c", "ls", "-l")
# which can be tried from command line:
sh -c ls -l
# result is a list of files without details, -l was ignored.
# see sh(1) man page for -c string syntax and what happens to further arguments.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.