当我运行这个程序时,我得到了q
的所有输出,但是q
应该创建的.mafft是空的。编辑:我忘了问真正的问题。我做错什么了?是不是有些语法我不知道?
#!/usr/bin/python
import sys
import os
import math
data = sys.argv[2]
b = sys.argv[1]
bfile = open(b, "r")
for barcode in bfile:
barcode = barcode.strip()
print "barcode: %s" %barcode
outfname = "%s.%s.fasta" % (data, barcode)
print outfname
outf = open(outfname,"w")
handle = open(data, "r")
for line in handle:
linearr = line.split()
sid = linearr[0]
seq = linearr[1]
potential_barcode = seq[0:len(barcode)]
if potential_barcode == barcode:
outseq = line.replace(potential_barcode, "", 1)
newseq = outseq.split(' ',1)[-1].strip()
sys.stdout.write(newseq)
outf.write(">%s\n%s\n" % (sid,newseq))
gamma = outfname + ".mafft"
delta = gamma + ".stock"
q = "mafft %s > %s" % (outfname, gamma)
os.system(q)
qq = "fasta_to_stockholm %s > %s" % (gamma, delta)
os.system(qq)
qqq = "quicktree -out m %s" % (delta)
os.system(qqq)
handle.close()
outf.close()
bfile.close()
它与使用
os.system()
而不是subprocess
无关。 问题是在运行程序之前没有关闭outfname
文件。将closes移到调用os.system()
之前:mafft
(outfname
)的输入文件是空的,因为缓冲区没有被刷新,所以您“正在遭受缓冲的痛苦”。在我会考虑每个人都说的使用
subprocess
,但是在之后,你就可以使用它了!一次只改变一件事!在相关问题 更多 >
编程相关推荐