题
我想生成树fasta文件输入以及与MuscleCommandline
import sys,os, subprocess
from Bio import AlignIO
from Bio.Align.Applications import MuscleCommandline
cline = MuscleCommandline(input="c:\Python26\opuntia.fasta")
child= subprocess.Popen(str(cline),
stdout = subprocess.PIPE,
stderr=subprocess.PIPE,
shell=(sys.platform!="win32"))
align=AlignIO.read(child.stdout,"fasta")
outfile=open('c:\Python26\opuntia.phy','w')
AlignIO.write([align],outfile,'phylip')
outfile.close()
我总是会遇到这些问题
Traceback (most recent call last):
File "<string>", line 244, in run_nodebug
File "C:\Python26\muscleIO.py", line 11, in <module>
align=AlignIO.read(child.stdout,"fasta")
File "C:\Python26\Lib\site-packages\Bio\AlignIO\__init__.py", line 423, in read
raise ValueError("No records found in handle")
ValueError: No records found in handle
解决方案
1.54 Biopython今天被释放与Bio.Phylo模块的稳定版本。我已经更新了一个例子管道用于生成树木的文档。为了简单起见,该示例使用ClustalW比对序列和产生一个树,而不是肌肉和PHYLIP,但大部分的代码仍然是相同的或相似的。
http://biopython.org/wiki/Phylo#Example_pipeline
如果您已经生成的树PHYLIP(使用.phy对准作为输入),仍可以遵循一般Phylo例子。 PHYLIP创建Newick文件中包含 “outttree” 或 “foo.tree” 的名称。
(随时与布拉德的回答这个合并;我不能写在该线程评论还)
其他提示
一对夫妇的事情给予的问题:
你需要一个孩子。等()后子进程的呼叫所以,你的代码等到外部程序完成运行。
肌肉实际上没有写信给stdout,尽管帮助的文档说是这样,至少有3.6个,我在这里。我认为,最新的是v3。8因此,这可能是固定的。
Biopython是告诉你,stdout你穿它是空的,这是错误你都看到的。试试运行命令行直接:
muscle -in opuntia.fasta
看看如果你看到FASTA输出。这里是一个版本,修复等问题,并使用中间输出的文件:
import sys,os, subprocess
from Bio import AlignIO
from Bio.Align.Applications import MuscleCommandline
out_file = "opuntia.aln"
cline = MuscleCommandline(input="opuntia.fasta", out=out_file)
child= subprocess.Popen(str(cline),
stdout = subprocess.PIPE,
stderr=subprocess.PIPE,
shell=(sys.platform!="win32"))
child.wait()
with open(out_file) as align_handle:
align=AlignIO.read(align_handle,"fasta")
outfile=open('opuntia.phy','w')
AlignIO.write([align],outfile,'phylip')
outfile.close()
os.remove(out_file)
从 subproccess库的文档:
警告
使用通信(),而不是 .stdin.write,.stdout.read或 .stderr.read避免因死锁 任何其他OS管缓冲器的 填充和阻塞的孩子 过程
所以也许你可以尝试这样的:
mydata = child.communicate()[0]
您有一个未受保护的反斜线在输出文件名,这是从来没有好。
使用 'R' 来获得原始字符串,即r'c:\Python26\opuntia.phy'
。