2016-04-15 30 views
1

マルチファーストBLAST結果を含むxmlファイルを解析しようとしています - ここにはlinkがあります。サイズは約400KBです。プログラムは4つのシーケンス名を返さなければなりません。すべての次の結果が第1の後でなければなりません(最良のアライメントが含まれています) "< Iteration_iter-num>はN < Iteration_iter-NUM />" このように、ここで、n = 1,2,3、...マルチファストBLAST結果を含むPythonでxmlファイルを解析する

< Iteration_iter-num >1< /Iteration_iter-num > 

****Alignment**** 
sequence: gi|171864|gb|AAC04946.1| Yal011wp [Saccharomyces cerevisiae] 

< Iteration_iter-num >2< /Iteration_iter-num > 

****Alignment**** 
sequence: gi|330443384|ref|NP_009392.2| 

< Iteration_iter-num >3< /Iteration_iter-num > 

****Alignment**** 
sequence: gi|6319310|ref|NP_009393.1| 

< Iteration_iter-num >4< /Iteration_iter-num > 

****Alignment**** 
sequence: gi|6319312|ref|NP_009395.1| 

しかし、結果に私のプログラムは、これを返します。

<Iteration_iter-num>1</Iteration_iter-num> 
****Alignment**** 
sequence: gi|171864|gb|AAC04946.1| Yal011wp [Saccharomyces cerevisiae] 

<Iteration_iter-num>2</Iteration_iter-num> 
****Alignment**** 
sequence: gi|171864|gb|AAC04946.1| Yal011wp [Saccharomyces cerevisiae] 

<Iteration_iter-num>3</Iteration_iter-num> 
****Alignment**** 
sequence: gi|171864|gb|AAC04946.1| Yal011wp [Saccharomyces cerevisiae] 

<Iteration_iter-num>4</Iteration_iter-num> 
****Alignment**** 
sequence: gi|171864|gb|AAC04946.1| Yal011wp [Saccharomyces cerevisiae] 

このxmlファイルから別のBLASTA結果を取得する方法は?

はここに私のコードです:私は私の英語が完璧ではないですけど、私は本当に何をすべきかわからない、私はそれを求めるためにすべての人を持っていない//

from Bio.Blast import NCBIXML 
from bs4 import BeautifulSoup 

result = open ("BLAST_left.xml", "r") 
records = NCBIXML.parse(result) 
item = next(records) 

file = open("BLAST_left.xml") 
page = file.read() 
soup = BeautifulSoup(page, "xml") 
num_xml_array = soup.find_all('Iteration_iter-num') 
i = 0 
for records in records: 
    for itemm in num_xml_array: 
     print (itemm) 
     for alignment in item.alignments: 
      for hsp in alignment.hsps: 
       print("\n\n****Alignment****") 
       print("sequence:", alignment.title) 
      break 
     itemm = num_xml_array[i+1] 
    break 

、私はあなたを選んだ:)

答えて

1

を私はBiopythonは、XMLを解析するために、ここで良いオプション、BeautifulSoupを使用することがないニートだと思う:

from Bio.Blast import NCBIXML 


result = open("BLAST_left.xml", "r") 
records = NCBIXML.parse(result) 

for i, record in enumerate(records): 
    for align in record.alignments: 
     print("Iteration {}".format(i)) 
     print(align.hit_id) 
     break # Breaking here gives you only the best HSP. 
0

あなたがでビルドモジュールxml.etree.ElementTreeをパイソンを使用することができますXMLを解析する

import xml.etree.ElementTree as ET 
tree = ET.parse('BLAST_left.xml') 
doc = tree.getroot() 
for item in doc.find('BlastOutput_iterations'): 
    print '< Iteration_iter-num >{0}< /Iteration_iter-num >'.format(item.find('Iteration_iter-num').text) 
    print '** ** Alignment ** **' 
    print 'sequence:{0}|{1}'.format(item.find('Iteration_hits/Hit/Hit_id').text, item.find('Iteration_hits/Hit/Hit_def').text) 
関連する問題