Skip to content

Instantly share code, notes, and snippets.

@renaud
Created October 17, 2013 07:36
Show Gist options
  • Save renaud/7020659 to your computer and use it in GitHub Desktop.
Save renaud/7020659 to your computer and use it in GitHub Desktop.
Retrieve synonyms of gene ontology (GO) terms
import urllib, sys
from xml.etree import cElementTree as ElementTree
def get_go_name(go_id):
sys.stdout.write("GO"+go_id+"\t"),
#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':
sys.stdout.write(child.text),
if child.tag == 'synonym':
for c2 in child.getchildren():
if c2.tag == 'synonym_text':
sys.stdout.write("\t"+c2.text),
print('')
get_go_name('0044225')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment