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

2023-11-21 15:59

本文主要是介绍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]

这篇关于Biopython从NCBI搜索和取回数据库记录的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/403400

相关文章

Python中4大日志记录库比较的终极PK

《Python中4大日志记录库比较的终极PK》日志记录框架是一种工具,可帮助您标准化应用程序中的日志记录过程,:本文主要介绍Python中4大日志记录库比较的相关资料,文中通过代码介绍的非常详细,... 目录一、logging库1、优点2、缺点二、LogAid库三、Loguru库四、Structlogphp

JavaWeb项目创建、部署、连接数据库保姆级教程(tomcat)

《JavaWeb项目创建、部署、连接数据库保姆级教程(tomcat)》:本文主要介绍如何在IntelliJIDEA2020.1中创建和部署一个JavaWeb项目,包括创建项目、配置Tomcat服务... 目录简介:一、创建项目二、tomcat部署1、将tomcat解压在一个自己找得到路径2、在idea中添加

MySQL MHA集群详解(数据库高可用)

《MySQLMHA集群详解(数据库高可用)》MHA(MasterHighAvailability)是开源MySQL高可用管理工具,用于自动故障检测与转移,支持异步或半同步复制的MySQL主从架构,本... 目录mysql 高可用方案:MHA 详解与实战1. MHA 简介2. MHA 的组件组成(1)MHA

MySQL 数据库进阶之SQL 数据操作与子查询操作大全

《MySQL数据库进阶之SQL数据操作与子查询操作大全》本文详细介绍了SQL中的子查询、数据添加(INSERT)、数据修改(UPDATE)和数据删除(DELETE、TRUNCATE、DROP)操作... 目录一、子查询:嵌套在查询中的查询1.1 子查询的基本语法1.2 子查询的实战示例二、数据添加:INSE

通过DBeaver连接GaussDB数据库的实战案例

《通过DBeaver连接GaussDB数据库的实战案例》DBeaver是一个通用的数据库客户端,可以通过配置不同驱动连接各种不同的数据库,:本文主要介绍通过DBeaver连接GaussDB数据库的... 目录​一、前置条件​二、连接步骤​三、常见问题与解决方案​1. 驱动未找到​2. 连接超时​3. 权限不

MySQL数据库读写分离与负载均衡的实现逻辑

《MySQL数据库读写分离与负载均衡的实现逻辑》读写分离与负载均衡是数据库优化的关键策略,读写分离的核心是将数据库的读操作与写操作分离,本文给大家介绍MySQL数据库读写分离与负载均衡的实现方式,感兴... 目录读写分离与负载均衡的核心概念与目的读写分离的必要性与实现逻辑读写分离的实现方式及优缺点读负载均衡

Go语言中如何进行数据库查询操作

《Go语言中如何进行数据库查询操作》在Go语言中,与数据库交互通常通过使用数据库驱动来实现,Go语言支持多种数据库,如MySQL、PostgreSQL、SQLite等,每种数据库都有其对应的官方或第三... 查询函数QueryRow和Query详细对比特性QueryRowQuery返回值数量1个:*sql

Mysql数据库聚簇索引与非聚簇索引举例详解

《Mysql数据库聚簇索引与非聚簇索引举例详解》在MySQL中聚簇索引和非聚簇索引是两种常见的索引结构,它们的主要区别在于数据的存储方式和索引的组织方式,:本文主要介绍Mysql数据库聚簇索引与非... 目录前言一、核心概念与本质区别二、聚簇索引(Clustered Index)1. 实现原理(以 Inno

MySQL数据库双机热备的配置方法详解

《MySQL数据库双机热备的配置方法详解》在企业级应用中,数据库的高可用性和数据的安全性是至关重要的,MySQL作为最流行的开源关系型数据库管理系统之一,提供了多种方式来实现高可用性,其中双机热备(M... 目录1. 环境准备1.1 安装mysql1.2 配置MySQL1.2.1 主服务器配置1.2.2 从

SpringBoot基于注解实现数据库字段回填的完整方案

《SpringBoot基于注解实现数据库字段回填的完整方案》这篇文章主要为大家详细介绍了SpringBoot如何基于注解实现数据库字段回填的相关方法,文中的示例代码讲解详细,感兴趣的小伙伴可以了解... 目录数据库表pom.XMLRelationFieldRelationFieldMapping基础的一些代