Skip to content

Instantly share code, notes, and snippets.

@cplaisier
Created July 19, 2011 22:42
Show Gist options
  • Select an option

  • Save cplaisier/1093927 to your computer and use it in GitHub Desktop.

Select an option

Save cplaisier/1093927 to your computer and use it in GitHub Desktop.
Reannotating halobacterium with GO annotations from: ftp://ftp.geneontology.org/pub/go/ontology/gene_ontology.obo
goTerms = {}
inFile = open('gene_ontology.obo','r')
while 1:
line = inFile.readline()
if not line:
break
if line.strip()=='[Term]':
id1 = inFile.readline().strip().split('id: ')[1]
name = inFile.readline().strip().split('name: ')[1]
namespace = inFile.readline().strip().split('namespace: ')[1]
goTerms[id1] = { 'name': name, 'namespace': namespace}
if line.strip()[0:6]=='alt_id':
goTerms[line.strip().split('alt_id: ')[1]] = { 'name': name, 'namespace': namespace}
inFile.close()
inFile = open('halo_GO.csv','r')
outFile = open('halo_GO_annotations.csv','w')
line = inFile.readline() # Get rid of header
writeMe = ['geneId,goId,annotation,type']
while 1:
line = inFile.readline()
if not line:
break
line = line.strip()
geneId = line.split(',')[0]
goId = 'GO:'+line.split(',')[1]
writeMe += [geneId+','+goId+','+goTerms[goId]['name'].replace(',',';')+','+goTerms[goId]['namespace']]
inFile.close()
outFile.write('\n'.join(writeMe))
outFile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment