在 GitHub 上编辑此页面

使用 Entrez 模块检索和标注 Entrez Gene ID。

问题

如果您处理大量的基因 ID(例如微阵列分析产生的基因 ID),那么在您想确定它们的潜在生物学意义时,对它们进行标注非常重要。但是,许多标注系统仅基于网络,或无法与 Python 协同工作。

解决方案

得益于 Entrez 模块,可以使用以下提供的“retrieve_ids”函数轻松地标注一批 Entrez Gene ID。

此示例假设您有一个 Entrez Gene ID 列表。注意:即使它们是数字,也应该将它们存储为字符串,而不是整数。

import sys

from Bio import Entrez

# *Always* tell NCBI who you are
Entrez.email = "your email here"


def retrieve_annotation(id_list):

    """Annotates Entrez Gene IDs using Bio.Entrez, in particular epost (to
    submit the data to NCBI) and esummary to retrieve the information.
    Returns a list of dictionaries with the annotations."""

    request = Entrez.epost("gene", id=",".join(id_list))
    try:
        result = Entrez.read(request)
    except RuntimeError as e:
        # FIXME: How generate NAs instead of causing an error with invalid IDs?
        print "An error occurred while retrieving the annotations."
        print "The error returned was %s" % e
        sys.exit(-1)

    webEnv = result["WebEnv"]
    queryKey = result["QueryKey"]
    data = Entrez.esummary(db="gene", webenv=webEnv, query_key=queryKey)
    annotations = Entrez.read(data)

    print "Retrieved %d annotations for %d genes" % (len(annotations), len(id_list))

    return annotations

如函数的文档字符串所述,该函数返回一个字典列表,每个字典对应一个基因,您可以根据需要使用它们。以下示例打印了检索到的注释的 ID、基因符号和基因名称

def print_data(annotation):
    for gene_data in annotation:
        gene_id = gene_data["Id"]
        gene_symbol = gene_data["NomenclatureSymbol"]
        gene_name = gene_data["Description"]
        print "ID: %s - Gene Symbol: %s - Gene Name: %s" % (
            gene_id,
            gene_symbol,
            gene_name,
        )

更多

Tao Liu 在此代码的基础上扩展了一个完整的将 Entrez ID 和 RefSeq ID 之间进行转换的示例