質問

XML 形式の BLAST 出力ファイルがあります。これは 22 のクエリ配列であり、各配列から 50 件のヒットが報告されます。そして、50x22 のヒットをすべて抽出したいと考えています。これは私が現在持っているコードですが、最初のクエリから 50 件のヒットのみを抽出します。

from Bio.Blast import NCBIXM
blast_records = NCBIXML.parse(result_handle)
blast_record = blast_records.next()

save_file = open("/Users/jonbra/Desktop/my_fasta_seq.fasta", 'w')

for alignment in blast_record.alignments:
    for hsp in alignment.hsps:
            save_file.write('>%s\n' % (alignment.title,))
save_file.close()

すべてのヒットを抽出する方法について誰かが提案を持っていますか?アライメント以外の何かを使用する必要があると思います。これが明らかだったことを願っています。ありがとう!

ジョン

役に立ちましたか?

解決

これにより、すべてのレコードが取得されるはずです。オリジナルと比べて目新しい点は、

for blast_record in blast_records

これは、blast_records ( CBIXML モジュールのドキュメント parse() が実際に反復子を返すことを示しました)

from Bio.Blast import NCBIXM
blast_records = NCBIXML.parse(result_handle)

save_file = open("/Users/jonbra/Desktop/my_fasta_seq.fasta", 'w')

for blast_record in blast_records:
  for alignment in blast_record.alignments:
      for hsp in alignment.hsps:
            save_file.write('>%s\n' % (alignment.title,))
  #here possibly to output something to file, between each blast_record
save_file.close()

他のヒント

私はすべての結果

抽出するためのこのコードを使用しました
from Bio.Blast import NCBIXML
for record in NCBIXML.parse(open("rpoD.xml")) :
    print "QUERY: %s" % record.query
    for align in record.alignments :
        print " MATCH: %s..." % align.title[:60]
        for hsp in align.hsps :
            print " HSP, e=%f, from position %i to %i" \
                % (hsp.expect, hsp.query_start, hsp.query_end)
            if hsp.align_length < 60 :
                 print "  Query: %s" % hsp.query
                 print "  Match: %s" % hsp.match
                 print "  Sbjct: %s" % hsp.sbjct
            else :
                 print "  Query: %s..." % hsp.query[:57]
                 print "  Match: %s..." % hsp.match[:57]
                 print "  Sbjct: %s..." % hsp.sbjct[:57]


print "Done"

以下の詳細について

from Bio.Blast import NCBIXML
for record in NCBIXML.parse(open("NC_003197.xml")) :
    #We want to ignore any queries with no search results:
    if record.alignments :
        print "QUERY: %s..." % record.query[:60]
        for align in record.alignments :
            for hsp in align.hsps :
                print " %s HSP, e=%f, from position %i to %i" \
                % (align.hit_id, hsp.expect, hsp.query_start, hsp.query_end)
print "Done"

私はこのサイトを使用

ます。http://www2.warwick。 ac.uk/fac/sci/moac/currentstudents/peter_cock/python/rpsblast/する

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top