科学计算与排版:Python 工具与 LaTeX 入门
1. 编程式 BLAST 搜索
1.1 BLAST 简介
基本局部比对搜索工具(BLAST)用于寻找生物序列之间的相似区域。Biopython 提供了一个模块,方便我们对在线数据库进行 BLAST 搜索。
1.2 代码实现
# NCBIWWW 允许以编程方式访问 NCBI 的 BLAST 服务器 from Bio.Blast import NCBIWWW # 使用 SeqIO 检索序列 handle = open("Uropsilus_BMI1.fasta", "r") # 将 SeqRecord 转换为列表以便于访问 records = list(SeqIO.parse(handle, "fasta")) # 检索第四条序列 print(records[3].id, " ", records[3].seq)1.3 运行 BLAST 搜索
# 始终告知 NCBI 你是谁 Entrez.email = "me@bigu.edu" # NCBIWWW.qblast 需要三个参数:程序、数据库、序列 result_handle = NCBIWWW.qblast("blastn", "nt", records[3].seq) # 设置输出文件 save_file = open("my_blast.xml", "w") # 将结果写入输出文件 save_file.write(result_handle.read()) sa