Biopython从NCBI搜索和取回数据库记录

Entrez模块

Entrez提供了链向在NCBI服务器的esearch和efetch工具的连接

列出Entrez模块的方法和属性

#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'sunchengquan'
__mail__ = '1641562360@qq.com'

from Bio import Entrez
s = dir(Entrez)
print(s)

运行结果:
['_HTTPError', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '_as_bytes', '_binary_to_string_handle', '_construct_cgi', '_construct_params', '_encode_options', '_open', '_update_ecitmatch_variables', '_urlencode', '_urlopen', 'ecitmatch', 'efetch', 'egquery', 'einfo', 'elink', 'email', 'epost', 'esearch', 'espell', 'esummary', 'parse', 'print_function', 'read', 'time', 'tool', 'warnings']

Entrez数据库提供了什么

#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'sunchengquan'
__mail__ = '1641562360@qq.com'

#从Entrez数据库得到信息,使用Entrez.einfo()函数
from Bio import Entrez
#email属性把邮箱地址告诉NCBI(可选)
Entrez.email = '1641562360@qq.com'
handle = Entrez.einfo()
info = Entrez.read(handle)
print(info)

运行结果:
{'DbList': ['pubmed', 'protein', 'nuccore', 'ipg', 'nucleotide', 'nucgss', 'nucest', 'structure', 'sparcle', 'genome', 'annotinfo', 'assembly', 'bioproject', 'biosample', 'blastdbinfo', 'books', 'cdd', 'clinvar', 'clone', 'gap', 'gapplus', 'grasp', 'dbvar', 'gene', 'gds', 'geoprofiles', 'homologene', 'medgen', 'mesh', 'ncbisearch', 'nlmcatalog', 'omim', 'orgtrack', 'pmc', 'popset', 'probe', 'proteinclusters', 'pcassay', 'biosystems', 'pccompound', 'pcsubstance', 'pubmedhealth', 'seqannot', 'snp', 'sra', 'taxonomy', 'biocollections', 'unigene', 'gencoll', 'gtr']}

#给定一个数据库名字作为Entrez.einfo()的参数
#则可以得到关于这个数据库的信息
from Bio import Entrez
Entrez.email = '1641562360@qq.com'
handle = Entrez.einfo(db ='pubmed')
info = Entrez.read(handle)
#print(info)
#print(info['DbInfo'])
print(info.keys())
print(info['DbInfo']['Description'])

运行结果:
dict_keys(['DbInfo'])
PubMed bibliographic record

多于一个术语搜索Pubmed,用AND/OR组合关键词

#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'sunchengquan'
__mail__ = '1641562360@qq.com'

from Bio import Entrez
Entrez.email = '1641562360@qq.com'
handle = Entrez.esearch(db='pubmed',term='PyCogent AND RNA')
record = Entrez.read(handle)
print(record['IdList'])
运行结果:
['18230758']

#验证在NCBI网站pumed用关键词‘PyCogent AND RNA’检索

这里写图片描述

#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'sunchengquan'
__mail__ = '1641562360@qq.com'

from Bio import Entrez
Entrez.email = '1641562360@qq.com'
handle = Entrez.esearch(db='pubmed',term='PyCogent OR RNA')
record = Entrez.read(handle)
print(record['Count'])
运行结果:
961515

这里写图片描述


#可选参数retmax最大返回数目,可以用来设置查询文本的最大检索数目
from Bio import Entrez
Entrez.email = '1641562360@qq.com'
handle = Entrez.esearch(db='pubmed',term='PyCogent or RAN',retmax=3)
record = Entrez.read(handle)
print(record['IdList'])
运行结果:
['29192776', '29191911', '29191431']

用GenBank格式检索和解析核酸数据库条目

#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'sunchengquan'
__mail__ = '1641562360@qq.com'

from Bio import Entrez
# search sequences by a combination of keywords
Entrez.email = '1641562360@qq.com'
handle = Entrez.esearch(db='nucleotide',term='Homo sapiens AND mRNA AND Mapk')
records = Entrez.read(handle)
print(records['Count'])
top3_records = records['IdList'][0:3]
print(top3_records)
# retriveve the sequences by their GI number
#多个ID必须用一个逗号隔开的GI号的字符串
gi_list = ','.join(top3_records)
print(gi_list)
#文件格式retmode必须设置成xml
handle = Entrez.efetch(db='nucleotide',id=gi_list,rettype='gb',retmode='xml')
records = Entrez.read(handle)
print(len(records))
print(records[0].keys())
print(records[0]['GBSeq_organism'])

运行结果:
2855
['385298702', '373938425', '239046737']
385298702,373938425,239046737
3
dict_keys(['GBSeq_locus', 'GBSeq_length', 'GBSeq_strandedness', 'GBSeq_moltype', 'GBSeq_topology', 'GBSeq_division', 'GBSeq_update-date', 'GBSeq_create-date', 'GBSeq_definition', 'GBSeq_primary-accession', 'GBSeq_accession-version', 'GBSeq_other-seqids', 'GBSeq_keywords', 'GBSeq_source', 'GBSeq_organism', 'GBSeq_taxonomy', 'GBSeq_references', 'GBSeq_comment', 'GBSeq_primary', 'GBSeq_feature-table', 'GBSeq_sequence'])
Homo sapiens

用关键词搜索NCBI蛋白质数据库条目

#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = 'sunchengquan'
__mail__ = '1641562360@qq.com'

from Bio import Entrez
# search sequences by a combination of keywords
Entrez.email = '1641562360@qq.com'
handle = Entrez.esearch(db='protein',term='Human AND cancer AND p21')
records = Entrez.read(handle)
print(records['Count'])
id_list = records['IdList'][0:3]
#retrieve sequences
id_list = ','.join(id_list)
print(id_list)
handle = Entrez.efetch(db='protein',id=id_list,rettype='fasta',retmode='xml')
records = Entrez.read(handle)
print(records[0].keys())
print(records[0]['TSeq_defline'])

运行结果:
1320
161377472,161377470,161377468
dict_keys(['TSeq_seqtype', 'TSeq_gi', 'TSeq_accver', 'TSeq_taxid', 'TSeq_orgname', 'TSeq_defline', 'TSeq_length', 'TSeq_sequence'])
cyclin-A1 isoform c [Homo sapiens]
  • 5
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值