This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Lookup A Gene Ontology Definition With Biopython

What is the easiest way to lookup a GO term in Python, given the GO ID?

python biopython gene

currently biopython doesn't have support for GO. What do you want to do, exactly? what do you mean by 'lookup'?

It's not for Python 3.5 :(

3 answers

you can also use goatools in python:

it would look like:

>>> from goatools import obo_parser
>>> p = obo_parser.GODag('data/gene_ontology.1_2.obo')
>>> p['GO:0006915'].name
'apoptosis'

you'll just have to download the obo from here.

Very interesting to know :) Is there a way in goatools to do statistical testing on a set and a subset of genes to know if the subset contains over-representated functions?

Didn't know about goatools, will have to investigate further. Thanks :)

You could use the QuickGO web services. These tools allow you to quickly download relevant information, given a GO ID.

For instance, take the ID GO:0006915.

import urllib
from xml.etree import cElementTree as ElementTree

def get_go_name(go_id):
    #get the GO entry as XML
    xml = urllib.urlopen("http://www.ebi.ac.uk/QuickGO/GTerm?id=GO:"+go_id+"&format=oboxml")
    #open in cElementTree, for fast XML parsing
    for event, element in ElementTree.iterparse(xml):
        #need to make sure we are getting the name contained within the 'term' entry
        if element.tag == 'term':
            for child in element.getchildren():
                #this is the name of the GO ID in the URL above.
                if child.tag == 'name':
                    return child.text

print get_go_name('0006915')

This script should print 'apoptosis'.

Is goatools still the most up to date python package?

Any idea how the files in goatools / data / on Github were created?

How would it be possible to use plotgoterm.py (from goatools) to create input files for Cytoscape or VisANT ?

Log in to answer this question.