This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Programatic Technique For Gene-Name/Id Conversion

Does anyone know of a good gene-id conversion tool written in Python. I've come across numerous webtools but I'd like something a little more automated. I have the knowledge/ability to do it myself I was just wondering if there was something already out there. There's no point in re-inventing the wheel each time.

Thanks in advance

python conversion

Which Ids do you want to convert, exactly? I think there is not a single service that can convert between all the most used ids for genes, even biomart and uniprot lack some databases. Look at this question.

5 answers

Writing a small tool to automate access to the website/service is pretty simple. Here's a method I wrote for the UniProt ID mapping service:

import urllib
import urllib2

def uniprot_mapping(fromtype, totype, identifier):
    base = 'http://www.uniprot.org'
    tool = 'mapping'
    params = {'from':fromtype,
                'to':totype,
                'format':'tab',
                'query':identifier,
    }
    data = urllib.urlencode(params)
    url = base+'/'+tool+'?'+data
    response = urllib2.urlopen(url)
    return response.read()

It's not extensively tested, but should work. You can find a list of fromtypes and totypes here: http://www.uniprot.org/faq/28#id_mapping_examples

Check out the python library for mygene.info. For example:

In [1]: import mygene

In [2]: mg = mygene.MyGeneInfo()

In [3]: mg.getgene(1017)
Out[3]:
{'_id': '1017',
 'entrezgene': 1017,
 'name': 'cyclin-dependent kinase 2',
 'symbol': 'CDK2',
 'taxid': 9606}

In [4]:  mg.query('cdk2', size=2)
Out[4]:
{'hits': [{'_id': '1017',
   '_score': 373.24667,
   'entrezgene': 1017,
   'name': 'cyclin-dependent kinase 2',
   'symbol': 'CDK2',
   'taxid': 9606},
  {'_id': '12566',
   '_score': 353.90176,
   'entrezgene': 12566,
   'name': 'cyclin-dependent kinase 2',
   'symbol': 'Cdk2',
   'taxid': 10090}],
 'max_score': 373.24667,
 'took': 10,
 'total': 28}

A few nice features of mygene.info

  • automated updates (minimum weekly) from NCBI Entrez, Ensembl, UniProt, NetAffy, and PharmGKB
  • can be easily configured to incorporate additional gene-centric resources, so ask if you see something missing
  • the API is fast and can handle lots of concurrency, so hit it as hard as you want (up to, say, 5 queries per second)

More information in this publication and on these blog posts.

In case anyone comes by this later I've made a simple python module for doing this sort of converting. You can find it on GitHub: http://github.com/JudoWill/IDConverter

Feel free make comments and provide suggestions.

the link is broken:/ UPDATE: okay, now I see the date of this post.

You could automate the access to the website with Python ;-)

Have you come across bioDBnet?

Log in to answer this question.