In modern biological research, multiple databases exist for gene information, each with its own nomenclature and identifiers. Genes may be identified by Ensembl IDs, Entrez Gene IDs, HGNC symbols, UniProt IDs, and others. These identifiers are often used in different contexts or tools, making it necessary to convert one identifier type to another. This challenge is known as the gene ID conversion problem. Effective conversion is essential for integrating data from different sources, performing downstream analysis, and ensuring data interoperability across bioinformatics tools and platforms.
Several Python modules have been developed to facilitate the conversion of gene IDs, allowing researchers to automate and simplify the conversion process. Below are some Python packages that are commonly used for this purpose, along with example scripts illustrating how to use each of them.
MyGene.py is a Python wrapper for the MyGene.info web service, which provides fast and reliable access to gene annotation information. It supports various identifiers like Ensembl, Entrez, UniProt, and more.
import mygene
# Initialize the MyGene.info service
mg = mygene.MyGeneInfo()
# Convert a list of Ensembl IDs to gene symbols
ensembl_ids = ['ENSG00000157764', 'ENSG00000139618']
result = mg.querymany(ensembl_ids, scopes='ensembl.gene', fields='symbol', species='human')
# Display the results
for entry in result:
print(f"Ensembl ID: {entry['query']}, Gene Symbol: {entry.get('symbol', 'Not found')}")
The Ensembl_converter module provides a straightforward approach to convert Ensembl IDs to gene symbols. It takes a list of Ensembl IDs and returns a DataFrame with the corresponding gene symbols.
from Ensembl_converter import EnsemblConverter
# Initialize the converter
converter = EnsemblConverter()
# Convert Ensembl IDs to gene symbols
ensembl_ids = ['ENSG00000157764', 'ENSG00000139618']
result = converter.convert_ids(ensembl_ids)
# Display the resulting DataFrame
print(result)
pyEntrezId is another Python package that facilitates the conversion between different gene IDs, including Ensembl, Entrez, HGNC, UniProt, and others. It is useful for conversions where Entrez IDs are involved.
from PyEntrezId import Conversion
# Initialize the converter and specify your email
converter = Conversion('youremail@example.com')
# Convert Ensembl Gene ID to Entrez Gene ID
ensembl_id = 'ENSG00000157764'
entrez_id = converter.convert_ensembl_to_entrez(ensembl_id)
# Display the result
print(f"Ensembl ID: {ensembl_id}, Entrez ID: {entrez_id}")
biomart is a Python package that connects to the BioMart servers to query various databases, such as Ensembl. BioMart is an open-source data management system that provides unified access to biological databases. It allows researchers to easily retrieve information such as gene annotations, orthologs, and mappings between different identifiers. More information about BioMart can be found on their official website.
Below is an example of how to use the biomart package to convert gene IDs:
from biomart import BiomartServer
# Connect to the BioMart server
server = BiomartServer("http://www.ensembl.org/biomart")
dataset = server.datasets['hsapiens_gene_ensembl']
# Define the attributes we want to convert (Ensembl Gene ID to Gene Symbol)
attributes = ['ensembl_gene_id', 'external_gene_name']
# Retrieve the data for the list of Ensembl Gene IDs
response = dataset.search({'attributes': attributes, 'filters': {'ensembl_gene_id': ['ENSG00000157764', 'ENSG00000139618']}})
# Display the results
for line in response.iter_lines():
ensembl_id, gene_name = line.decode().split(' ')
print(f"Ensembl ID: {ensembl_id}, Gene Name: {gene_name}")