Skip to content

Commit

Permalink
Update fb_tools.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbie1977 authored Oct 23, 2024
1 parent 88d5c31 commit f4c9a0c
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/uk/ac/ebi/vfb/neo4j/flybase2neo/fb_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,19 @@ def query_fb(self, query, max_retries=5, delay=30):
self.conn = get_fb_conn() # Re-establish the connection

def commit_via_csv(self, statement, dict_list):
df = pd.DataFrame.from_records(dict_list)
df.to_csv(self.file_path + "tmp.csv", sep='\t')
self.nc.commit_csv("file:///" + "tmp.csv",
statement=statement,
sep="\t")
# add something to delete csv here.
"""Modified commit_via_csv to send data directly via commit_list using UNWIND."""
if not dict_list:
warnings.warn("No data provided to commit_via_csv.")
return False
# Build the Cypher query with UNWIND
cypher = """
UNWIND $batch AS line
""" + statement
# Now send the statement and parameters via commit_list
# Optionally, split dict_list into batches if needed
batch_size = 1000 # Adjust batch size as needed
for batch in chunks(dict_list, batch_size):
self.nc.commit_list([{'statement': cypher, 'parameters': {'batch': batch}}])

def close(self):
self.conn.close() # Investigate implementing using with statement. Then method not required.
Expand Down

0 comments on commit f4c9a0c

Please sign in to comment.