luria的个人博客分享 http://blog.sciencenet.cn/u/luria

博文

使用Biopython解析Blast结果(二)

已有 4975 次阅读 2020-3-19 16:55 |个人分类:BioIT|系统分类:科研笔记| blast, python, biopython, blast格式, xml

之前整理了一份采用biopython来解析blast format 5结果文件的博文:<使用Biopython解析Blast结果>,但是有朋友联系我说写得不够直观,今天再次用到biopython来解析blast format 5这种xml格式的文件。重新整理了一下,如下图:


用代码展示blast结果format 6format 5对应关系:

from Bio.Blast import NCBIXML

for record in NCBIXML.parse(open("blast_fmt5.xml")):

      print record.query  #这里对应format 6中的第一列query

      for element in record.alignments:

           print element.hit_def

           #对应format 6subject列。之前的博文中这里输出的结果为None,但是这次是可以直接输出的,可能是之前用的比较老的版本,目前测试版本为2.7.1+。如果读者在测试时输出为None,可以采用在element.titlesubject信息取出来

 

           for hsp in element.hsps:

                 print hsp.bits  #这里对应format 6中的最后一列bit score

                 print hsp.except #对应format 6evalue

                 print hsp.gaps

                 #对应format 6gap open,当gap open也可以通过match算出来

 

                 print hsp.align_length #对应format 6alignment length

                 print hsp.query_start  #对应format 6中的q. start

                 print hsp.query_end  #对应format 6中的q. end

                 print hsp.sbjct_start  #对应format 6中的s. start

                 print hsp.sbjct_end  #对应format 6中的s.end

                

                 #最后剩下% identity, mismatch,可以通过hsp.match间接计算出来。

                 其中%identity表示match到的bases除以alignment长度[1,2]

 

 

参考材料:

[1] https://www.ncbi.nlm.nih.gov/books/NBK62051/

[2] https://lh3.github.io/2018/11/25/on-the-definition-of-sequence-identity




https://blog.sciencenet.cn/blog-2970729-1224295.html

上一篇:FitHiC V1算法解析(二)
下一篇:通过vcf格式的SNP位点信息找到其对应的rs号
收藏 IP: 183.95.249.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-3-29 17:19

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部