Entrez 是NCBI提供的在线搜索系统.它通过支持布尔运算符和字段搜索的集成全局查询,提供对几乎所有已知分子生物学数据库的访问.它返回来自所有数据库的结果,其中包含来自每个数据库的命中数,带有指向原始数据库的链接的记录等信息.
可以通过Entrez访问的一些流行数据库列出如下 :
Pubmed
Pubmed Central
核苷酸(GenBank序列数据库)
蛋白质(序列数据库)
基因组(全基因组数据库)
结构(三维大分子结构)
分类学(GenBank中的生物)
SNP(单核苷酸多态性)
UniGene(基因导向的转录序列簇)
CDD(保守蛋白质域数据库)
3D域(来自Entrez结构的域) )
除上述数据库外,Entrez还提供了更多数据库来执行字段搜索.
Biopython提供Entrez特定的模块le,Bio.Entrez访问Entrez数据库.让我们在本章中学习如何使用Biopython访问Entrez :
数据库连接步骤
要添加Entrez的功能,请导入以下模块 :
>>>来自Bio import Entrez
接下来设置您的电子邮件,以确定谁与下面给出的代码相关联;<
>>> Entrez.email ='< youremail>'
然后,设置Entrez工具参数,默认情况下,它是Biopython.
>>> Entrez.tool ='Demoscript'
现在,调用einfo函数查找索引术语计数,上次更新以及每个数据库的可用链接如下定义 :
>>> info = Entrez.einfo()
einfo方法返回一个对象,通过其读取方法提供对信息的访问,如下所示 :
>>> data = info.read() >>> print(data)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
数据采用XML格式,要将数据作为python对象获取,请尽快使用 Entrez.read 方法调用Entrez.einfo()方法 :
>>> info = Entrez.einfo()>>> record = Entrez.read(info)
这里,record是一个字典,它有一个键,DbList如下所示 :
>>> record.keys() [u'DbList']
访问DbList键返回下面显示的数据库名称列表 :
>>> record[u'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模块解析Entrez搜索系统返回的XML并将其作为python词典和列表提供.
搜索数据库
要搜索Entrez数据库中的任何一个,我们可以使用Bio.Entrez.esearch()模块.它的定义低于 :
>>> info = Entrez.einfo() >>> info = Entrez.esearch(db = "pubmed",term = "genome") >>> record = Entrez.read(info) >>>print(record) DictElement({u'Count': '1146113', u'RetMax': '20', u'IdList':['30347444', '30347404', '30347317', '30347292', '30347286', '30347249', '30347194', '30347187', '30347172', '30347088', '30347075', '30346992', '30346990', '30346982', '30346980', '30346969', '30346962', '30346954', '30346941', '30346939'], u'TranslationStack': [DictElement({u'Count': '927819', u'Field': 'MeSH Terms', u'Term': '"genome"[MeSH Terms]', u'Explode': 'Y'}, attributes = {}), DictElement({u'Count': '422712', u'Field': 'All Fields', u'Term': '"genome"[All Fields]', u'Explode': 'N'}, attributes = {}), 'OR', 'GROUP'], u'TranslationSet': [DictElement({u'To': '"genome"[MeSH Terms] OR "genome"[All Fields]', u'From': 'genome'}, attributes = {})], u'RetStart': '0', u'QueryTranslation': '"genome"[MeSH Terms] OR "genome"[All Fields]'}, attributes = {})>>>
如果您指定了错误的数据库,则返回
>>> info = Entrez.esearch(db = "blastdbinfo",term = "books")>>> record = Entrez.read(info) >>> print(record) DictElement({u'Count': '0', u'RetMax': '0', u'IdList': [], u'WarningList': DictElement({u'OutputMessage': ['No items found.'], u'PhraseIgnored': [], u'QuotedPhraseNotFound': []}, attributes = {}), u'ErrorList': DictElement({u'FieldNotFound': [], u'PhraseNotFound': ['books']}, attributes = {}), u'TranslationSet': [], u'RetStart': '0', u'QueryTranslation': '(books[All Fields])'}, attributes = {})
如果要跨数据库搜索,然后你可以使用 Entrez.egquery .这类似于 Entrez.esearch ,但它足以指定关键字并跳过数据库参数.
>>>info = Entrez.egquery(term = "entrez") >>> record = Entrez.read(info) >>> for row in record["eGQueryResult"]: ... print(row["DbName"], row["Count"]) ... pubmed 458 pmc 12779 mesh 1 ... ... ... biosample 7 biocollections 0
获取记录
Enterz提供了一种特殊方法,用于搜索和下载Entrez记录的完整详细信息.请考虑以下简单示例 :
>>> handle = Entrez.efetch( db ="nucleotide",id ="EU490707",rettype ="fasta")
现在,我们可以只需使用SeqIO对象读取记录
>>> record = SeqIO.read( handle, "fasta" ) >>> record SeqRecord(seq = Seq('ATTTTTTACGAACCTGTGGAAATTTTTGGTTATGACAATAAATCTAGTTTAGTA...GAA', SingleLetterAlphabet()), id = 'EU490707.1', name = 'EU490707.1', description = 'EU490707.1 Selenipedium aequinoctiale maturase K (matK) gene, partial cds; chloroplast', dbxrefs = [])