Skip to content

Commit

Permalink
Merge pull request #298 from VirtualFlyBrain/edged_pagination
Browse files Browse the repository at this point in the history
Update neo4j_kb_export.py
  • Loading branch information
Robbie1977 authored Aug 31, 2024
2 parents fa4a5e4 + 1175bf7 commit 9d17a1d
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/uk/ac/ebi/vfb/neo4j/neo4j_kb_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,24 @@ def export_entities(nc, entity_count, outfile):
page_count = page_count + 1
page_start = page_start + page_size

def export_relations(nc, outfile):
def export_relations(nc, entity_count, outfile):
page_size = (entity_count // 4) + 10 # create 4 chunks
page_start = 0
page_count = 0

file_path = Path(outfile)
file_name_without_extension = file_path.stem
file_extension = file_path.suffix
parent_directory = file_path.parent

out_name = f"{file_name_without_extension}_rels{file_extension}"
out_path = os.path.join(parent_directory, out_name)

q_generate = 'CALL ebi.spot.neo4j2owl.exportOWLEdges()'
o = query(q_generate,nc)[0]['o']
write_ontology(o, out_path)
while page_start < entity_count:
q_generate = f'CALL ebi.spot.neo4j2owl.exportOWLEdges({page_start},{page_size})'
o = query(q_generate,nc)[0]['o']
part_name = f"{file_name_without_extension}_rels_{page_count}{file_extension}"
part_path = os.path.join(parent_directory, part_name)
write_ontology(o, part_path)
page_count = page_count + 1
page_start = page_start + page_size

kb=sys.argv[1]
user=sys.argv[2]
Expand All @@ -84,5 +90,5 @@ def export_relations(nc, outfile):
entity_count = get_entity_count(nc)
print("Entity count: " + str(entity_count))
export_entities(nc, entity_count, outfile)
export_relations(nc, outfile)
export_relations(nc, entity_count, outfile)

0 comments on commit 9d17a1d

Please sign in to comment.