Chinaunix首页 | 论坛 | 博客
  • 博客访问: 40801
  • 博文数量: 14
  • 博客积分: 770
  • 博客等级: 军士长
  • 技术积分: 200
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-30 09:35
文章分类

全部博文(14)

文章存档

2011年(1)

2008年(13)

我的朋友

分类: Python/Ruby

2008-03-31 16:33:54

    在生物信息学中,对BLAST结果文件的解析是最为普遍的一个工作之一,在Perl中有BioPerl可以解析,而在Python中也有BioPython,并且解析起来非常方便。由于BLAST的版本升级比较快,它的结果输出文件的格式有时也会相应变化,因此为了能正确的解析BLAST结果,在做BLAST的时候使用'-m 7'参数,使输出结果保存为xml的格式,这是由于xml的格式很少随着BLAST的版本而发生变化,所以推荐使用xml文件来做自动化分析,这能保证我们的程序能准确的解析BLAST结果。下面的代码是一个简单的框架,可以在此基础上添加内容以满足自己的需要:

#!/usr/bin/python
"""
DESCRIPTION
    Frame for parsing BLAST report

AUTHOR
    Wubin Qu: quwubin@gmail.com
"""
from Bio.Blast import NCBIXML
def parseBlast (result_file):
    result_handle = open(result_file)
    blast_parser = NCBIXML.BlastParser()
    blast_records = blast_parser.parse(result_handle)
   
    record_list = list(blast_records)

    expects = []
    for record in record_list:
  for alignment in record.alignments:
      for hsp in alignment.hsps:
          # Do whatever you want, such as
          expects.append(hsp.expect)

    return expects

def main ():
    expects = parseBlast(Blast_report_file)
    print expects
if __main__ == '__main__':
    main()
阅读(2658) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~