所以我在python中做了一些生物信息学的工作,利用Biopython和Clustalw2来对齐蛋白质序列。我对此相当陌生(只有几个月的经验),而且我在使用stdout和遍历整个目录时遇到了一个问题。任何帮助都将不胜感激。在
所以我写了这个,一次处理一个文件,产生期望的结果。。。在#!/usr/bin/python
import Bio
import os
from Bio.Align.Applications import ClustalwCommandline
from Bio import Seq
from Bio import SeqIO
from Bio import AlignIO
from Bio.SeqRecord import SeqRecord
clustal_loc=r"/Users/Wes/Desktop/eggNOG_files/clustalw-2.1-macosx/clustalw2"
try:
f_in=raw_input("Enter the filepath of the FASTA to align: ")
f_out= raw_input("Enter the output filename: ")
fh= open(f_in)
fo=open(f_out,'w')
for record in SeqIO.parse(fh,"fasta"):
id = record.id
seq = record.seq
print("Name: %s, size: %s"%(id,len(seq)))
try:
cl = ClustalwCommandline(clustal_loc,infile=f_in, outfile=f_out, align=True, outorder="ALIGNED", convert=True, output="pir")
assert os.path.isfile(clustal_loc), "Clustal W not found"
stdout, stderr = cl()
print cl
except:
print("There was a problem aligning. Check ClustalW path and .fasta input.")
fh.close()
fo.close()
except:
print("Could not parse. Check to make sure filepath is correct and that file is in FASTA format")
……这似乎很管用。当我试图在整个目录(比如1000多个需要对齐的蛋白质序列文件)上迭代时,问题就来了。我知道问题出在stdout上,但我现在太业余了,不知道如何解决它。下面是坏代码-
^{pr2}$
如你所见,我把这件事搞得一团糟。谢谢你能提供的任何帮助。在