Created
May 2, 2012 21:33
-
-
Save eclarke/2580678 to your computer and use it in GitHub Desktop.
filter obsolete go terms
This file contains 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
#!/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