Skip to content

Commit

Permalink
fixing targets
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbie1977 authored Oct 23, 2024
1 parent f312382 commit d76be76
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions src/uk/ac/ebi/vfb/neo4j/flybase2neo/fb_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ 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_template, dict_list):
"""Modified commit_via_csv to generate Cypher statements by substituting values from dict_list."""
"""Modified commit_via_csv to handle placeholders with 'line.' prefix."""
if not dict_list:
warnings.warn("No data provided to commit_via_csv.")
return False
Expand All @@ -132,25 +132,16 @@ def cypher_escape(value):
# For numbers and booleans
return str(value).lower()

# **Preprocess the statement_template to remove spaces inside placeholders and within placeholder names**
import re

def clean_placeholders(template):
# Match placeholders and remove spaces inside braces and within placeholder names
def replacer(match):
placeholder = match.group(1)
cleaned_placeholder = placeholder.strip()
return '{' + cleaned_placeholder + '}'
return re.sub(r'{([^}]*)}', replacer, template)

statement_template = clean_placeholders(statement_template)

batch_size = 1000 # Adjust batch size as needed
for batch in chunks(dict_list, batch_size):
statements = []
for line in batch:
# Escape and substitute values into the statement template
escaped_line = {key.strip(): cypher_escape(value) for key, value in line.items()}
# Escape the values
escaped_values = {key: cypher_escape(value) for key, value in line.items()}
# Add 'line.' prefix to keys
escaped_line = {'line.' + key: value for key, value in escaped_values.items()}
# Also include original keys in case they are used without 'line.'
escaped_line.update(escaped_values)

try:
statement = statement_template.format(**escaped_line)
Expand Down

0 comments on commit d76be76

Please sign in to comment.