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

相关文章

Linux下MySQL数据库定时备份脚本与Crontab配置教学

《Linux下MySQL数据库定时备份脚本与Crontab配置教学》在生产环境中,数据库是核心资产之一,定期备份数据库可以有效防止意外数据丢失,本文将分享一份MySQL定时备份脚本,并讲解如何通过cr... 目录备份脚本详解脚本功能说明授权与可执行权限使用 Crontab 定时执行编辑 Crontab添加定

如何通过try-catch判断数据库唯一键字段是否重复

《如何通过try-catch判断数据库唯一键字段是否重复》在MyBatis+MySQL中,通过try-catch捕获唯一约束异常可避免重复数据查询,优点是减少数据库交互、提升并发安全,缺点是异常处理开... 目录1、原理2、怎么理解“异常走的是数据库错误路径,开销比普通逻辑分支稍高”?1. 普通逻辑分支 v

Python与MySQL实现数据库实时同步的详细步骤

《Python与MySQL实现数据库实时同步的详细步骤》在日常开发中,数据同步是一项常见的需求,本篇文章将使用Python和MySQL来实现数据库实时同步,我们将围绕数据变更捕获、数据处理和数据写入这... 目录前言摘要概述:数据同步方案1. 基本思路2. mysql Binlog 简介实现步骤与代码示例1

使用shardingsphere实现mysql数据库分片方式

《使用shardingsphere实现mysql数据库分片方式》本文介绍如何使用ShardingSphere-JDBC在SpringBoot中实现MySQL水平分库,涵盖分片策略、路由算法及零侵入配置... 目录一、ShardingSphere 简介1.1 对比1.2 核心概念1.3 Sharding-Sp

Go语言连接MySQL数据库执行基本的增删改查

《Go语言连接MySQL数据库执行基本的增删改查》在后端开发中,MySQL是最常用的关系型数据库之一,本文主要为大家详细介绍了如何使用Go连接MySQL数据库并执行基本的增删改查吧... 目录Go语言连接mysql数据库准备工作安装 MySQL 驱动代码实现运行结果注意事项Go语言执行基本的增删改查准备工作

MySQL 数据库表操作完全指南:创建、读取、更新与删除实战

《MySQL数据库表操作完全指南:创建、读取、更新与删除实战》本文系统讲解MySQL表的增删查改(CURD)操作,涵盖创建、更新、查询、删除及插入查询结果,也是贯穿各类项目开发全流程的基础数据交互原... 目录mysql系列前言一、Create(创建)并插入数据1.1 单行数据 + 全列插入1.2 多行数据

MySQL 数据库表与查询操作实战案例

《MySQL数据库表与查询操作实战案例》本文将通过实际案例,详细介绍MySQL中数据库表的设计、数据插入以及常用的查询操作,帮助初学者快速上手,感兴趣的朋友跟随小编一起看看吧... 目录mysql 数据库表操作与查询实战案例项目一:产品相关数据库设计与创建一、数据库及表结构设计二、数据库与表的创建项目二:员

MybatisPlus中removeById删除数据库未变解决方案

《MybatisPlus中removeById删除数据库未变解决方案》MyBatisPlus中,removeById需实体类标注@TableId注解以识别数据库主键,若字段名不一致,应通过value属... 目录MyBATisPlus中removeBypythonId删除数据库未变removeById(Se

在 Spring Boot 中连接 MySQL 数据库的详细步骤

《在SpringBoot中连接MySQL数据库的详细步骤》本文介绍了SpringBoot连接MySQL数据库的流程,添加依赖、配置连接信息、创建实体类与仓库接口,通过自动配置实现数据库操作,... 目录一、添加依赖二、配置数据库连接三、创建实体类四、创建仓库接口五、创建服务类六、创建控制器七、运行应用程序八

基于Spring Boot 的小区人脸识别与出入记录管理系统功能

《基于SpringBoot的小区人脸识别与出入记录管理系统功能》文章介绍基于SpringBoot框架与百度AI人脸识别API的小区出入管理系统,实现自动识别、记录及查询功能,涵盖技术选型、数据模型... 目录系统功能概述技术栈选择核心依赖配置数据模型设计出入记录实体类出入记录查询表单出入记录 VO 类(用于