跳转到主要内容

"Python访问NCBI的eutilities API的接口"

项目描述

pypi_badge build_status issues_badge contributors license docs changelog

eutils是一个Python包,用于通过NCBI的E-utilities接口简化搜索、获取和解析NCBI记录。

新闻

功能

  • 简单的 Pythonic 接口用于搜索和获取

  • 自动根据 NCBI 指引进行查询速率限制

  • 可选的基于 sqlite 的压缩回复缓存

  • “外观”使访问回复中的基本属性变得容易

快速示例

截至 2018 年 5 月 1 日,NCBI 根据客户端是否注册来限制请求。未注册客户端限制为每秒 3 个请求;注册客户端被授予每秒 10 个请求,并且可以请求更多。请参阅 NCBI 公告 了解更多信息。

eutils 包将根据 NCBI 指引自动限制请求(无 API 密钥时为每秒 3 个请求,有 API 密钥时为每秒 10 个请求)。

$ pip install eutils
$ ipython

>>> from eutils import Client

# Initialize a client. This client handles all caching and query
# throttling.  For example:
>>> ec = Client(api_key=os.environ.get("NCBI_API_KEY", None))

# search for tumor necrosis factor genes
# any valid NCBI query may be used
>>> esr = ec.esearch(db='gene',term='tumor necrosis factor')

# fetch one of those (gene id 7157 is human TNF)
>>> egs = ec.efetch(db='gene', id=7157)

# One may fetch multiple genes at a time. These are returned as an
# EntrezgeneSet. We'll grab the first (and only) child, which returns
# an instance of the Entrezgene class.
>>> eg = egs.entrezgenes[0]

# Easily access some basic information about the gene
>>> eg.hgnc, eg.maploc, eg.description, eg.type, eg.genus_species
('TP53', '17p13.1', 'tumor protein p53', 'protein-coding', 'Homo sapiens')

# get a list of genomic references
>>> sorted([(r.acv, r.label) for r in eg.references])
[('NC_000017.11', 'Chromosome 17 Reference GRCh38...'),
 ('NC_018928.2', 'Chromosome 17 Alternate ...'),
 ('NG_017013.2', 'RefSeqGene')]

# Get the first three products defined on GRCh38
#>>> [p.acv for p in eg.references[0].products][:3]
#['NM_001126112.2', 'NM_001276761.1', 'NM_000546.5']

# As a sample, grab the first product defined on this reference (order is arbitrary)
>>> mrna = eg.references[0].products[0]
>>> str(mrna)
'GeneCommentary(acv=NM_001126112.2,type=mRNA,heading=Reference,label=transcript variant 2)'

# mrna.genomic_coords provides access to the exon definitions on this reference

>>> mrna.genomic_coords.gi, mrna.genomic_coords.strand
('568815581', -1)

>>> mrna.genomic_coords.intervals
[(7687376, 7687549), (7676520, 7676618), (7676381, 7676402),
(7675993, 7676271), (7675052, 7675235), (7674858, 7674970),
(7674180, 7674289), (7673700, 7673836), (7673534, 7673607),
(7670608, 7670714), (7668401, 7669689)]

# and the mrna has a product, the resulting protein:
>>> str(mrna.products[0])
'GeneCommentary(acv=NP_001119584.1,type=peptide,heading=Reference,label=isoform a)'

重要说明

  • 我们鼓励您 浏览问题。请报告您发现的任何问题。

  • 使用 pip 软件包规范以确保在 API 稳定性的情况下保持次要版本。 例如,eutils >=0.6,<0.7

开发和贡献

欢迎提交错误报告、代码补丁和文档的贡献!

开发在默认分支上发生。请从默认分支工作在功能分支或书签。功能分支应命名为修复的 eutils 问题,例如 121-update-xml-facades。在合并时,使用类似“closes #121: 将 xml facades 更新为新样式接口”的提交信息。(“closes #n”将自动识别并在推送时关闭票证。)

包含的 Makefile 自动化了许多任务。特别是,make develop 准备开发环境,make test 运行单元测试。(请在提交前运行测试!)

再次感谢您的贡献。

项目详情


下载文件

下载您平台上的文件。如果您不确定选择哪个,请了解更多关于 安装软件包 的信息。

源代码分布

eutils-0.6.0.tar.gz (304.6 kB 查看散列)

上传时间 源代码

构建分布

eutils-0.6.0-py2.py3-none-any.whl (41.9 kB 查看散列)

上传时间 Python 2 Python 3

支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面