我在下面的代码中使用python3.5。在
def raxml(DIR,cleaned,num_cores,seqtype):
assert cleaned.endswith(".aln-cln"),\
"raxml infile "+cleaned+" not ends with .aln-cln"
assert seqtype == "aa" or seqtype == "dna","Input data type: dna or aa"
assert len(read_fasta_file(DIR+cleaned)) >= 4,\
"less than 4 sequences in "+DIR+cleaned
clusterID = cleaned.split(".")[0]
tree = DIR+clusterID+".raxml.tre"
raw_tree = "RAxML_bestTree."+cleaned
model = "PROTCATWAG" if seqtype == "aa" else "GTRCAT"
if not os.path.exists(tree) and not os.path.exists(raw_tree):
# raxml crashes if input file starts with .
infasta = cleaned if DIR == "./" else DIR+cleaned
cmd = ["raxml","-T",str(num_cores),"-p","12345","-s",\
infasta,"-n",cleaned,"-m",model]
print (" ".join(cmd))
p = subprocess.Popen(cmd,stdout=subprocess.PIPE)
out = p.communicate()
assert p.returncode == 0,"Error raxml"+out[0]
try:
os.rename(raw_tree,tree)
os.remove("RAxML_info."+cleaned)
os.remove("RAxML_log."+cleaned)
os.remove("RAxML_parsimonyTree."+cleaned)
os.remove("RAxML_result."+cleaned)
os.remove(DIR+cleaned+".reduced")
except: pass # no need to worry about extra intermediate files
return tree
它运行并返回以下代码:
^{pr2}$最初,我尝试了以下方法:
p = subprocess.Popen(cmd,stdout=subprocess.PIPE)
p = p.decode('utf-8')
out = p.communicate()
assert p.returncode == 0,"Error raxml"+out[0]
这根本没有解决问题。我看过类似的问题,但我不能想出一个解决办法。我希望能在这方面有所帮助。在
谢谢!在
我不知道您的p.communicate()方法到底做了什么,但它似乎返回了一个byte对象。而这段代码,不能将这个byte对象添加到“Error raxml”str对象中:
也许你应该试着把它转换成str:
^{pr2}$p
,Popen
对象没有.decode(...)
成员。在你需要真正解码输出
也就是说,可以改进此代码以使用
^{pr2}$subprocess.check_output
:或者你碰巧在用python3.6+
相关问题 更多 >
编程相关推荐