2

私は biopython を使用して 、ヒットの位置で rps-blast の結果を並べ替えますが、ローカルヒットを結合または連結して、連続したクエリとサブジェクトヒットを取得したいと考えています。

私のコード:

for record in records:
   for alignment in record.alignments:
                hits = sorted((hsp.query_start, hsp.query_end, hsp.sbjct_start, hsp.sbjct_end, alignment.title, hsp.query, hsp.sbjct)\
                               for hsp in alignment.hsps)
                for q_start, q_end, sb_start, sb_end, title, query, sbjct in hits:
                      print title
                      print 'The query starts from position: ' + str(q_start)
                      print 'The query ends at position: ' + str(q_end)
                      print 'The hit starts at position: ' + str(sb_start)
                      print 'The hit ends at position: ' + str(sb_end)
                      print 'The  query is: ' + query
                      print 'The hit is: ' + sbjct

これにより、次のようにソートされた結果が得られます。

Species_1
The query starts from position: 1
The query ends at position: 184
The hit starts at position: 1
The hit ends at position: 552
The query is: #######query_seq
The hit is: ######### hit_seq
Species_1
The query starts from position: 390
The query ends at position: 510
The hit starts at position: 549
The hit ends at position: 911
The query is: #######query_seq
The hit is: ######### hit_seq
Species_1
The query starts from position: 492
The query ends at position: 787
The hit starts at position: 889
The hit ends at position: 1776
The query is: #######query_seq
The hit is: ######### hit_seq

これで問題ありませんが、次の論理的なステップに進みたいと思います。つまり、ここに示す 3 つの sub_queries とサブヒットをすべて連結して (ヒットの数は異なります)、完全なクエリとサブジェクトのシーケンスを取得します。今後の方向性は?

4

1 に答える 1

0

わかりましたので、サンプルソリューションを提供します。うまくいけば、それは役に立ちます!

ループの外側で空の変数を作成し、クエリ文字列をその変数に連結できます。指定されたコードの編集は次のとおりです。

expected_query_seq = ""
for record in records:
   for alignment in record.alignments:
                hits = sorted((hsp.query_start, hsp.query_end, hsp.sbjct_start, hsp.sbjct_end, alignment.title, hsp.query, hsp.sbjct)\
                               for hsp in alignment.hsps)
                for q_start, q_end, sb_start, sb_end, title, query, sbjct in hits:
                      print title
                      print 'The query starts from position: ' + str(q_start)
                      print 'The query ends at position: ' + str(q_end)
                      print 'The hit starts at position: ' + str(sb_start)
                      print 'The hit ends at position: ' + str(sb_end)
                      print 'The  query is: ' + query
                      print 'The hit is: ' + sbjct

                      expected_query_seq += str(query[q_start:q_end])
print expected_query_seq
于 2014-02-01T23:34:57.543 に答える