Created
July 19, 2011 22:42
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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