Skip to content

Commit

Permalink
Merge pull request #782 from hubmapconsortium/Derek-Furst/update-prov
Browse files Browse the repository at this point in the history
Derek furst/update prov
  • Loading branch information
yuanzhou authored Jan 13, 2025
2 parents df786a3 + f8df5e8 commit 48dca4d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/app_neo4j_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,13 +574,25 @@ def get_provenance(neo4j_driver, uuid, depth):
max_level_str = ''
if depth is not None and len(str(depth)) > 0:
max_level_str = f"maxLevel: {depth}, "

delimiter = ', '
entity_properties = ['group_uuid', 'created_by_user_displayname', 'created_by_user_sub', 'created_by_user_email', 'uuid', 'dataset_type', 'hubmap_id', 'entity_type', 'status', 'created_timestamp']
activity_properties = ['hubmap_id', 'created_by_user_displayname', 'created_by_user_sub', 'created_by_user_email', 'creation_action', 'uuid', 'status', 'created_timestamp']
entity_cypher_pairs_list = [f'{prop}: node.{prop}' for prop in entity_properties]
activity_cypher_pairs_list = [f'{prop}: node.{prop}' for prop in activity_properties]
entity_cypher_pairs_string = delimiter.join(entity_cypher_pairs_list)
activity_cypher_pairs_string = delimiter.join(activity_cypher_pairs_list)
# More info on apoc.path.subgraphAll() procedure: https://neo4j.com/labs/apoc/4.0/graph-querying/expand-subgraph/
query = (f"MATCH (n:Entity) "
f"WHERE n.uuid = '{uuid}' "
f"CALL apoc.path.subgraphAll(n, {{ {max_level_str} relationshipFilter:'<ACTIVITY_INPUT|<ACTIVITY_OUTPUT', labelFilter:'-Lab' }}) "
f"YIELD nodes, relationships "
f"WITH [node in nodes | node {{ .*, label:labels(node)[0] }} ] as nodes, "
f"WITH [node in nodes | "
f" CASE "
f" WHEN 'Activity' IN labels(node) THEN node {{{activity_cypher_pairs_string} , label: labels(node)[0] }} "
f" WHEN 'Entity' IN labels(node) THEN node {{{entity_cypher_pairs_string} , label: labels(node)[0] }} "
f" ELSE node {{ label: labels(node)[0] }} "
f" END "
f"] as nodes, "
f"[rel in relationships | rel {{ .*, fromNode: {{ label:labels(startNode(rel))[0], uuid:startNode(rel).uuid }}, toNode: {{ label:labels(endNode(rel))[0], uuid:endNode(rel).uuid }}, rel_data: {{ type: type(rel) }} }} ] as rels "
f"WITH {{ nodes:nodes, relationships:rels }} as json "
f"RETURN json")
Expand Down
2 changes: 1 addition & 1 deletion src/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Flask==3.0.3
neo4j==5.20.0
prov==2.0.0
prov==2.0.1
Werkzeug==3.0.3
deepdiff==7.0.1

Expand Down

0 comments on commit 48dca4d

Please sign in to comment.