2012-07-09 89 views
2

我在通过Python调用一个名为sixpack的EMBOSS程序(通过命令行运行)时遇到问题。从python调用EMBOSS程序的麻烦

我通过Windows 7,Python版本3.23,Biopython版本1.59,EMBOSS版本6.4.0.4运行Python。 Sixpack用于翻译所有六个阅读框架中的DNA序列,并创建两个文件作为输出;识别ORF的序列文件以及包含蛋白质序列的文件。

我可以从命令行成功调用三个必需参数:(-sequence [input file]-outseq [output sequence file]-outfile [protein sequence file])。我一直在使用子进程模块来代替os.system,因为我已经读过它,它更强大和多功能。

以下是我的python代码,它运行时没有错误,但不会生成所需的输出文件。

from Bio import SeqIO 
import re 
import os 
import subprocess 

infile = input('Full path to EXISTING .fasta file would you like to open: ') 
outdir = input('NEW Directory to write outfiles to: ') 
os.mkdir(outdir) 
for record in SeqIO.parse(infile, "fasta"): 

    print("Translating (6-Frame): " + record.id) 

    ident=re.sub("\|", "-", record.id) 

    print (infile) 
    print ("Old record ID: " + record.id) 
    print ("New record ID: " + ident) 

    subprocess.call (['C:\memboss\sixpack.exe', '-sequence ' + infile, '-outseq ' + outdir + ident + '.sixpack', '-outfile ' + outdir + ident + '.format']) 

    print ("Translation of: " + infile + "\nWritten to: " + outdir + ident) 
+0

它会给出错误吗?命令是否与您在命令行上键入的命令完全相同? – 2012-07-09 15:49:08

+0

那么,不完全一样......我正在使用(字符串,变量?),如'infile','outdir'和'ident'来表示将被输入到命令行中的实际路径和文件名。子进程模块可以处理这些字符串/变量吗? – user1426421 2012-07-09 16:45:04

+0

使用变量是好的,但我的意思是:如果我将代码(基本上是一个字符串)中的命令复制并粘贴到实际的命令行,它会起作用吗?您可能需要指定完整路径,而不是相对路径才能使文件访问正常工作。 – 2012-07-09 16:50:20

回答

2

找到答案..我使用错误的语法来调用子进程。这是正确的语法:

subprocess.call (['C:\memboss\sixpack.exe', '-sequence', infile, '-outseq', outdir + ident + '.sixpack', '-outfile', outdir + ident + '.format'])