根据位置连接爆炸命中的子集以获得完整的命中

2024-05-13 19:52:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我用生物圈来做类似的事情, Sort rps-blast results by position of the hit但希望连接或连接本地命中,以获得连续的查询和主题命中。在

我的代码:

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

这将给出排序结果:

^{pr2}$

这一切都很好,但我想进入下一个逻辑步骤,那就是将这里显示的所有三个子查询和子点击(点击的数量会有所不同),以获得完整的查询和主题序列。未来的路怎么走?在


Tags: theinfortitlepositionquerystartsb
1条回答
网友
1楼 · 发布于 2024-05-13 19:52:02

好的,我给你一个样品溶液。希望,这会有帮助!在

可以在循环外部创建一个空变量,并将查询字符串连接到该变量。以下是对给定代码的编辑:

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

相关问题 更多 >