NCBI网站是最常用的生物信息数据库之一,集成了pubmed,genebank等子数据库。最简便的用法当然是直接在网站上检索,为了方便检索,NCBI提供了自己的检索系统,称之为Entrez。 对于想要在命令行访问NCBI的人而言,NCBI也提供了Eutils工具,可以通过对应的API在命令行操作。biopython将Eutils工具进行了封装,通过Bio.Entrez子模块,可以在python环境中与NCBI进行交互。 E-utilities是由8个小程序组成的工具集,能够将符合语法规则的URL转换为对应数据库的检索条件,并返回检索结果,是Entrez检索系统和NCBI数据库的接口,biopython也提供了对应的功能 该方法用于查看数据库的基本信息,用法如下 >>> Entrez.email = "577198016@qq.com" >>> handle = Entrez.einfo() >>> record = Entrez.read(handle) >>> record {'DbList': ['pubmed', 'protein', 'nuccore', 'ipg', 'nucleotide', 'structure', 'sparcle', 'protfam', 'genome', 'annotinfo', 'assembly', 'bioproject', 'biosample', 'blastdbinfo', 'books', 'cdd', 'clinvar', 'gap', 'gapplus', 'grasp', 'dbvar', 'gene', 'gds', 'geoprofiles', 'homologene', 'medgen', 'mesh', 'ncbisearch', 'nlmcatalog', 'omim', 'orgtrack', 'pmc', 'popset', 'proteinclusters', 'pcassay', 'biosystems', 'pccompound', 'pcsubstance', 'seqannot', 'snp', 'sra', 'taxonomy', 'biocollections', 'gtr']} >>> record.keys() dict_keys(['DbList']) >>> record['DbList'] ['pubmed', 'protein', 'nuccore', 'ipg', 'nucleotide', 'structure', 'sparcle', 'protfam', 'genome', 'annotinfo', 'assembly', 'bioproject', 'biosample', 'blastdbinfo', 'books', 'cdd', 'clinvar', 'gap', 'gapplus', 'grasp', 'dbvar', 'gene', 'gds', 'geoprofiles', 'homologene', 'medgen', 'mesh', 'ncbisearch', 'nlmcatalog', 'omim', 'orgtrack', 'pmc', 'popset', 'proteinclusters', 'pcassay', 'biosystems', 'pccompound', 'pcsubstance', 'seqannot', 'snp', 'sra', 'taxonomy', 'biocollections', 'gtr'] 在使用这个系统时,我们必须提供一个邮箱地址,当你访问频繁或者违反了Eutils的使用规范时,会通过邮件与你沟通。Entrez.read方法将结果读取为一个dict对象,这样方便在python中查看和处理信息。EInfo也可以查询某个特定的数据库的信息,用法如下 >>> handle = Entrez.einfo(db='pubmed') >>> record = Entrez.read(handle) >>> record.keys() dict_keys(['DbInfo']) >>> record['DbInfo'].keys() dict_keys(['DbName', 'MenuName', 'Description', 'DbBuild', 'Count', 'LastUpdate', 'FieldList', 'LinkList']) >>> record['DbInfo']['DbName'] 'pubmed' >>> record['DbInfo']['MenuName'] 'PubMed' >>> record['DbInfo']['Description'] 'PubMed bibliographic record' 2. ESearch 该方法用于检索特定的数据库,提供数据库名称和检索的关键词即可,用法如下 >>> handle = Entrez.esearch(db="pubmed", term="cnv-seq") >>> record = Entrez.read(handle) >>> record.keys() dict_keys(['Count', 'RetMax', 'RetStart', 'IdList', 'TranslationSet', 'TranslationStack', 'QueryTranslation']) >>> record["IdList"] ['33255631', '33179236', '33135740', '32924127', '32924122', '32858251', '32820524', '32820506', '32820498', '32761601', '32761594', '32643293', '32625247', '32619246', '32597569', '32591622', '32536972', '32489010', '32342531', '32335885'] 在查询结果中,会返回数据库中的ID,可以结合后续的其他命令来下载。 3. EPost 该方法用于上传待查询的ID到NCBI服务器,一次可以上传多个ID, 用法如下 >>> id_list = ["19304878", "18606172", "16403221", "16377612", "14871861", "14630660"] >>> search_results = Entrez.read(Entrez.epost("pubmed", id=",".join(id_list))) >>> webenv = search_results["WebEnv"] >>> query_key = search_results["QueryKey"] >>> webenv 'MCID_5fd9615755b20b529b7599d1' >>> query_key '1' 上传之后可以获取webenv, query_key变量的值,这些值可以通过efetch等命令来获取并下载对应的记录。 4. ESummary 该方法用于下载对应的摘要信息,用法如下 >>> handle = Entrez.esummary(db="pubmed", id="33255631") >>> record = Entrez.read(handle) >>> record [{'Item': [], 'Id': '33255631', 'PubDate': '2020 Nov 25', 'EPubDate': '2020 Nov 25', 'Source': 'Genes (Basel)', 'AuthorList': ['Qi Q', 'Jiang Y', 'Zhou X', 'Meng H', 'Hao N', 'Chang J', 'Bai J', 'Wang C', 'Wang M', 'Guo J', 'Ouyang Y', 'Xu Z', 'Xiao M', 'Zhang VW', 'Liu J'], 'LastAuthor': 'Liu J', 'Title': 'Simultaneous Detection of CNVs and SNVs Improves the Diagnostic Yield of Fetuses with Ultrasound Anomalies and Normal Karyotypes.', 'Volume': '11', 'Issue': '12', 'Pages': '', 'LangList': ['English'], 'NlmUniqueID': '101551097', 'ISSN': '', 'ESSN': '2073-4425', 'PubTypeList': ['Journal Article'], 'RecordStatus': 'PubMed - in process', 'PubStatus': 'epublish', 'ArticleIds': {'pubmed': ['33255631'], 'medline': [], 'pii': 'genes11121397', 'doi': '10.3390/genes11121397', 'rid': '33255631', 'eid': '33255631'}, 'DOI': '10.3390/genes11121397', 'History': {'pubmed': ['2020/12/02 06:00'], 'medline': ['2020/12/02 06:00'], 'received': '2020/09/06 00:00', 'revised': '2020/11/09 00:00', 'accepted': '2020/11/16 00:00', 'entrez': '2020/12/01 01:09'}, 'References': [], 'HasAbstract': IntegerElement(1, attributes={}), 'PmcRefCount': IntegerElement(0, attributes={}), 'FullJournalName': 'Genes', 'ELocationID': 'pii: E1397. doi: 10.3390/genes11121397', 'SO': '2020 Nov 25;11(12)'}] >>> record[0].keys() dict_keys(['Item', 'Id', 'PubDate', 'EPubDate', 'Source', 'AuthorList', 'LastAuthor', 'Title', 'Volume', 'Issue', 'Pages', 'LangList', 'NlmUniqueID', 'ISSN', 'ESSN', 'PubTypeList', 'RecordStatus', 'PubStatus', 'ArticleIds', 'DOI', 'History', 'References', 'HasAbstract', 'PmcRefCount', 'FullJournalName', 'ELocationID', 'SO']) >>> record[0]['Item'] [] >>> record[0]['Title'] 'Simultaneous Detection of CNVs and SNVs Improves the Diagnostic Yield of Fetuses with Ultrasound Anomalies and Normal Karyotypes.' 5. EFetch 该方法用于下载数据库中的内容,用法如下 >>> handle = Entrez.efetch(db="nucleotide", id="186972394", rettype="gb", retmode="text") >>> context = handle.read() >>> with open('out.gb', 'w') as fp: ... fp.write(context) ... 通过rettype和retmode参数可以指定下载文件的格式,对于批量下载,推荐将下载之后的数据另存为文件,然后在通过Bio.SeqIO模块来读取。 6. ELink 该方法用于数据库之间的交叉查询,用法如下 >>> record = Entrez.read(Entrez.elink(dbfrom="gene", db="clinvar", id="7157")) >>> record[0]['LinkSetDb'][0]['Link'][0] {'Id': '988617'} 以上例子展示了在gene和clinvar两个数据库之间进行交叉查询的方式,根据基因ID获取对应的clinvar数据库中该基因上包含的突变位点的信息。 7. EGQuery 该方法用于统计检索项在各个数据库中检索到的条目,用法如下 >>> handle = Entrez.egquery(term="biopython") >>> record = Entrez.read(handle) >>> for row in record["eGQueryResult"]: ... print(row["DbName"], row["Count"]) ... pubmed 29 pmc 1734 mesh 0 books 2 ... geoprofiles 0 gds 17 bioproject 1 8. ESpell 该方法用于自动校正拼写错误,用法如下 >>> handle = Entrez.espell(term="biopythooon") >>> record = Entrez.read(handle) >>> record.keys() dict_keys(['Database', 'Query', 'CorrectedQuery', 'SpelledQuery']) >>> record['Query'] 'biopythooon' >>> record['CorrectedQuery'] 'biopython' 在实际使用中,ESearch, ELink, EFetch这3个命令时最为常用的,通过ESearch和ELink进行查询,获取对应的数据库ID, 然后通过EFectch命令进行下载。
|