Skip to content

Instantly share code, notes, and snippets.

@eclarke
Created May 2, 2012 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eclarke/2580678 to your computer and use it in GitHub Desktop.
Save eclarke/2580678 to your computer and use it in GitHub Desktop.
filter obsolete go terms
#!/usr/bin/env python
import re
import json
import clint
def import_go(gofile='go.json'):
try:
return json.loads(json.load(open(gofile)))
except IOError:
goterms = []
obo = open('gene_ontology_ext.obo').read()
for chunk in obo.split('[Term]'):
lines = chunk.splitlines()
gid = lines[1].replace('id: ','')
if 'is_obsolete: true' in lines:
goterms.append(gid)
return goterms
def main():
inp = clint.piped_in().splitlines()
if not inp:
inp = open(clint.args.get(0)).readlines()
goterms = import_go()
filtered = []
for line in inp:
goid = line.split('\t')[4]
if goid in goterms:
print line.strip('\n')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment