Skip to content

Commit

Permalink
new script for dumping out children goid
Browse files Browse the repository at this point in the history
  • Loading branch information
sweng66 committed Mar 27, 2019
1 parent 5471292 commit f7194be
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions scripts/dumping/curation/dump_children_for_go.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import sys
from src.models import Go, GoRelation
from scripts.loading.database_session import get_session

__author__ = 'sweng66'

def dump_data(goid):

nex_session = get_session()

go_id_to_go = dict([(x.go_id, (x.goid, x.display_name)) for x in nex_session.query(Go).all()])

goObj = nex_session.query(Go).filter_by(goid=goid).one_or_none()

if goObj is None:
print "The goid:", goid, " is not in the database."
return

go_id = goObj.go_id

parent_to_children = {}
for x in nex_session.query(GoRelation).all():
children = []
if x.parent_id in parent_to_children:
children = parent_to_children[x.parent_id]
children.append(x.child_id)
parent_to_children[x.parent_id] = children

output_children(go_id, parent_to_children, go_id_to_go)

nex_session.close()


def output_children(go_id, parent_to_children, go_id_to_go):
if go_id not in parent_to_children:
return
for this_go_id in parent_to_children[go_id]:
(goid, term) = go_id_to_go[this_go_id]
print goid + "\t" + term
output_children(this_go_id, parent_to_children, go_id_to_go)

if __name__ == '__main__':

if len(sys.argv) >= 2:
goid = sys.argv[1]
dump_data(goid)
else:
print "Usage: python dump_children_for_go.py goid"
print "Usage example: python dump_children_for_go.py GO:0002057"
exit()




0 comments on commit f7194be

Please sign in to comment.