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

相关文章

MySQL进行数据库审计的详细步骤和示例代码

《MySQL进行数据库审计的详细步骤和示例代码》数据库审计通过触发器、内置功能及第三方工具记录和监控数据库活动,确保安全、完整与合规,Java代码实现自动化日志记录,整合分析系统提升监控效率,本文给大... 目录一、数据库审计的基本概念二、使用触发器进行数据库审计1. 创建审计表2. 创建触发器三、Java

Zabbix在MySQL性能监控方面的运用及最佳实践记录

《Zabbix在MySQL性能监控方面的运用及最佳实践记录》Zabbix通过自定义脚本和内置模板监控MySQL核心指标(连接、查询、资源、复制),支持自动发现多实例及告警通知,结合可视化仪表盘,可有效... 目录一、核心监控指标及配置1. 关键监控指标示例2. 配置方法二、自动发现与多实例管理1. 实践步骤

SQL server数据库如何下载和安装

《SQLserver数据库如何下载和安装》本文指导如何下载安装SQLServer2022评估版及SSMS工具,涵盖安装配置、连接字符串设置、C#连接数据库方法和安全注意事项,如混合验证、参数化查... 目录第一步:打开官网下载对应文件第二步:程序安装配置第三部:安装工具SQL Server Manageme

C#连接SQL server数据库命令的基本步骤

《C#连接SQLserver数据库命令的基本步骤》文章讲解了连接SQLServer数据库的步骤,包括引入命名空间、构建连接字符串、使用SqlConnection和SqlCommand执行SQL操作,... 目录建议配合使用:如何下载和安装SQL server数据库-CSDN博客1. 引入必要的命名空间2.

Java通过驱动包(jar包)连接MySQL数据库的步骤总结及验证方式

《Java通过驱动包(jar包)连接MySQL数据库的步骤总结及验证方式》本文详细介绍如何使用Java通过JDBC连接MySQL数据库,包括下载驱动、配置Eclipse环境、检测数据库连接等关键步骤,... 目录一、下载驱动包二、放jar包三、检测数据库连接JavaJava 如何使用 JDBC 连接 mys

MySQL数据库中ENUM的用法是什么详解

《MySQL数据库中ENUM的用法是什么详解》ENUM是一个字符串对象,用于指定一组预定义的值,并可在创建表时使用,下面:本文主要介绍MySQL数据库中ENUM的用法是什么的相关资料,文中通过代码... 目录mysql 中 ENUM 的用法一、ENUM 的定义与语法二、ENUM 的特点三、ENUM 的用法1

Java中调用数据库存储过程的示例代码

《Java中调用数据库存储过程的示例代码》本文介绍Java通过JDBC调用数据库存储过程的方法,涵盖参数类型、执行步骤及数据库差异,需注意异常处理与资源管理,以优化性能并实现复杂业务逻辑,感兴趣的朋友... 目录一、存储过程概述二、Java调用存储过程的基本javascript步骤三、Java调用存储过程示

Go语言数据库编程GORM 的基本使用详解

《Go语言数据库编程GORM的基本使用详解》GORM是Go语言流行的ORM框架,封装database/sql,支持自动迁移、关联、事务等,提供CRUD、条件查询、钩子函数、日志等功能,简化数据库操作... 目录一、安装与初始化1. 安装 GORM 及数据库驱动2. 建立数据库连接二、定义模型结构体三、自动迁

在Spring Boot中集成RabbitMQ的实战记录

《在SpringBoot中集成RabbitMQ的实战记录》本文介绍SpringBoot集成RabbitMQ的步骤,涵盖配置连接、消息发送与接收,并对比两种定义Exchange与队列的方式:手动声明(... 目录前言准备工作1. 安装 RabbitMQ2. 消息发送者(Producer)配置1. 创建 Spr

嵌入式数据库SQLite 3配置使用讲解

《嵌入式数据库SQLite3配置使用讲解》本文强调嵌入式项目中SQLite3数据库的重要性,因其零配置、轻量级、跨平台及事务处理特性,可保障数据溯源与责任明确,详细讲解安装配置、基础语法及SQLit... 目录0、惨痛教训1、SQLite3环境配置(1)、下载安装SQLite库(2)、解压下载的文件(3)、