だから私は、タンパク質配列を整列させるためにBiopythonとClustalw2を利用して、Pythonで少しバイオインフォマティクスの仕事をしています。私はこれにかなり慣れていません (経験は数か月しかありません) が、stdout を使用してディレクトリ全体を反復処理する際に問題が発生しています。どんな助けでも大歓迎です。
だから私はこれを書きました.これは一度に1つのファイルを処理し、望ましい結果を生成します...
#!/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 にあることはわかっていますが、この時点で少し素人すぎて、修正方法を知ることができません。 . 以下は壊れたコードです —</p>
/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
import subprocess
from subprocess import Popen
clustal_loc=r"/Users/Wes/Desktop/eggNOG_files/clustalw-2.1-macosx/clustalw2"
try:
folder= raw_input("Enter the folder of .fasta files to iterate over and align: ")
listing = os.listdir(folder)
for infile in listing:
print folder+'/'+infile
f_in = open(folder+'/'+infile,'r')
f_out=open(folder+'/'+infile+".pir",'w')
for record in SeqIO.parse(f_in,"fasta"):
id = record.id
seq = record.seq
print("Name: %s, size: %s"%(id,len(seq)))
clustalw_cline= 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"
saveout = sys.stdout
sys.stdout = clustalw_cline()
sys.stdout = saveout
f_in.close()
f_out.close()
except:
print("There was a problem aligning. Check ClustalW path and .fasta folder format/location")
ご覧のとおり、私はこれをかなりひどくいじっています。ご協力いただきありがとうございます。