단백질 서열을 정렬하기 위해 Biopython과 Clustalw2를 사용하여 파이썬에서 약간의 생물 정보학 작업을하고 있습니다. 나는 이것 (상당히 2 개월의 경험)에 상당히 익숙하며, stdout을 사용하고 전체 디렉토리를 반복하는 데 문제가있다. 어떤 도움을 주시면 감사하겠습니다. Python을 사용하는 Bioinformatics 스크립트/Biopython/Clustalw 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 함께 알지만이 시점에서 너무 아마추어 그것을 수정하는 방법을 알고 알고 오전 .
/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")
당신은 내가 꽤 심하게이 일을 일 처리 한 덕분에 당신이 제공 할 수있는 모든 도움을 볼 수있는 바와 같이
당신은 또한 BIOSTAR를 요청할 수있다 : - 오브젝트를 제출하지 http://www.biostars.org/ – Pierre
을 당신이 ClustalwCommandline 객체를 생성 경우, INFILE과 OUTFILE 인수는 문자열로 파일 이름이어야합니다. 나는 여기에 더 쓸 것이지만 주석은 내가 코드 포맷팅을하도록 내버려 두지 않는다. ... – peterjc